I am finishing up an embedded project for my vehicle and the last step is to make it automatically power off with the car. The way I detect whether the vehicle is on or not is via a battery pin, which maps the car’s battery voltage as a value between 0-3.3 volts, multiplied by 7.2 to give the real voltage. To preserve power, I need to sleep the microcontroller until a signal is written to the wake up pin. So, I need to write gpio high (3.3v) to the pin when the battery is below 13 volts (around 1.8v on the battery pin), and gpio low when it isn’t. Theoretically the high/low can be flipped but that’s not important.

I have done a fair amount of research and have gotten swamped with solutions. At first I thought I could get away with just a transistor but apparently the right way is through a voltage comparator built from op-amps... but that almost seems overkill? I would prefer to input the minimum voltage into the comparator and for it to be low power. I am also not quite adapt a parsing their spec sheets so I’m really at a loss as to pick the exact part I need. I would really appreciate some guidance :)

  • 1
    \$\begingroup\$ XY problem? There are so many easy ways to reliably detect when vehicle is running. Starting with tapping any car circuit powered by ingintion switch. \$\endgroup\$
    – Maple
    Commented Sep 2, 2018 at 7:37
  • 1
    \$\begingroup\$ Is there a reason why you decided to use an analog way to detect whether the car is on, by measuring the battery voltage? It seems to make more sense to me to use a digital way of measuring whether the car is on, like @Maple suggested. You'd only need a voltage divider (e.g. two resistors), and some over voltage/spike protection (e.g. clamp diodes and/or transient protecton diodes). \$\endgroup\$
    – MartinF
    Commented Sep 2, 2018 at 11:01
  • \$\begingroup\$ @Maple the reason I opted for the battery pin is because it allows my device to be standalone, as it is built around a Carloop which is just an obd adapter with a microcontroller plugged into it. Tapping into the ignition circuit would indeed be more straightforward but it would also sacrifice portability which I do not want to do. \$\endgroup\$
    – Dan Appel
    Commented Sep 2, 2018 at 19:14
  • \$\begingroup\$ @MartinF there are digital ways of detecting whether the vehicle is on with the OBD connector (ie through the CAN bus) but they all require the microcontroller to be awake, where as I want the car to wake up the microcontroller when it turns on. If there is a better way it would naturally be better but as far as I understand I have to stick with this. \$\endgroup\$
    – Dan Appel
    Commented Sep 2, 2018 at 19:16

1 Answer 1


A comparator is indeed a great solution for this, given that is pretty much a comparator's only job. The transistor solution will be much more difficult to tune and make stable. By the time you've added enough to the transistor circuit to get it to behave well, you'll have effectively designed a comparator.

To keep things really simple, consider a 5-pin, push-pull output, comparator IC like the LMC7211. Your requirements will be met by a huge range of comparators, so I'll just use the LMC7211 to explain.

Simply connect your scaled battery voltage to the inverting - input pin, your threshold voltage to the non-inverting + input pin, and your 3.3V supply to the supply pins. Finally, because the battery voltage changes very slowly and will likely increase at the moment you turn off the car, you'll probably want to add some hysteresis. Hysteresis means the turn on threshold is different from the turn off threshold so the circuit doesn't bounce repeatedly between on and off. To do so, just add a large value resistor from the output pin to the non-inverting input pin. The output pin will then give you the signal you require.

Something like this:


simulate this circuit – Schematic created using CircuitLab

With the resistor values I've used in the schematic, the output goes to 3.3V when the input falls below 1.76V and the output goes to 0V when the input rises above 1.94V. Adjust to suit your preferences.

  • \$\begingroup\$ Thank you so much! This looks like exactly what I was looking for, much appreciated. \$\endgroup\$
    – Dan Appel
    Commented Sep 2, 2018 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.