2
\$\begingroup\$

This question relates to my earlier question on how to wire an optointerruptor:Figuring out wiring of optical encoder

I was able to get the optointerruptor working using the circuit below. I wanted to add an LED to indicate sensor state. The blue LED in the image below is what I tried initially. However this doesn't work: the result is that with the LED connected, it will light and show state, but the input to the microcontroller (an Arduino) stops showing correct state. This is totally confusing. Why would the LED interfere what the Arduino can read (as a digitalRead)?

I've breadboarded the circuit and it seems to work - but in my actual project it doesn't. As a starting point in figuring this out, is the circuit below wrong?

enter image description here

\$\endgroup\$

4 Answers 4

1
\$\begingroup\$

Check the minimum voltage that will be accros the LED for the current you are giving it, then compare that to the minimum guaranteed voltage the arduino requires to interpret the digital signal as high. You will probably find that the former is less than the latter.

As always you need to read the datasheets before just hooking stuff up.

A better way to do the indicator is to have the micro produce a separate signal just for that purpose. This will be a separate digital signal, so driving the LED is decoupled from the current and voltage requirements of the detecting circuit. The firmware also doesn't have to exactly mirror the detection signal on the LED. It can, for example, stretch short pulses to some minimum value to make them easier to see.

\$\endgroup\$
2
  • \$\begingroup\$ So the LED is draining current that the Arduino input pin needs to read the sensor output as HIGH? That makes sense. Any other way I can wire this to prevent that? I know I could use the Arduino to control a state LED but that means more wires and additional code (admittedly minimal) \$\endgroup\$
    – spring
    Dec 7, 2013 at 15:55
  • \$\begingroup\$ @skinny: You could use a transistor to sense the signal and drive the LED accordingly. \$\endgroup\$ Dec 7, 2013 at 17:21
0
\$\begingroup\$

Olin is correct - the LED is limiting the voltage at the output. An alternative to using another I/O line to mimic the output would be to add a PNP transistor using the circuit below.

enter image description here

R2 and R3 form the load for the optotransistor (roughly equal to the original 1k0 value). When the optotransistor is ON this forms a potential divider circuit giving a 2V drop (approx.) across R2 (470R).

This allows Q1 to be turned ON as a small base current (about 0.3mA) will flow through R4 (4k7).

With the optotransistor OFF no base current can flow through R4 ( because there is no voltage drop across R2 ) and so Q1 is turned OFF as well.

R5 limits the current through LED1. Depending on the colour of the LED used this value produces a current of a couple of mA.

Values of resistance are not particularly critical and Q1 can be just about any general purpose PNP transistor.

\$\endgroup\$
1
  • \$\begingroup\$ There is no need for R2 and R3 to be separate resistors. With the right choice of R4, R3 can be eliminated (replaced by a wire). Note also that your circuit inverts the LED from the OP's original. \$\endgroup\$ Dec 8, 2013 at 13:34
0
\$\begingroup\$

As usual, Olin is correct.

If you're looking for a very simple quick test, perhaps you might prefer the following:

schematic

simulate this circuit – Schematic created using CircuitLab

This circuit dimly lights the green LED when the interrupter is "on". The circuit JIm Dearden shows gives a much brighter and easier-to-see indicator, but at the cost of extra complexity.

\$\endgroup\$
0
\$\begingroup\$

You can also try to connect the LED to the input side of the opto, the transistor will be biased by the current flowing through the opto-diode resistor and will turn on the led.

led indicator

Edited: In the above circuit the current of the led goes through the opto diode so a better alternative is to use a PNP so that the current of the led doesn't go through the opto diode, this way the led can work with a different current than the opto-diode

led indicator2

\$\endgroup\$
2
  • \$\begingroup\$ What's the transistor for? Why not just connect the two LEDs in series? \$\endgroup\$
    – Dave Tweed
    Dec 8, 2013 at 17:42
  • \$\begingroup\$ With the use of a transistor the current of the Opto-diode can be different from the one of the LED, if they are in series then they will both have the same current but you are right that in my first schematic the current was common anyway so I have posted a second schematic using a PNP. \$\endgroup\$
    – alexan_e
    Dec 8, 2013 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.