A µC measuring the voltage of its powersource

I have a 6V lead battery as a power source. I have an LM2596 regulator, which takes the voltage down to 5V, which powers the microcontroller as well as some servos. Is it possible to measure the voltage of the lead battery with the µC? I would have a voltage divider, which takes the 6V down to a measureable 4.6V. The circuit would look like this:

Or will there be some interference or whatever between the 6V source and the regulated 5V, which would mess with the ADC of the microcontroller? I wish to be able to detect when the voltage of the battery has dropped from 6.4 V to some 5.5 V. I don't need moonlanding accuracy.

The problem is that as the 6V drops it might affect the 5V that is the reference for the measurement.

Instead use the internal reference. On an UNO thats 1.1V. Target your divider to that range and use the internal reference and you'll get more stable reading from the battery.

The LM2596 could have a dropout voltage of 1.3volt every time the servos start moving, which could affect the 5volt supply of the Arduino. I don't see why you need this DC/DC converter at all. Most servos are fine with 6volt, or you could use a 1N4004 diode in each servo supply line. The Arduino should be fine with 6volt on V-in.

Use the 1.1volt Aref for voltage measurements, as @Delta_G explained.
Leo..

Consider using a SEPIC (Single-Ended Primary-Inductor Converter). It operates similarly to a buck/boost converter, switching modes as needed. A SEPIC converter can produce an output voltage that is greater than, less than, or equal to its input voltage, covering the full battery voltage cycle.

Your divider circuit should work fine. Just ensure it cycles with the power; otherwise, it could drain your battery.

Vin wants 7.5 or more IIRC

2 Likes

Connect 5V to the 5V pin, NOT VIN.

Ideally, yes. But the 1117 voltage regulator doesn't drop much more than 1volt at the 50mA current of an Uno R3. 6.7volt is the absolute minimum for the DC socket though.
Leo..

Small resistance will drain your battery.
Increase the resistors.
220k vs 1M or something like that.

Hello Johan_Ha

Take a search eingine of your choice and ask the WWW for 'Secret Arduino Voltmeter'.

hth