Sleep and low power
On this page
A phone with the screen on is empty by the evening. The same phone with the screen off lasts for days, because almost everything inside it is switched off between uses. A battery sensor is designed in the same way. Sleep is a mode in which a microcontroller switches off nearly all of itself, and a low power device is one that sleeps almost all the time.
See it
A sensor node wakes every 5 minutes. It is awake for 2 s and draws 120 mA while it measures and sends. Then it sleeps for 298 s and draws 0.01 mA. In one cycle, which part uses more charge from the battery?
The node draws 120 mA while awake and wakes every 5 minutes. The upper bar is time and the lower bar is charge. With a good sleep current, a thin slice of time takes nearly all the charge. With a poor one, the sleep takes it.
The idea
A battery holds a fixed amount of charge, written in milliampere hours (mAh). A device that draws 1 mA empties a 2,500 mAh battery in 2,500 hours. So the life of a battery depends on one number: the average current.
A node that measures every few minutes has nothing to do between measurements. In deep sleep the processor, the radio and most of the memory are off, and only a small timer runs. One common module draws about 0.01 mA in deep sleep, against 100 mA or more with its radio on.
I is a current and t is a time within one cycle. Battery life in hours = capacity in mAh ÷ Iaverage in mA.
Deep sleep has a price. When the timer wakes the chip, the program starts again from the beginning, and only values placed in a small kept memory survive. The lesson on power management and deep sleep shows how to keep them.
The formula also assumes a perfect battery. Real cells lose charge by themselves and give less in the cold, so a calculated life of several years is too optimistic.
One worked number
A node wakes every 5 minutes (300 s). It is awake for 2 s at 120 mA and asleep for 298 s at 0.01 mA. How long do two AA cells of 2,500 mAh last?
Show the worked solution, 3 steps
- Find the charge used in each part
Awake: 120 mA × 2 s = 240 mA s. Asleep: 0.01 mA × 298 s = 2.98 mA s.
- Spread it over the whole cycle
Average = (240 + 2.98) ÷ 300 = 0.810 mA.
- Divide the capacity by the average
2,500 mAh ÷ 0.810 mA = 3,086 h. Divide by 24: about 129 days. The figure opens on this case.
The mistake to avoid
Check yourself
The node of the worked number is changed to connect faster, so it is awake for 1 s, not 2 s. Nothing else changes. What happens to the battery life?
A node built on a development board should last 129 days by calculation. Its cells are empty after 18 days. The program is correct and the cells were new. What is the most likely cause?
A node counts the readings it has sent in an ordinary variable. After every deep sleep the count is back at its first value. Why?
Where you meet it
- A tank level sensor on a remote siteIt wakes every 15 minutes, measures, sends and sleeps. On paper two AA cells then last about a year.
- A temperature tag in a cold roomIt sleeps until a timer or the door switch wakes it, so nobody runs a cable to it.
- A water meter with a radioIts sealed battery must last for many years, so it is awake for a fraction of a second each time.
- Battery life = capacity ÷ average current.
- The awake time is short but can use nearly all the charge. Make it shorter.
- The sleep current of the whole board counts, not that of the chip alone.
- After deep sleep the program starts again from the beginning.
Discussion
No comments yet. Questions, results from your own build, a better way to explain it: all welcome.
My notes on this page
Kept on this device only. Nothing is sent anywhere.
Tip: select words in the lesson, or tap a figure or an equation, to put a note right there.
Notes on earlier wording
The lesson has changed and these words are no longer in it. Your notes are kept, with the words you chose.