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?
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.
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.
You should be able to see it glowing if you look at it through a digital camera.
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.
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.
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.
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?