Measuring 12V car battery on Arduino Mega2560

I'm working on a project that is able to measure 12V (car battery) on a 5V Arduino without damaging the Arduino. I know I must start with a voltage divider to regulate the output voltage, I also want to create a 3 LED pin to show how much battery is left in the battery I measure, any ideas on code or schematic? I'll appreciate anything, have any questions or more details make sure to leave a comment and ill get back with you, again I would really appreciate anything.

You could use a internal voltage as reference, that is often better than the 5V as reference.
https://www.arduino.cc/reference/en/language/functions/analog-io/analogreference/.

With two resistors it is safe to measure 12V, as long as no other ground currents can go through the Arduino board via the GND pins.
Suppose that you use 2.56V as internal reference (you have to measure the actual voltage), and R1 = 56k and R2 = 10k.
Then a voltage can be measured up to 16.9V and voltage of 92V will not damage the Arduino. That is the theory, in real life a voltage peak can probably be a lot more than 100V.
The calculation of the 92V was done by allowing to raise the analog input to 5.5V and 1mA is pushed into the pin, which flows via the internal ESD diodes to VCC.

In what environment does this 12 volt live?

Hello,
well beside from the hardware design you can start with the design of the voltmeter. The world wide net provides a lot of solutions to be used as a kickstarter for your project.

As a basic start, I use a 47K / 10K divider... a ~5:1 drop ratio with minimal current loss.

I allowed a ~25V peak, to accomodate the vagaries of utility 12V supplies without losing too much resolution in the measurement.
It’s worked well for a number of years.

If it’s on a really dirty supply, you may want add some noise/spike suppression.

I would use the Vin for power and let the regulator do its thing. The Arduino has its own internal voltage references - but they are not very precise. A built-in reference, equal to 1.1 volts on the ATmega168 or ATmega328; also on the ESP32; and 2.56 volts on the ATmega8 and 32U4 chip boards. ... these are just a "typical" value. Keep the current as constant as much as possible on the on board regulators, they will be stable. They are designed with extremely tight load and line regulation. The output voltage output from min to max is 0.03 volts from regulator to regulator. I've read a few other forum posts which raised some questions: The accuracy of the ADC in the Arduino is around +/- 2 LSB, which means 9.8mV with a 5V reference. This should be more or less constant and be corrected with an offset in the arduino code. Temperature being reasonably stable your biggest source of error will be your connections and the resistors. To save time use whatever resistors you have then adjust for the error in your code. This is much easier the purchasing 0.1% resistors.

A lead-acid battery will show approximatly 12 volts with NO charge left to supply current. So, to determine the charge based on a voltage measurement, you MUST be able to put a load on the battery. Several amps would be appropriate, and measure the voltage at theat time.
Paul

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.