Arduino – Calculate VCC

A little known feature of many AVR chips is the ability to measure the internal analog voltage reference. This trick can be used in all sorts of ways such as:

  • Monitoring battery voltage to your Arduino
  • Checking to see if A/C power is running
  • Improve accuracy of analogRead() in many situations

The way to perform these feats is use the internal reference to actually measure Vcc. In the code following, we will actually measure the internal voltage reference, and then use this value to calculate our actually Vcc. Here is the code:

There are some limitations in accuracy due to tolerances on the internal voltage reference. You can however, calibrate the scale factor for greater accuracy. This code runs on all Arduino variants as well as the ATtinyx4 series chips.

Bron: https://www.instructables.com/Secret-Arduino-Voltmeter/


Other example

Another option which does not require a voltage divider is to use Vcc as a reference to measure both the analog input and the internal 1.1 V “bandgap“ reference. Measuring the 1.1 V against Vcc is an indirect way to measure Vcc. This is not supported by the Arduino core library, but you can do it by programming directly the control registers of the ADC:

Beware that the very first reading after boot may be bogus.

Source: https://newbedev.com/does-adc-conversion-to-a-voltage-rely-on-the-actual-value-of-the-5-v-pin