Author Topic: How to use an opto-interrupter with Arduino  (Read 20738 times)

0 Members and 1 Guest are viewing this topic.

Offline unknowndomainTopic starter

  • Regular Contributor
  • *
  • Posts: 63
  • Country: gb
    • Blog
How to use an opto-interrupter with Arduino
« on: June 02, 2013, 07:54:38 am »
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?

Thanks

Tom
 

Offline AndreasF

  • Frequent Contributor
  • **
  • Posts: 251
  • Country: gb
    • mind-dump.net
Re: How to use an opto-interrupter with Arduino
« Reply #1 on: June 02, 2013, 09:10:07 am »
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 the data sheet has 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.
my random ramblings mind-dump.net
 

Offline Paul Price

  • Super Contributor
  • ***
  • Posts: 1433
Re: How to use an opto-interrupter with Arduino
« Reply #2 on: June 02, 2013, 09:32:39 am »
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.
« Last Edit: June 02, 2013, 10:20:57 am by Paul Price »
 

Offline unknowndomainTopic starter

  • Regular Contributor
  • *
  • Posts: 63
  • Country: gb
    • Blog
Re: How to use an opto-interrupter with Arduino
« Reply #3 on: June 03, 2013, 11:05:07 am »
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).

I 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?
 

Offline Paul Price

  • Super Contributor
  • ***
  • Posts: 1433
Re: How to use an opto-interrupter with Arduino
« Reply #4 on: June 03, 2013, 12:53:27 pm »
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.
 

Offline unknowndomainTopic starter

  • Regular Contributor
  • *
  • Posts: 63
  • Country: gb
    • Blog
Re: How to use an opto-interrupter with Arduino
« Reply #5 on: June 03, 2013, 01:53:09 pm »
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.

I did try covering it and it made no improvement, or variation.

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?

No, 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.

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.


 

Offline dr_p

  • Frequent Contributor
  • **
  • Posts: 309
  • Country: ro
Re: How to use an opto-interrupter with Arduino
« Reply #6 on: June 03, 2013, 01:57:33 pm »

mobile phone cameras are sensitive to IR, you you can easily verify that it's working. For instance:


 

Offline unknowndomainTopic starter

  • Regular Contributor
  • *
  • Posts: 63
  • Country: gb
    • Blog
Re: How to use an opto-interrupter with Arduino
« Reply #7 on: June 03, 2013, 02:07:07 pm »
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
 

Offline Paul Price

  • Super Contributor
  • ***
  • Posts: 1433
Re: How to use an opto-interrupter with Arduino
« Reply #8 on: June 03, 2013, 02:44:00 pm »
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?
« Last Edit: June 03, 2013, 02:53:34 pm by Paul Price »
 

Offline unknowndomainTopic starter

  • Regular Contributor
  • *
  • Posts: 63
  • Country: gb
    • Blog
Re: How to use an opto-interrupter with Arduino
« Reply #9 on: June 03, 2013, 03:09:34 pm »
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?

Hey 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.

 :-DMM

 

Offline Paul Price

  • Super Contributor
  • ***
  • Posts: 1433
Re: How to use an opto-interrupter with Arduino
« Reply #10 on: June 03, 2013, 04:43:28 pm »
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.
« Last Edit: June 03, 2013, 05:55:59 pm by Paul Price »
 

Offline Paul Price

  • Super Contributor
  • ***
  • Posts: 1433
Re: How to use an opto-interrupter with Arduino
« Reply #11 on: June 03, 2013, 05:04:06 pm »
The elephant in the room here is the measured LED voltage of the interrupter. If it is above 1.5V approx. it is zorched.
« Last Edit: June 03, 2013, 05:56:19 pm by Paul Price »
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1310
  • Country: 00
Re: How to use an opto-interrupter with Arduino
« Reply #12 on: June 03, 2013, 08:30:44 pm »
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. 
 

Offline Paul Price

  • Super Contributor
  • ***
  • Posts: 1433
Re: How to use an opto-interrupter with Arduino
« Reply #13 on: June 03, 2013, 08:54:17 pm »
TerminalJack505:

If you look at the breadboarded circuit, it clearly is wired correctly according to the pinout diagram in the spec sheet.
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1310
  • Country: 00
Re: How to use an opto-interrupter with Arduino
« Reply #14 on: June 03, 2013, 09:05:47 pm »
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.
 

Offline MasterOfNone

  • Regular Contributor
  • *
  • Posts: 123
Re: How to use an opto-interrupter with Arduino
« Reply #15 on: June 03, 2013, 11:40:36 pm »
The markings on the device might be misleading. Checkout the image and website link.
http://www.digitaldandt.org/db/index.php/datasheet/show/929


 

Offline unknowndomainTopic starter

  • Regular Contributor
  • *
  • Posts: 63
  • Country: gb
    • Blog
Re: How to use an opto-interrupter with Arduino
« Reply #16 on: June 04, 2013, 02:49:11 pm »
The markings on the device might be misleading. Checkout the image and website link.
http://www.digitaldandt.org/db/index.php/datasheet/show/929




You are a genius! This is exactly what the problem was...

E != Emitter on the Transistors
D != Diode

D= Darlington
E = 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.
 

Offline Paul Price

  • Super Contributor
  • ***
  • Posts: 1433
Re: How to use an opto-interrupter with Arduino
« Reply #17 on: June 05, 2013, 02:19:16 am »
You almost got it right...


E = Emitter as in "Something that is the Emitter, the source of something that Emits   light"
[/b]
D=Detector as in "Something  that Detects light"

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!
« Last Edit: June 05, 2013, 02:25:46 am by Paul Price »
 

Offline unknowndomainTopic starter

  • Regular Contributor
  • *
  • Posts: 63
  • Country: gb
    • Blog
Re: How to use an opto-interrupter with Arduino
« Reply #18 on: June 05, 2013, 07:12:08 am »
You almost got it right...


E = Emitter as in "Something that is the Emitter, the source of something that Emits   light"
[/b]
D=Detector as in "Something  that Detects light"

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!

I 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!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf