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
Project Source on GitHub Return to the LEAP Catalog

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

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 (IMHO!).

The projects are usually inspired by things found wild on the net, or ideas from the sources such as:

Feel free to borrow liberally, and if you spot any issues do let me know. See the individual projects for credits where due. There are even now a few projects contributed by others - send your own over in a pull request if you would also like to add to this collection.