Phototransistor and Arduino

Hi Everyone,

I am brand new to the microcontroller world, but I am really enjoying it so far… so much in fact that I may have gotten myself a little over my head.

The project goal to make an array of phototransistors (maybe a 20x20 grid) in order to have surface that would be able to trace my finger across it (like a touch pad mouse for a laptop). This project is motivated by the fact that we have a good deal of unused phototransistors at work that I am free to play with. Because they’re free, I can’t be choosy- Here is the data sheet (http://www.mouser.com/ds/2/143/PT334-6C … -41749.pdf).

Given the raw number of phototransistors I want to use, I figured I could some shift registers (https://www.sparkfun.com/products/10680). But this is where I start to find myself in over my head…

The phototransistor sheet is a mystery to me even after watching Pete’s description on transistors (http://www.youtube.com/watch?v=w9cd7B5QRRo). There is no “Beta” on the data sheet and, of course, the specifics of Collector-Emitter Voltage (and vice versa) eludes me.

To make a long story short, can someone help me with a schematic (like the one presented here for driving leds with a shift register: http://bildr.org/2011/02/74hc595/) for pulling light intensity levels from the phototransistors (PT334-6C), through 3 shift registers sold by sparkfun, and into my arduino? How much do I need to worry about the Vce Rating of 30V? I can still provide a 5V supply and be ok, right?

Like I said, I know I am in way over my head- Any help would be greatly appreciated!

Thanks,

Drew

Vce is a maximum rating; you just need to stay below it. For each one, wire the emitter to ground and pull up the collector to 5V through a resistor. Feed the collector to the shift register (you need parallel-in serial-out one).

/mike

Hi Mike,

Thanks for the quick reply- So basically, I can treat the PT334-6C like a regular LED except I will be reading them rather than driving them (right?).

And because of this, the shift registers that I purchased 74HC595 (https://www.sparkfun.com/products/10680) won’t work.

So I need the SN74HC165 Shift-In board instead (https://www.sparkfun.com/products/11512)? I found some nice support code here: http://playground.arduino.cc/Code/ShiftRegSN74HC165N

Out of curiosity, what is the downside to chaining together 10 shift registers? Is there a maximum for the Arduino Uno?

Thanks again,

Drew

A problem with using shift registers is that the change in phototransistor output will depend very strongly on the ambient light level, and you can’t guarantee a logic one or zero. There IS an equivalent to beta for a phototransistor, it is the ratio of the collector current to illumination intensity. In the data sheet, the symbol Ee is the equivalent of the base current.

I would recommend experimenting with a small scale matrix with just a few phototransistors, to see how the output behaves in various illumination situations, before committing yourself to building the 20x20 array.

For a clever way of reading out a few phototransistors quantitatively, take a look at the circuit for the Pololu QTR-1RC reflectance sensor. However, note that their explanation of how the circuit works is oversimplified (and frankly, misleading). http://www.pololu.com/product/959

Hi Jreminton,

Ah! Yes- I forgot about the digtial issue!

Would I be better off using a mulitplex set-up (like this: https://www.sparkfun.com/products/9056)?

Rather than the “all-or-none” nature of the shift register, the MUX should give me 10 bit resolution, correct?

-Drew

That might be a better idea but there’s a price to be paid, and that is speed of response. An A/D conversion takes ~124 usec. Add some other code to store the reading and switch the MUX, let’s guess 150 usec to do each reading. That’s 20x20x150us = 60 msecs to read the array. That’s a 16 Hz sampling rate. Is that going to be fast enough to ‘track’ finger motion ?

I’ll second the recommendation above. You’ve got 6 analog pins … wire up 6 sensors, code it up, add in delays to simulate other sensors and play with it.

I should have pointed out that reading out the illumination intensity using the Pololu circuit/method is much faster than using an ADC.

Mee_n_mac - Thanks for those numbers. 16Hz is way to low for my taste.

The “Pololu method” that Jreminton suggested should work for 6 phototransistor, but any thoughts about up-scaling? How would one deal with more than 6 analog inputs?

There are analog multiplexing chips: http://www.jameco.com/1/3/analog-multiplexer-ic

Hi Jreminton,

Does this mean that the analog MUX chips won’t have the delay issue that Mee_n_mac pointer out?

Thanks again- this is all fantastic info.

-Drew

Analog multiplexer which is what is used inside your processor to change analog inputs to the ADC.

Another way may be to use a multichannel ADC. Like this one as an example:

http://www.microchip.com/wwwproducts/De … e=en010530

Another way if you can determine to photo-transistor output Voltage for a ‘detect’ verses ‘not detect’ is Voltage comparators. But then if you setup the photo-transistor bias to obtain logic level out at ‘detect’ verses ‘not detect’ then a digital input would work and be fast since you can read 8 inputs at once.

As jremington said above, experiment with one photo-transistor to state with and learn what you need for the processor interface.

Thanks Waltr- I will definitely experiment. If I get the chance in the next few days, I will post the results here…

For better or worse, I have something in mind and I am bit too stubborn to give up easily.

The MCP3008 chip looks fantastic. Again, I am in way over my head- could I get the sampling rate of 60Hz or better by using that chip in conjunction with the multichannel ADC?

Checking the data sheet of the MCP3008.

You can get one ADC sample in 24 serial clocks (figures 6-1 & 6-2).

Minimum clock speed is 10kHz (section 6.2) and a maximum clock of 4MHz.

So one sample can take between 2.4msec and 6usec which is 416sps to 16.666ksps.

So yes, it can do more that 60sps.

Do download and study the data sheet before deciding to use it. It does need a separate CS line for each chip.

Just to illustrate what waltr said re: using comparators. The idea is that you setup your phototransistor to produce a voltage that varies w/the light intensity falling on it. That voltage is fed into 1 input of a comparator. The MCU can then generate a PWM waveform, whose DC component can be extracted by a low pass filter. This DC component is fed into the other input of the comparator, and that DC value can be varied by the MCU. This way you can set whatever threshold is appropriate for the given light level. Since the end result is a binary decision, is the finger above the phototransistor or not, you’re losing little in the way of information vs the ADC route. It’s like your original idea but with the adaptability added. You still need to use some MUX or SR approach to get all the bits into the MCU. Comparators come in quads, 4/IC, so you’d need 2x the amount of 8 channel ADCs, but comparators are cheap $s.

(click on to open)

Thanks Mee_n_mac. A few days ago, I think I experimented with a low-tech version of something similar (I made the set-up decribed here: http://www.thebox.myzen.co.uk/Workshop/LED_Sensing.html). Unfortunately, it didn’t seem to work that well when using regular LEDs.

The only reason that I shy away from a comparator method is because it doesn’t look like it will scale up that well. I could be quite wrong here, so please correct me.

I guess what I am coming to terms with is that I initially wanted as many phototransistor analog values piped into the arduino as possible, but there is no way to do this with the few A0-A5 inputs that the Uno has. What I envisioned was a system that could “infer pressure/closeness” (I could use a capacitive touch system as well, but the phototransistors are free and I would still need analog). If I understand everything correctly, using the analogWrite command, I would be relegated to a 0-255 domain (which I am ok with). Is this true with the MCP3008 microchip? Does it provide values between 0-255 rather than a binary output?

Even in this case, I am concerned that (1) I won’t be able to get more than a half dozen of pin inputs into the arduino and (2) to multiplex the signal would take too long.

Nonetheless,it’s all great information and I am sure I will use the comparator schematic in the future!

Thanks again,

Drew

I think you should make a block diagram of each method and figure out how each gets connected to the Arduino and how many pins are needed. That should bring things into focus.

But even before that you can play w/a few PT’s and the existing analog inputs.

Ok- I have a small set up here:

https://www.dropbox.com/sc/ufppnh3eoz2dz9q/NXXnSCY2m9

I am running two of my phototransistors (PT344-6C): one into A) and another into digitalPin 2 (I am using analogRead to get the data out). Resistors are 1 M Ohm. I tried lower values (10K down to 220 Ohms, but only read 0’s). I tried no resistor when I only had 1 phototransistors reading from A0 (1021-1023… no surprise here).

Here is a typical output for the pins away from the light:

DigitalPin2: 163, Pin A0: 52

DigitalPin2: 161, Pin A0: 47

DigitalPin2: 159, Pin A0: 46

And here is what it looks like when I put the diodes up close to my desk lamp:

DigitalPin2: 855, Pin A0: 1020

DigitalPin2: 853, Pin A0: 1023

DigitalPin2: 852, Pin A0: 1021

For sake of completeness, here is my code:

int sensePin = A0;
int sensePinTwo = 2;
void setup(){
analogReference(DEFAULT);
pinMode(2,INPUT);
Serial.begin(9600);
}

void loop(){
  Serial.print("DigitalPin2: ");
  Serial.print(analogRead(sensePinTwo));
  Serial.print(", Pin A0: ");
  Serial.println(analogRead(sensePin));
  delay(100);
}

With two pins, if I pull the first resistor, I no longer see values of 1022-1023 but they’re more in the ballpark of 963. I suspect that - after looking at the spec. sheet- the 5V supplied by the arduino will not be sufficient.

Thoughts, ideas or criticisms?

Drew

Your image doesn’t show. How did you wire up the PT, resistor and A0 ? I infer from the results that the PT collector was tied to 5v, the emitter to A0 and the resistor, whose otheR end was tied to GND.

Sorry, let me try that again

http://s24.postimg.org/tavsb31is/2013_1 … _18_15.jpg

I infer from the results that the PT collector was tied to 5v, the emitter to A0 and the resistor, whose otheR end was tied to GND.

Yes, the first time around when I used 1 LED, this was the set-up I used. The image shows what I was doing for 2 LEDs...

Ok- I have set up 4 photoresistors (wish I could give a part number, but it’s whatever that comes with the arduino starter kit) with 4 phototransistors (PT334-6C). These 8 inputs run into a MCP3008 Analog-to-digital converter.

http://s23.postimg.org/6g5ar5pxn/2013_1 … _17_18.jpg

It took a little google scouring, but I found some code that facilitated using the chip with the Arduino. The P.Resistor and P.Transistors performed comparably, so I am happy with the components. I may need to calibrate each transistor independently as they have mildly different value but not a big deal.

Anyway, If I can do some simple math, the ADC takes in 8 inputs and uses 4 Arduino pins which means that I will top out at a total of 24 Phototransistors for 12 digital pins (or 32 if I use four of the analog pins as well). The breadboard is getting crowded, but I think I could make a small mock-up…

But what if I want more Phototransistors? Is it possible to use more phototransistors without needing another Arduino? Any thoughts?

Thanks again for all your input so far- as you can see, I have put it to use!