Just a simple voltage monitor

Greetings
Many posts about voltage drops, measurements etc.

All I want to do is show the voltage of an external 12 volt battery. This battery is NOT powering anything Arduino.

I think I understand the voltage divider but want to get ‘best’ ideas.
The voltage reading will be sent via ESP8266 wifi

Thanks
Doug

Do you have a multimeter? ...Just to make sure you don't connect 12V to your Arduino and kill it. :wink:

A voltage divider is the solution. For example, a 3:1 voltage regulator made with a 10K resistor and a 20K resistor will knock 12V down to 4V. You don't have to use those exact values ,but that's the idea. Values around 10K are good because the current is relatively low and noise should be low or manageable. (Higher resistance/impedance is more prone to noise pickup.)

Then you just have to figure-out the ratio between the ADC and voltage... With the default 5V reference 5V reads 1023, so 4V would read 818. But of course, that means 818 is actually 12V into the voltage divider. The accuracy will depend on the accuracy of the 5V reference and the resistor accuracy (tolerance) so you might want to calibrate with a known good voltmeter.

Of course, test that with the serial monitor like the Analog Read Serial and Analog Read Voltage examples before you play-around with Wi-Fi.

That's the easy part... Most of your work will go into the Wi-Fi stuff.

Also, if it's a lead acid battery, plan to measure as high as 14 volts, a fully charged battery is more like 13.8V than 12V.

seymourmtn:
The voltage reading will be sent via ESP8266 wifi

Measured and sent, or measured by something else and sent by the ESP8266.

If an Uno/Nano/etc. is used, then it’s better to use it’s internal ~1.1volt reference voltage (code).
So the measurements are not depending on a possible fluctuating 5volt supply.

The voltage divider has to drop battery voltage to ~1volt if 1.1volt Aref is used.
Voltage divider resistor ratio depends.
Are you measuring a stationary battery (<= 12.8volt) or one under normal charge (<=13.8volt) or one in a car (<= 14.5volt) or one on a fast charger (<= 16.5volt).
For the first scenario, 10k:120k can be used. The last one could be 10k:150k.
Or any other values with the same ratio.

Tell us which ESP you have if you measure directly with the ESP (only has a ~1volt A/D).
Some ESP boards already have a voltage divider.
Leo…

I agree that a voltage divider is your best solution. I thought I'd share a few of the resources I recently spent an exorbitant some time reading.

Nick Gammon's page is always a great resource. Scroll down to the Measuring High Voltages section at the following link:

https://www.gammon.com.au/adc

Below, he also provides a really in depth discussion on how to interpret the results of the ADC and touches on the different "1023 vs 1024" schools of thought. He suggests the following formula to calculate voltage:

float voltage = ((float) rawADC + 0.5 ) / 1024.0 * Vref;

JeeLabs also has some great articles on how to read voltages without the draining your batteries. I'm not sure if this as much of an issue for your 12V battery, but there's some good circuits provided. He also follows up with several additional posts that are all good reads!

https://jeelabs.org/2013/05/16/measuring-the-battery-without-draining-it/

Cheers,
A

adam_g:
Below, he also provides a really in depth discussion on how to interpret the results of the ADC and touches on the different "1023 vs 1024" schools of thought. He suggests the following formula to calculate voltage:

float voltage = ((float) rawADC + 0.5 ) / 1024.0 * Vref;

Not relevant if you compare that (0.1%) to the 1% tolerance of the resistors of the divider and the 5% tolerance of the reference voltage.
You always need to calibrate readout with a DMM.
Leo..