PiWeather, part 3: low power design of the first prototype

In this third article about the PiWeather project, I will present a few techniques I used to design the first PiWeather prototype.

The first sensor unit prototype.
The first sensor unit prototype.

When I tried to write down for the first time the "specifications" of my sensor units, I thought that getting to more than one year of battery life would be satisfying. But I really didn't have any idea if I could reach this goal with an Arduino. It turns out you can. And, depending on your project obviously, you can reach very, very long battery lives with a regular Atmega328p used on a regular Arduino UNO.Let's go through a case study here, with a 220 mAh CRC2032 battery. It delivers 3V but let's pretend here it can deliver 5V for the sake of simplicity.

Get rid of the Arduino board.

This decision is a no brainer. There is no way to make something low powered when using the Arduino board. It's actually quite logical when you think about it. It packs many more things than the 328p itself, like an FTDI chip, 3.3 and 5V regulators.

A program running on a regular Arduino UNO board will draw about 55mA, which is a LOT .The CR2032 battery will live 4 hours.

Now remove the 328p from the UNO board, put it on a breadboard with a 16 MHz quart and a, 5V power supply. You get down to 11mA. Now the battery will last 5 times longer, so 20 hours.  Only 20?!

Does your application need to run at 16MHz@5V ?

If you' re working on a low power project, what you want is to only monitor some values, and take simple actions from the data you read. My sensor units only need to read what the sensors tell them, and send these data back to the Pi. There is absolutely no need for performance, therefore no need to run at 16MHz.

A side effect of lowering operating frequency, is that you can also lower the AtMega328 voltage. Indeed, it requires 4.2V to safely operate at 16MHz. At 8MHz, you only need to give it more 2.4V. Which means you could use a single cell battery such as a CR2032, or two AA/AAA batteries.

The difference between running at 16MHz@5V and 8MHz@3V is huge : power consumption drops from 11mA to roughly 3-4mA! Another very big save. Another advantage of running the ATMega at 8MHz is that you can use its internal oscillator, thus eliminating the need for a crystal(or resonator). That's why I chose the 8MHz frequency for this project.

Save power with good software

The software part is as important as the hardware part, when trying to reach lowest consumptions. Indeed, the ATMega328 has different sleep modes that can theoretically reduce its power draw to barely 100nA!

When used in the "default" mode, the Arduino will just endlessly run through the loop function, event if there is nothing to do. This will draw around 4mA running 8MHz@3V. This barely gives us a battery life of 56 hours with a CR2032 cell.

Use interrupts

The ATMega328 can be put into different sleep modes. The "highest" sleep mode basically turns off the Arduino. The only to wake it up is then to trigger an interrupt (that you will have previously registered in your setup() function !). A possible source of interrupt is the change of state on one of the Arduino's pins. Another  way of triggering an interrupt is to use a timer. Timers can generate an interrupt periodically to trigger an action. The maximum sleeping time you can achieve with the Arduino is unfortunately pretty low : 8 seconds. This means that if you want, like me, to sleep for minutes between every action, you'll have to keep track of a counter to reach the desired sleeping time. I found the Low-Power library to be pretty useful. It keeps away the ugly register assigning code and makes sleeping a breeze 🙂

The results

My code is pretty simple. Sleep 800 seconds (around 13 minutes), wake up,acquire and send the sensors data (a few seconds), and go back to sleep for 800 seconds. The average power draw while sleeping is 6 µA, due to the watchdog timer of the Arduino. The few milliamps drawn at wake up can be ignored since they represent less than 0.5% off the total time, which gives us approximately 225/0.006=1562.5 days of battery life. This is much better. If you don't need the timers and can get external interrupts to wake up your device, you can achieve a lifetime that will essentially be your battery life time!

Sleeping with the watchdog timer on draws 6 µA, more than 9000 times less than using the Arduino Un board!
Sleeping with the watchdog timer on draws 6 µA, more than 9000 times less than using the Arduino Un board!

First prototype

The first sensor unit prototype is very simple. A DS18B20 temperature sensor, an ATMega328p and a nF24L01+ for RF communication. The power is given by a CR2032 battery.
First prototype

One of the flaws of this design is the minimum voltage required by the DS18B20. It theoretically is 3V. The CR2032 voltage is 3V when new, but slowly goes down until around 2.8V (then it's pretty much flat). It turns out the DS18B20 behave completely normally, even at 2.8V, but powering a sensor outside its recommended operating voltage range is probably never a good thing.The second prototype, which I'll present in a future article, fixed this 🙂

That's it for this short introduction to low power design for Arduino. If you want to know everything about Arduino and low-power, read Nick Gammon's great posts here 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *