Detecting 12v dc

Hey guys, I need to detect the presence of 12v power from a few different sources. I want to connect to a trailer plug on the back of a truck and detect which lights are active (brake, turn signal, etc). My only thought is a voltage divider (resistors?) and a digital input pin each. I only need to know on or off state, nothing more. What would be the best (and safest for the Atmega) way?

I agree - a voltage divider. Just remember to design it to not exceed 5v based upon the highest voltage that may be measured - something like 14.5v

I would advise a pair of catching diodes as well.
http://www.thebox.myzen.co.uk/Tutorial/Protection.html

Ok, so a voltage divider using a 2.2k and a 1k would keep my input voltage under 5 for all the way to 16v source. 1/4 watts should be more than enough.

Also a signal diode between my input pin and ground, and another between my input pin and my 5v supply to the arduino.

Connect both grounds.

If this all sounds good, I'll give it a try soon.

Yes it sounds good.

Catching diodes only duplicate protection diodes on the chip - try using a potential divider using a 10k resistor and a 4.3V or 3.9V zener - this will protect against much higher voltages than 12 (say a 24V truck), work when the vehicle battery is low (starter motor), and the zener acts as a protection diode for reverse polarity too.

Catching diodes only duplicate protection diodes on the chip

No not not true, while there are diodes on the inputs of all chips the diodes on the chip can only handle very small amounts of current certainly not enough to offer any sort of protection from over voltage. They are designed to cope with the small currents found in very mild static discharge.

A zener diode is another way of protection but you should use a 5V1 diode with a series resistor not a lower value one.

Yeah a 5V1 zener and series resistor and then a pot in parallel with the zener could work nicely.

Or you could put in an opto isolater just to absolutely safe.

I'm looking to make this project wireless, and the XBee radios seem perfect for what I need. It looks like if I use the I/O passing feature of them, I won't need a seperate microcontroller on the transmitting (current sensing) end. XBees are 3.3v devices, though.

If I change the resistor from a 2.2k to a 3.3k in the voltage divider, would that be all I need to change, or are there other things I need to consider here?

Ok, so a voltage divider using a 2.2k and a 1k would keep my input voltage under 5 for all the way to 16v source. 1/4 watts should be more than enough.

Also a signal diode between my input pin and ground, and another between my input pin and my 5v supply to the arduino.

Connect both grounds.

If this all sounds good, I'll give it a try soon.

What kind of signal diode did you use?

Thx Andy

What kind of signal diode did you use?

Any low cost sort. I have yet to see one that won't do.

I just wanted to add that sensing the 12v works perfectly! I have a tendency to not follow up, which I'm working on, and just wanted to say thanks to everyone!

Alright, I have a new question, not sure that I should make a new thread for it, though. It looks like I may not have an always available 12v power source. Can I use the same wires that I'm using to sense 12v, to also power my xbee, assuming I pass them individually through diodes on the way to my power rail? The XBee seems to work and transmit instantaneously, so 'boot-up' time is not a problem. I'm just wondering if there are any other considerations I should take for this. I'd rather not fry another XBee in testing.

EDIT: Dang, I just fried my second XBee! My circuit is exactly as drawn below, except that there are 4 pins sensing instead of just the one.

I notice when my XBees are fried when the ASC LED stops blinking. The XBee is warm, and my 3.3v regulator is hot. I fried one running from a 12v wall adapter and the other one from a 9v battery. My XBee on the receiving side is powered by the same type regulator and has same capacitors. It has been fine.


Both times I fried an XBee I was testing the sensing part by closing the switch shown above. I ran this circuit from a truck for a long time with no problems. The difference between the setup on my desk and on the truck is that on the desk I was using the same source to power my regulator and go across my switch. On the truck I was powering from a 9v and sensing 12v from the truck. (Didn't have an always on 12v available)

I read 12.33v from my wall adapter and 3.28v or so from my regulator. I also get about 2.86v going to my digital input on the XBee from the voltage divider.

The only thing I can think of is a bigger better cap on the 12v side of the regulator, since I didn't have a problem when I was running from two seperate power sources.

Can I use the same wires that I'm using to sense 12v, to also power my xbee, assuming I pass them individually through diodes on the way to my power rail?

No because the input pin will be a higher voltage than the power rail due to the drop across the diodes. That is a good way to fry a chip.

With 3k3 and 1K you can't put anything over 14V on the input. I know you measured less than 13, but any other error could leave you in a dangerous situation. If for example the ground got disconnected from the 1K. Given your recode I suggest next time you use an opto isolator.

It seems like the ILQ615 Transistor Output Optocoupler will do what I want. I think. It also has the upside of inverting the logic, which I needed to do anyway.

Assuming I bring in the inputs this way, I can power my device from the four different on-and-off 12v sources though diodes.

I can power my device from the four different on-and-off 12v sources though diodes.

I am not sure what these sources are, but if they all share a common ground and you can guarantee there is always at least one on at any time and you put it through a regulator then yes.

These sources are wires on a truck's pigtail for trailer lights. They should all be the same 12v-ish, and they all share a common ground. I can't guarantee that at least one will always be on, though when none of them are on, my project doesn't need to be on either. My receiver defaults properly when there is no signal, and the xbee comes up and links to my receiver instantaneously in IO passing mode.

If you are designing for a car you may want to have a look at this http://www.eet-china.com/ARTICLES/2003MAY/PDF/2003MAY26_POW_AN04.PDF.

Then you can decide what protection you will need.

Udo

I should make any device for use in a car tolerant of 120V spikes? That's scary.

Depends if you need it to work reliably. The point is that the 12V power supply in a car

1) is very well understood 2) may be pretty "dirty"

Once you know it you can deal with it. But this is the reason why 12V devices for cars are either somewhat expensive or unreliable. Unreliable usually translates to "may only be used while the engine is not running". The manual will typcially not hint at "if you use it while the engine is running you might damage your device".

Udo