I'm tying to figure out how to have an optical interrupter connect to my Arduino, but I have a bit of an issue. Namely, the interrupter seems to be reacting to the ambient light in the room, rather than the infrared light beam that is supposed to be crossing it.
Yes, but the problem is that it does not seem to be reacting to it's own built-in light source. If I turn off the room light, the interrupter should still keep the LED on, as it has it's own built-in IR LED. But it doesn't. That's the issue.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?
Also post a picture of your project so we can see the physical arrangement.
Based on the datasheet, I've come up with a suggested circuit to try (untested):
Here, the D2 input goes HIGH when when the IR beam is interrupted. The signal is normally LOW.
If you switch the transistor and 10K resistor locations, then the D2 input will go LOW when when the IR beam is interrupted. For this arrangement, the signal would be normally HIGH.
I've tried looking at the optical interrupter through a digital camera, after first looking at the end of a TV remote (while sending a command) to see what to expect. I didn't see anything on either end of the interrupter, even with switching the polarity to the IR LED. I've also tried multiple interrupters with the same results.
Here's how I have the breadboard set up:
The 1M resistor at the top is actually 2M - the software I was using didn't go up this high. As per dlloyd's suggestion, I did try substituting the 2M resistor for a 10K, but this just resulted in the LED not coming on in the first place.
You need to use a resistor of 100-300 ohms for the LED portion of the optointerruptor. If you have already tried reverse polarity, it is possible that the LED has been destroyed.
Avoid Fritzing diagrams -- they are only for complete beginners. Even hand drawn schematics are better.
As per dlloyd's suggestion, I did try substituting the 2M resistor for a 10K, but this just resulted in the LED not coming on in the first place.
Actually, that's good because the output signal is normally LOW. You have to break the beam (with something opaque) to make the signal go HIGH.
The slot is only 1/8" ... try using a coin.
I've tried looking at the optical interrupter through a digital camera, after first looking at the end of a TV remote (while sending a command) to see what to expect. I didn't see anything on either end of the interrupter, even with switching the polarity to the IR LED. I've also tried multiple interrupters with the same results.
You'll not be able to see the beam with a camera because the IRLED is perpendicular to the slot, and of course, the camera will not fit into the slot. To test if the IRLED is functional, you should measure about 1.2V at terminal 1. If you read 5V and it's not reverse connected, then IRLED is blown.
Boardburner2:
led on the right on your breadboard has no current limiting resistor
If you're referring to Reply#6, it's more fritzing dorkery- that's representing the phototransistor, connected to an input pin, which should be pulled up in software (or with a resistor, my preference.)
You can't "REPRESENT" an opto-interrupter. You either have one or you don't. Period. (is is possible to fabricate the interrupter case and install an IR led and a photo transistor to obtain a functioning interrupter but that is obviously not what you have done so you should change your post title to :
"Why can't I use an LDR as an opto-interrupter in normal room lighting ?"
R4 shouldn't be there. The base of the opto transistor is not driven by a hard wired connection such as you've shown using R4. The base is driven by photons traveling through the transparent 5000V isolation barrier that separates the input led from the output transistor. Also your load should go to the collector of the transistor, not the emitter. If you don't mind me asking, what in the hell is a 2 M ohm resistor doing connected to the emitter of the opto transistor ? Also R3 doesn't belong there. It could be a pullup for the transistor but it should be 10k. Also why is the input of the opto tied high ? Where is you input device for the opto input ? Pin-7 input should come from the collector of the transistor where the 10 k pullup should be connected. There's no reason for a 100 ohm resistor there. Did you just pull that out of the air ? Why is it there ?