I have an Arduino Due and i am using a CNY17 optocoupler to sense a 12v brake signal from a car. The 12v signal is going thru a 1K resistor to the opto on pin 1, pin 2 to the ground. 3.3v is going thru a 1K resistor to opto pin 5 and pin 4 to the ground. Pin 5 is connected to a digital input of the Arduino Due.

All is working good when the 12v is connected i get a 0 and when not connected a 1 on my digital port.

Now when i touch the wire going from the opto to the digital input is floating between 0 and 1. The voltage on the pin of the opto stays 3.3v but on the digital input voltage drops around 1.6 volts. the 1.6v would explain why it floats between 0 and 1. What i don't understand is why it would drop when i touch the wire could someout explain that to me?


simulate this circuit – Schematic created using CircuitLab

  • 1
    \$\begingroup\$ Could you add clarification as to what a "CNY17" is? Also, add a schematic. There is a button on the top of the editor that makes this very easy. \$\endgroup\$
    – uint128_t
    Commented Jan 27, 2016 at 17:01
  • \$\begingroup\$ Add the diagram as suggested and also mark the spot you are touching. \$\endgroup\$
    – JRE
    Commented Jan 27, 2016 at 17:03
  • \$\begingroup\$ Your second paragraph says it works, but the third says it doesn't. Different conditions? Different connections? ?? \$\endgroup\$ Commented Jan 27, 2016 at 17:25
  • \$\begingroup\$ Thank you for the tip of the schematic thats very usefull!! It works fine exept as soon as i get close to the input with my finger or when i touch the wire going to the arduino input. then the digitalread is going crazy. \$\endgroup\$ Commented Jan 27, 2016 at 18:31
  • \$\begingroup\$ Is the 0V of you microcontroller connected to CNY17 pin4? You say that the voltage on the opto output remains at 3.3V but the digital input voltage is at 1.6V. How and where did you measure the 1.6V, is the opto output pin not the same (connected by a piece of wire) as the digital input terminal? \$\endgroup\$ Commented Jan 27, 2016 at 18:41

1 Answer 1


There are two things I note:

  1. Your pull-up resistor R2 is very strong. When 12V is on, it will fire up the LED which fires the phototransistor inside the CNY17. This will pull the line going to the Arduino to 0. The amount of current sourced is generally based on the CTR, or current transfer ratio. I think you have enough headroom here as even at 40% CTR, your 12mA of forward current (12V / 1000 ohms) should source at least 4.8mA, overcoming that 1K resistor, but there's no reason that can't be a 10K resistor on the Arduino side to give you more headroom.

  2. The base is floating. It may help with noise immunity to tie the base (Pin P6) to the emitter (Pin P4) through a 100K resistor.

Touching that wire (which is biased quite strongly to 3.3V right now) shouldn't cause a DC reading of 1.6V unless something is horribly wrong, or you are grounded (and conductive) very, very oddly. Did you measure with a DMM?

Finally, I note that both sides of your opto are using the same GND symbol. If all you need is to sense 12V going into the Arduino, and you don't need isolation, you can divide it down such that some valid input voltage ranges matches the VIH spec of the Arduino input.

Alternately, with a sufficiently large resistor (like 100K), you could apply 12V directly and not take damage, as barely any current will flow, though this can be dangerous should you accidentally short across that resistor. This of course assumes that the inputs don't have a particularly high bias current requirement either.


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.