Optoisolator confusion.

Hi,

I am building a circuit that will work in a car. The intent is to have something on the car (12V) trigger on the Arduino input pin. I'm using the below circuit and have it working, but I am confused about something. I expected that with no signal on the 12V side, the Arduino input pin (connected to #5 below) would be Low (near 0V). However, I get 5V on #5 until the 12V input is applied (then it drops to near 0v). Also note that I did not connect the ground between #2 and #4 (but have tried with and without and the result is the same). D2 (diode) is also not being used as this is a DC circuit. I can work around this in the sketch, but though this is the way the optoisolator worked. I am using a NTE3041 optoisolator (NPN based).

I can work around this in the sketch, but though this is the way the optoisolator worked.

that is how the opto-isolator output transistor is suppose to work. When no light from the internal led is stricking the transistor it is turned off so the collector 'sees' the full +5vdc. When the led turns on the transistor is turned full on and 'grounds' out the +5vdc from the collector load resistor. It's simple in software to treat a low on the input pin as 'on' and a high input as off, so this is not an issue at all. By the way if you want to save having to use the external collector load resistor R3, just wire the collect directly to a input pin and then enable the pin's internal pull-up resistor.

Lefty

Also note that I did not connect the ground between #2 and #4 (but have tried with and without and the result is the same).

The ability to [u]not[/u] connect the grounds is one of the primary advantages of using an opto[u]isolator[/u]. It uses [u]optical[/u] coupling to allow you to [u]isolate[/u] the input and output circuits.

D2 (diode) is also not being used as this is a DC circuit.

It wouldn't hurt to leave it in. There's lots of noise in an automotive environment.

Don

The ability to not connect the grounds is one of the primary advantages of using an optoisolator. It uses optical coupling to allow you to isolate the input and output circuits.

Also note that I did not connect the ground between #2 and #4 (but have tried with and without and the result is the same).

Correct, if you connect the grounds there is no advantage to using a opto Vs just using a simpler and cheaper npn transistor. Don't connect the grounds.

Lefty

Thanks guys...

You could also just use a couple of resistors as a voltage divider. When 12-14.2v (car running) is applied to the top of the divider, a High will be presented at the input.

if you use an 820 and 430 in series, the voltage should not exceed 4.88v with the car running.

The alternative is to feed your 12v through a resistor to the base of an NPN transistor, and have the collector make the input LOW. If you are worried about excess voltage (base to collector short), you could add a 4.7v zener across the base. This is an inverting cct, just like the optocoupler.

Mark