How to read Arduino power supply voltage

Hi,

My project involves reading the Arduino 5V power supply voltage and displaying it on the serial monitor. Is this possible with just the Arduino alone and some code? Or do I need to purchase another sensor to read the supply’s voltage? The simpler the better. I plan on converting this voltage into a battery life % to monitor the Arduino battery supply’s life.

I have looked online and can only find sketches that involve multimeters or LCD screens. If I can do this with just the Arduino and code that would awesome.

Thanks,
Connor

You can connect 5V pin to A0 pin → read analog value from A0 → convert to voltage. See analog to voltage example

You may need to do some extra works: see DIY Voltmeter Using Arduino on Arduino project hub

AVR chips do have a 1.1V reference. You would have to divide the VCC and measure that fraction to know the actual value of VCC.

IoT_hobbyist, if VCC is 4.8V and you feed that to pin A0 it will return 1023 which will mean 4.8V - 4.8V / 1024. The number that the ADC returns is relative to Vref, not 5V.

The problem you'll have is that the normal ADC reference is the voltage you're trying to measure. So it will always read 1023 because the measured voltage is always going to be equal to the reference voltage.

That's why you'll need to use the fixed 1.1V reference (or an external reference voltage).

Steve