Trent "ripred" Wyatt Offers ATmega-Based Arduino Users a Hardware-Free Voltage-Monitoring Library

Implementing a Microchip Application Note, this clever library makes use of the ADC and internal voltage reference to measure power input.

Gareth Halfacree
5 months agoHW101

Developer Trent "ripred" Wyatt has released an Arduino library which gives Microchip ATmega-family microcontrollers the ability to measure the voltage coming in on their Vcc pin — without requiring any additional hardware whatsoever.

"The CPUVolt library is used to measure the current voltage level on the most popular ATmega series microcontrollers used on Arduino's without using any external components whatsoever," Wyatt writes of the library. "You read that right: you can read the current voltage level present on the Vcc pin of the processor without needing any additional parts or connections."

The library implements Microchip's Application Note AN2447, which uses the microcontroller's internal reference voltage (Vbg) as the input to an analog to digital converter (ADC) with the Vcc pin as the reference. "This solution helps the users setting up applications with low power consumption, low MCU [Microcontroller Unit] pin count, and/or few BOM [Bill of Materials] parts," Microchip says. "In general voltage/battery monitoring, this solution is quite attractive."

In its latest release, Wyatt's CPUVolt library offers the ability to report an absolute voltage or, for battery-based projects, a percentage based on user-configurable maximum and minimum voltage levels. "This is really useful for battery-based projects," Wyatt says. "You can now specify the lower voltage level you would like to use to indicate when the system needs charging and when it is fully charged."

This isn't Wyatt's first library designed to improve the lives of Arduino programmers: back in June he released the Smooth library, which offered a way to tame "noisy" inputs without using memory-hungry arrays. "You create the object and tell it what the running sample window size is," Wyatt explained at the time. "This object takes up eight bytes no matter the window size. And there's no looping over past values. And no arrays."

The CPUVolt library is now available on GitHub, under the permissive MIT license, and in the Arduino IDE Library Manager; more information on its new percentage feature is available in Wyatt's Reddit post.

Gareth Halfacree
Freelance journalist, technical author, hacker, tinkerer, erstwhile sysadmin. For hire: freelance@halfacree.co.uk.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles