Go Down

Topic: How to interface with a phototransistor (Read 7265 times) previous topic - next topic

RichP

Hello all,

I'm new to the world of Arduino and thoroughly enjoying things so far. I decided to go a little further with my experiments, and try hooking up a phototransistor.

The thing I'm a little unclear about though, is exactly how I'd go about hooking that up to the Arduino, and interpreting the output (I just tried to paste a link to the product into this post, but the forum software won't let me do it until I've made 'one normal post', so I'll follow this post up immediately with the link to the sensor!) :)

I've done a bit of digging around and I'm not really sure how to go about hooking it up and interpreting the readings with the Arduino just yet.

Would anyone be able to offer some advice/pointers?

Many thanks,

/Rich.

RichP

For reference, this is the sensor that I have purchased:
http://www.maplin.co.uk/module.aspx?moduleno=12709

There is a link to a schematic on the site but it doesn't look particularly clear...

roboter

I ordered this 1 - still waiting :)
Teh Hex Pummer
http://www.solarbotics.com/products/k_hp/

Grumpy_Mike

Just looked at the schematic and it is total pants.

Wire up anode to +5v, cathode to a resistor (between 100R and 300R) other end to ground. You should be able to see it glowing if you look at it through a digital camera.

Next the sensor. Emitter to ground, collector to a digital input pin, plus a resistor (about 10K) from that input pin to 5V.

Read the value from the pin, a zero will indicate light is being reflected back, a one indicates no light reflected.

mem

#4
Feb 09, 2009, 02:08 pm Last Edit: Feb 09, 2009, 02:09 pm by mem Reason: 1
Quote
Next the sensor. Emitter to ground, collector to a digital input pin, plus a resistor (about 10K) from that input pin to 5V.

Or you can use the internal pull up resistors
You will need to set the pinMode to input anyway:
 pinMode(pin, INPUT);           // set pin to input
if you write a HIGH value after the pin is set for input then the internal pull-up resistor will be connected:
digitalWrite(pin, HIGH);       // turn on pullup resistor
This saves you connecting an external 10k resistor to the pin.

Quote
You should be able to see it glowing if you look at it through a digital camera.

Nice tip

Grumpy_Mike

Hi  mem,
I did think of the internal pull ups but I think you want to pull more current through the photo transistor than they would give. The edges can be a little slow if you don't give them enough current. But in this application he will probably get away with it.

RichP

Hi all,

The schematic on the Maplin site is indeed - pants. :)

Thanks to everyone so far for all your help. I'll give this a go later this evening and post my results.

Again, thanks for the speedy replies!

/Rich

RichP

#7
Feb 09, 2009, 04:15 pm Last Edit: Feb 09, 2009, 04:15 pm by brainthings Reason: 1
Hi all,

Ok - bear with me here, new to this.

So I've connected the photoresistor to the breadboard and the arduino. I have verified that the emitter is wired correctly (can see the red light being emitted throuh a digicam - great tip!).

I'm having trouble actually wiring up the sensor correctly.

The sensor is connected as follows:

  GND -- [ SENSOR ] -- Resistor (10k) -- Digital Pin 7

My question is: where do I connect the +5v?

Thanks for your patience and support.

/Rich

retrolefty

Quote
The sensor is connected as follows:

 GND -- [ SENSOR ] -- Resistor (10k) -- Digital Pin 7

My question is: where do I connect the +5v?

Thanks for your patience and support.

/Rich


Ground should wire to the cathode lead of the photo diode. The anode lead of the diode should wire to the 10k resistor. The other end of the resistor should wire to +5vdc. Digital pin 7 should wire to the junction of the diode anode and 10K resistor.

Lefty

Grumpy_Mike

Hi  lefty,
It's not a photo diode he has but a photo transistor.

Quote
GND -- [ SENSOR ] -- Resistor (10k) -- Digital Pin 7


is not quite right it should be:-
Quote
GND -- [ SENSOR ] -- Resistor (10k) -- +5v
                             |
                     Digital Pin 7


That is Pin 7 and the sensor and the resistor all together.

RichP

Hi Grumpy_Mike,

That's exactly what I needed - thank you. Now, when the photo transistor is 'open' the input is HIGH. When it is 'reflecting' the input is LOW. Does that sound about right?

Thanks,

/Rich

Grumpy_Mike

Quote
when the photo transistor is 'open' the input is HIGH. When it is 'reflecting' the input is LOW.


Spot on. Now make it happen.  ;)

Go Up