Fork me on GitHub

Project Notes

#333 VoltageSelfMeasurement

Self-measurement of an Arduino’s supply voltage (Vcc).

Build

Notes

One of the issues with analogue measurements on the Arduino is that typically we assume an accurate 5V reference. When that is not actually true, all the readings are off.

In the past I’ve typically measured the actual rail voltage and scripted with a corresponding “fudge factor”. But wouldn’t it be nice if the Arduino could actually do this itself?

SecretVoltmeter is a snippet of code that demonstrates how to get an Arduino (at least Atmega 168 and 328 processors) to measure it’s own supply rail. I found this via Julian Ilett’s video on the subject.

I’ve cleaned up and modified the code a little in the VoltageSelfMeasurement.ino sketch.

How It Works

It relies on two things:

  • the Atmega chip has an internal 1.1V voltage reference (Vbg) that we assume is a known and precise value.
  • it is possible to configure the ADC to measure AVcc with respect to Vbg

So it is then trivial to calculate AVcc in mV.

Note: I’ve also followed the Atmel recommendation to put a 10nF cap on AREF to help stabilise the ADC readings.

Results

Measurements are piped to the serial port. These are pretty accurate according to my other meters:

console

But…

Two things:

  • the ADC is only 10-bit, and
  • how accurate is the internal 1.1V voltage reference anyway?

I put my 1.1V reference to the test, and according to the most accurate device I have on hand, it is actually running at 1.063V. The sketch includes some techniques for compensation.

So … if we’re compensating for innaccuracies in Vbg, aren’t we back to square one and no better off than calibrating Vcc in the first place? Perhaps. I haven’t done measurements to back this up, but one benefit of this approach could be if Vbg is relatively stable over variations in supply voltage.

Measuring the 1.1V reference:

VoltageSelfMeasurement_vbg_test

Construction

Breadboard

Schematic

Build

Credits and References

About LEAP#333 ArduinoADC

This page is a web-friendly rendering of my project notes shared in the LEAP GitHub repository.

Project Source on GitHub Return to the LEAP Catalog
About LEAP

LEAP is my personal collection of electronics projects - usually involving an Arduino or other microprocessor in one way or another. Some are full-blown projects, while many are trivial breadboard experiments, intended to learn and explore something interesting.

Projects are often inspired by things found wild on the net, or ideas from the many great electronics podcasts and YouTube channels. Feel free to borrow liberally, and if you spot any issues do let me know or send a pull-request.

NOTE: For a while I included various scale modelling projects here too, but I've now split them off into a new repository: check out LittleModelArt if you are looking for these projects.

Project Gallery view the projects as an image gallery Notebook reference materials and other notes Follow the Blog follow projects and notes as they are published in your favourite feed reader