# Detect car +12V using Arduino

I am looking to detect 12+V from a car wire using an Arduino.

I have found the following schematic:

I know how crazy automotive voltage can get so I just want to make sure the schematic I found above will accommodate the crazy random currents that the car could produce.

Also, wouldn't I need some type of heat sink taken that I am stepping down a +12V to 5V or less? That, in my mind, would produce a pretty good amount of heat?

• A simple resistive voltage divider would work best in this case. A transistor is only needed to step up the voltage for whatever reason. A heat sink is not necessary because the current through the components is not very high. The more power consumed by the components (P = I * V) the more heat will be dissipated. en.wikipedia.org/wiki/Voltage_divider – Kurt E. Clothier Jun 24 '13 at 5:10
• Kurt - you're right in theory but in practice automotive systems are subject to lots of variation + spikes + EMF so if you had a divider that produced a reliable logical 1 @5v (so at least 3v, probably 4v to be safe when cranking) from 12v, it may go high enough to damage the arduino when the car is charging (modern "smart" alternators will run to nearly 20v at times). StealthRT's circuit is very reasonable and I've seen many similar use in automotive applications. – John U Jun 24 '13 at 8:23
• For reference: www.industrologic.com/autotransients.pdf – John U Jun 24 '13 at 8:40
• One could follow the 2-resistor voltage divider with a Zener diode, though. – TDHofstetter Aug 24 '14 at 11:53

Knowing that all sorts of weird stuff can happen in automotive power circuits, and not being especially knowledgeable in those systems, I'd err on the side of caution and use an opto-isolator.

simulate this circuit – Schematic created using CircuitLab

Pin 1 = Car 12v R1
Pin 2 = Car Ground
Pin 3 = NC
Pin 4 = Arduino Ground
Pin 5 = Arduino 5v R2
Pin 6 = NC


With this scheme, your Arduino and the car aren't connected electrically at all. At worst, the optoisolator is destroyed, and you can replace it for less than a dollar. Put it in a socket and you won't even need a soldering iron to perform the repair.

R1 was selected such that input voltage transients up to 120V won't exceed the maximum forward current of U1. D1 avoids exceeding the maximum reverse voltage of U1 if the input voltage is inverted. The value of R2 isn't especially critical, so it might as well be the same value as R1.

You won't need any heat sink. Heat is the result of electrical energy being converted to heat, and power is the rate of energy conversion. Power $P$ in an electrical system is the product of current $I$ and voltage $E$:

$$P = I E$$

So, the voltage itself doesn't make heat: it also depends on how much current is flowing. In both these circuits, the current is low enough that the power is small and no heatsink is required.

• +1 for optocoupler, this is practically what they were designed for in the first place. – medivh Jun 24 '13 at 13:38
• I like this. That 4N25 is 25 cents at Jameco (as an example). – mikeY Jun 24 '13 at 15:09
• @Phil Frost do you happen to know what the pin out would be? does the 12v come into pin 1? The 5v comes into pin 5? – StealthRT Sep 12 '13 at 22:05
• @StealthRT if either of those pins see 12V or 5V with respect to their respective grounds (pins 2 and 4), a 4N25 will be destroyed. See the datasheet for the pinout, and acceptable operating conditions. – Phil Frost Sep 13 '13 at 11:42
• As said by @PhilFrost one comment ago, you can use the internal pull-ups instead of R2. These are configure in Arduino using pinMode(pin, INPUT_PULLUP). – heltonbiker Jun 9 '18 at 21:51

You are on the right track, never hurts to have the reverse diode in there although you can belt-and-braces it by sticking an 18-22v Zener in its place.

This is a similar version, widely used and works fine: http://www.msextra.com/forums/viewtopic.php?f=101&t=40330

Some good background info on the nature of transients in automotive applications Harris appnote , for starters this graph says a fair bit:

Here's the circuit from the forum link above:

• Where's the reverse diode / zener you mention? I don't see any such thing in the schematic. – Phil Frost Jun 24 '13 at 13:44
• It's not in that circuit, but if you replace the diode in the OP's circuit with a Zener it will protect against over-voltage as well as reverse-voltage. – John U Jun 24 '13 at 15:25

As noted in the comment to the question: "A simple resistive voltage divider would work best in this case." The voltage divider detects presence of 12V (HIGH @3V3 or 5V) and converts the voltage of the car circuit down to Arduino levels. http://en.wikipedia.org/wiki/Voltage_divider

• Vout = R2 / (R1+R2) * Vin
• 3300/(10000 + 3300) * 12.8V = 3.17V
• 6800/(10000 + 6800) * 12.8V = 5.1V

Be aware that the voltage of the car may be higher than 12V, but at the lead-battery it should not exceed 13.8V for charging reasons. I have used this for detecting a 12V circuit. You can also try to use this to detect charging levels of the battery if you connect it to an Analog input.

• This would normally be OK, although I'm not sure at some of the higher voltages occasionally present (as shown above) how well the internal clamp diodes in an AVR would cope with it. – PeterJ Aug 24 '14 at 9:46
• If you use the 3V3 circuit with a 5V Arduino you should be safe. 3V is still detected as HIGH, and you can have over-voltages of 20V on the divider. – cat Aug 25 '14 at 8:30