Arduino auto electrical question

Hi all. I have an Arduino Uno in a car, running off a USB lighter charger. All good there. However, I want it to be able to sense 12v on a pin. This will be tied into the headlight dimming wire, which goes hot when the headlights are on. How do I safely get that input into the Arduino?

GOOGLE : Read 12V with Arduino. :)

Thanks I was trying a lot of "common ground" searches :)

Or, Google 'voltage divider' for signal only, not power.

Use an opto-isolator.

|500x303

Open collector transistor to pull input with pullup resistor low.

I think I’d go for the opto isolator too.

As an alternative I have seen people use 5v voltage regulators - car supply in; 5v out .

Single transistor is the output of an optocoupler. If one has a lot of signals then cd74HC4049 (inverting) or cd74HC4050(non-inverting) can convert 12+V down to 5V. https://www.ti.com/lit/ds/symlink/cd74hc4049.pdf?HQS=dis-dk-null-digikeymode-dsf-pf-null-wwe&ts=1614725080188

Optos are great, but you'll loose isolation if Arduino GND is connected to Auto GND (unless the Arduino is powered with a separate battery).

dlloyd:

Headlights voltage goes to 13.8V sometimes 14.2V on very cold days (battery temperature compensation). 14.2 / 2 = 7.1V... not good. @Paul__B circuit would be the best for potential divider method. Opto Coupler method isolates any voltage spikes that may appear on the vehicle positive circuits. Tom.... :)

Meh, even without the pulldown, the voltage could reach 52V before it would inject (52-5)/47K = 1mA into the MCU's input protection diode. Without the pulldown, (14.2-5) /47K = 195µA injected through the pin.

Note that here, Atmel has up to 240VAC mains (rated for 1000V pk) connected through a 1M series resistor to an input. In this case, with 240VAC there would be ±310µA injected through the pin.

The 47K/47K isn't intended as a divider ... when the headlight switch is off (open-circuit), the 47K pulldown resistor ensures the input goes to 0V.