How to use an opto-interrupter with Arduino - Page 1
Forum section: electronics / beginners

author: unknowndomain
author_rank: Regular Contributor
timestamp: June 02, 2013, 07:54:38 am
content: Hello folks,I am not usually one to ask questions, mostly I figure things out eventually myself with research but I am properly stumped on this one...I am trying to get an Arduino to sense the output from an opto-interrupter, Kingbright KTIR0221DS, which I bought from Farnell in the UK (Datasheet).I have the photo-diode attached to a 220R resistor on the high side, and directly to ground on the low side, however I can't verify if this is working because it is IR and my iPhone can't see this wavelength I guess.I have the photo-transistor pair connected directly to 5V on the high side and to ground through a 10K resistor on the emitter, there is a tap between the two which I take off to A0 on the Arduino.This reads a value of about 700-800 (75%) on the Arduino ADC. Equally if I flip the circuit so it is pull up, not down this doesn't work either.I am really lost as to what to do, I have followed several online tutorials with no luck. What is the correct circuit and values for this kind of component, how can I check it isn't a faulty component?ThanksTom

author: AndreasF
author_rank: Frequent Contributor
timestamp: June 02, 2013, 09:10:07 am
content: The resistor on the diode side sounds reasonable. I guess you could verify that this side is working by measuring the current to see if it's in the expected range (just under 20mA).The test circuit on thedata sheethas the emitter tied to ground with the output at the collector, pulled high (though a resistor) to Vcc . This should be (pulled) high with no input, and low with an input.

author: Paul Price
author_rank: Super Contributor
timestamp: June 02, 2013, 09:32:39 am
content: To test your setup without a multimeter or a scope:Connect photo-interrupter pin 1 to the positive supply (+3.3 or +5V) through a 220 ohm resistor, pins2 and pin 3 connect to ground.Connect the cathode of a red LED to pin 4 and the anode to a 470 ohm resistor connecting to +5V or or +3.3. The test LED should light up. If you take a small piece of something (opaque to light) like a butter knife blade or a piece of black paper, in the gap, then the LED should turn off.If it don't work hooked up like this, you've got a defective interrupter. You must always connect pins 1 and 4 to the most positive voltage of your circuit and pins 2 and 3 to the ground. A correct valued resistor is needed on both pin1 and 4 or else both pin 2 and 3 pins.I think your problem is using a 10K resistor on the output transistor of the interrupter,. It should be smaller, closer to 470 to 1000 ohms.

author: unknowndomain
author_rank: Regular Contributor
timestamp: June 03, 2013, 11:05:07 am
content: Quote from: AndreasF on June 02, 2013, 09:10:07 amI did try this the other day and found it strange that the reading was only 3mA, I have tried with a couple of resistors and second one read 5mA but nothing near 20mA, I also tried switching out for another couple opto-interrupters and they do the same or similar values. Then I thought, perhaps the Arduino isn't providing 5V but I verified that it is. I also checked the resistors on the meter and they read as 220ohms give or take a little.The whole thing baffles me, no wonder I can't get a reading though, the LED probably isn't lit, what should I do?

author: Paul Price
author_rank: Super Contributor
timestamp: June 03, 2013, 12:53:27 pm
content: Even 3 mA should be enough. It might be that the light in the room you are in are reaching the photo-detector transistor in the interrupter and saturating it.When you reply, you fail to clearly describe how your testing circuit is actually connected and I suspect you still have some issues here.When the LED inside the optical interrupter is on, pins 1 and two show about 1.1 to 1.3 volts across these two pins even if you try a large range of resistor values.. If you don't get that reading you are hooking it up wrong. If you hook up the LED side correctly the current will always increase with any voltage applied(make sure you are using a current limiting resistor).Use a multimeter to make a measurement across pins 1 and 2 of the interrupter? Remember pin 1 must be the most positive voltage, a resistor is necessary in series on either pin 1 or 2 and then that pin 2 connects to ground.Did you try the test I recommended?Can you make a drawing to clearly show your test connection? it is very easy to use a PC scanner to scan in a hand-drawing into a computer and attach it as a .jpg or .png picture in your reply.

author: unknowndomain
author_rank: Regular Contributor
timestamp: June 03, 2013, 01:53:09 pm
content: Quote from: Paul Price on June 03, 2013, 12:53:27 pmI did try covering it and it made no improvement, or variation.Quote from: Paul Price on June 03, 2013, 12:53:27 pmQuote from: Paul Price on June 03, 2013, 12:53:27 pmQuote from: Paul Price on June 03, 2013, 12:53:27 pmNo, I was following the instructions on the first message by the Andreas as they related to the actual LED first, so although I read your message I didn't test that yet. In the above message you refer to pins 1, and 2 but they are not labeled on the device, instead I looked at the datasheet and saw these referred to the anode and cathode of the diode and presumed this is what you meant, this device is marked with a + on one side and a D on the other.Quote from: Paul Price on June 03, 2013, 12:53:27 pm

author: dr_p
author_rank: Frequent Contributor
timestamp: June 03, 2013, 01:57:33 pm
content: mobile phone cameras are sensitive to IR, you you can easily verify that it's working. For instance:

author: unknowndomain
author_rank: Regular Contributor
timestamp: June 03, 2013, 02:07:07 pm
content: Hey,I you read my original post I said that my iPhone isn't able to pick up the IR so it is either not working, highly directional or the wavelength is to high.Tom

author: Paul Price
author_rank: Super Contributor
timestamp: June 03, 2013, 02:44:00 pm
content: One picture is worth a thousand nerds!If you are reading 3.5V across the LED diode as shown in your diagram, then you've blown out the Infrared LED inside the opto-interrupter. Take care to measure the 220 ohm resistor you show in series with the LED inside it.Perhaps you have used a 22-ohm or 2.2 ohm or .22-ohm resistor instead?

author: unknowndomain
author_rank: Regular Contributor
timestamp: June 03, 2013, 03:09:34 pm
content: Quote from: Paul Price on June 03, 2013, 02:44:00 pmHey Paul.I have tried three others, the resistor is definitely the right one, not least because I used them fresh out of a new pack labeled 220ohm, but because it's red, red, brown and because the meter reads 220ohms too. I also swapped the resistor with another and it still reads the same.Finally to confirm I used another opto-interrupter to confirm this.

author: Paul Price
author_rank: Super Contributor
timestamp: June 03, 2013, 04:43:28 pm
content: Is it all possible that you have the interrupter placed 180-deg backwards in your test circuit? Otherwise the LED inside the interrupter is certainly zorched. If you put a voltmeter on the output (negative lead to ground) you should certainly see a change in voltage when you slide anything close to being opaque(even a piece of paper) into the gap of the opto-interrupter.I assume you do with this test with the Arduino disconnected from the output, it could be remotely possible that you have configured your program to set the pin connected as an output, rather than an input, as required. So, for the purpose of this test, just connect a volt meter to the interrupter side of the 10K resistor to ground.I see clearly everything is connected correctly, if the +buss breadboard rail is the one furthest from the bottom.Some opto-isolators that I have salvaged from used PC printers have the collector-emitter connections arranged so that the plus side of the LED corresponds to the NPN collector side of the output. But I checked the spec sheet and it shows clearly the opposite. Just to be sure, try reversing the output leads. This test will in no way damage the output stage.

author: Paul Price
author_rank: Super Contributor
timestamp: June 03, 2013, 05:04:06 pm
content: The elephant in the room here is themeasured LED voltage of the interrupter. If it is above 1.5V approx. it is zorched.

author: TerminalJack505
author_rank: Super Contributor
timestamp: June 03, 2013, 08:30:44 pm
content: Your schematic is wrong. The datasheet shows how you need to hook up the detector. You have the emitter tied to +5V. You need to tie it to GND. The collector resistor needs to be connected to +5V.

author: Paul Price
author_rank: Super Contributor
timestamp: June 03, 2013, 08:54:17 pm
content: TerminalJack505:If you look at the breadboarded circuit, it clearly is wired correctly according to the pinout diagram in the spec sheet.

author: TerminalJack505
author_rank: Super Contributor
timestamp: June 03, 2013, 09:05:47 pm
content: I can't tell which pins the wires are going to at the back of the device. I do see a 10k resistor going to ground, though, which would match with his schematic.

author: MasterOfNone
author_rank: Regular Contributor
timestamp: June 03, 2013, 11:40:36 pm
content: The markings on the device might be misleading. Checkout the image and website link.http://www.digitaldandt.org/db/index.php/datasheet/show/929

author: unknowndomain
author_rank: Regular Contributor
timestamp: June 04, 2013, 02:49:11 pm
content: Quote from: MasterOfNone on June 03, 2013, 11:40:36 pmYou are a genius! This is exactly what the problem was...E != Emitter on the TransistorsD != DiodeD= DarlingtonE = Emitter (LED)Who the ...... does that?!?!Seriously, WHY!Thanks everyone, the values are nice and even now so I can differentiate easily between the open state and closed.

author: Paul Price
author_rank: Super Contributor
timestamp: June 05, 2013, 02:19:16 am
content: You almost got it right...E =Emitteras in "Something that is theEmitter, the source of something thatEmitslight"D=Detectoras in "Something thatDetectslight"I told you to try switching the leads to the device to see it made a difference. You had the LED back-biased to measure 3V across it!

author: unknowndomain
author_rank: Regular Contributor
timestamp: June 05, 2013, 07:12:08 am
content: Quote from: Paul Price on June 05, 2013, 02:19:16 amI did, I just didn't switch the polarity, then the other time I tried it I looked at the image from my camera for IR not the sensor, my camera can't see this IR light it's too high a wave length.Thanks again!