# Determining is relay switched.

Hi my brains cant figure this out. How i can get signal to arduino when switch (at left) is switched on and current flows trought. Maybe transistor but how?

If the 12V are stable (not a car for example) you can use a simple voltage divider (two resistors) to generate a 5V signal compatible with your Arduino. But your diagram makes no sense as if the switch is closed you have a short circuit or did I misunderstood something?

It is actually a car so divider wont work so well unless there is regulatoe, its just very simplified picture (forgot add the load)

Where is the load? Is it between the 12V and the switch?

If so, simply also connect the Arduino to the pin via a resistor (of let's say 4k7) to protect the Arduino.

okay sorry guys this is really hard to explain, even in my own language. So it is this GPS tracker box, i wanted to use its ability to cut off engine to lock and unlock the doors. Actual switch is in tracker box propably npn type transistor where i have no access. So i wanted to get signal to arduino when gps tracker switches npn transistor on and when it turns it off. I can do this with relay and feed relay from car and set signal line to arduino but i was looking some other way to do it

Here is very very basic schematic what it was meant to do

GROUND---(switch) Npn transistor inside of gps box ---Relay--- +12v

But what does it drive now? And:

septillion:
Where is the load? Is it between the 12V and the switch?

And a picture drawing says more then a 1000 words (A quick hand drawing most often is better then any Fritzing madness...)

If so, simply also connect the Arduino to the pin via a resistor (of let's say 4k7) to protect the Arduino.

With a simple resistor you maybe limit the current but still have over 12V on the Arduino pin. I didn't try myself but according to the datasheet this at least ruins the pin if not the whole processor. The OP needs two resistors forming a voltage divider and connects the middle to the Arduino pin.

Because it's a car I would protect the Arduino even more and connect the switch output to an optocoupler and the optocoupler output to the Arduino input pin.

Nope, there is no 12V on the pin All thanks to the clamping diodes on the pins. They don't let the voltage rise above (approximately, it's a bit higher but withing spec) of Vcc. And you may not stress those diodes to much (which you would if you applies 12V directly) but if you limit the current to be under 1mA it's fine. But I see I made an error because 4k7 will result in to much current. But get a 10k or 22k and your fine (12V - 5V) / 22k = 0,3mA)

And if you want a bit more protection you could add a small ceramic cap between the pin and GND.

Maybe a double pole relay, one can be used as input then. Maybe voltage current detector like INA219. No need for voltage devider.

@Welsyntoffie, because we all now a IC is easier/cheaper then a resistor?

a simple voltage dividerwill be fine with addition of a 5v zenier diode between gnd and the input pin to protect from over voltage

Even without a zener it's fine as long as you know the input range.

And it's even fine with a single resistor instead of a divider