How to Save Power in Your Arduino Projects?
Power consumption is a crucial concern for a device that constantly runs for a long time without being shut off. To overcome this issue, every controller includes a sleep mode, which aids developers in designing electrical devices with the least amount of power usage. Sleep mode saves energy by turning off any modules that aren't in use.
Today, we'll learn about Arduino Sleep Modes and use an Ammeter to demonstrate power consumption. A sleep mode for an Arduino is also known as a power save mode or a standby mode.
Sleep Modes allow the user to stop or turn off the unused modules in the Microcontroller, which significantly reduce the power consumption. Arduino UNO, Arduino Nano and Pro-mini come with ATmega328P, and it has a Brown-out Detector (BOD), which monitors the supply voltage at the time of sleep mode.
The Atmega328P offers six different sleep modes. Depending on the mode, more or less of its functions are sent to sleep. The remaining power consumption is correspondingly different.
You must, of course, be able to wake up the ATmega328P if you put it to sleep. Each mode has its own set of potential "wake-up calls."
Depending on the "sleep depth," the ATmega328P takes a different amount of time to wake up.
The table below shows which functions are still active in the various sleep modes and how to wake up the ATmega328P. The good news is that the table is applicable to all ATmegas.
Active Clock Domains and Wake-up Sources in Different Sleep Modes
- Idle: light sleep. You may need to switch off other components directly via Power Reduction Register (coming later) so that the ATmega328P does not wake up unintentionally.
- ADC Noise Reduction: Even in this mode, many functions remain active. The ADC Noise Reduction Mode, as the name suggests, is also used to reduce noise in analogue-digital conversions. This allows a higher resolution to be achieved.
- Power-down: The most energy-saving deep sleep. Only external interrupts, TWI (Two Wire Interface – > I2C) or the watchdog interrupt can wake up the ATmega328P.
- Power-save: is similar to the power-down mode, but the Timer2 is still awake and could be operated via an external clock.
- Stand-by: the system oscillator is still running here. This mode is typically chosen when quick waking is necessary. Only six cycles are needed. It is important to know that an external quartz oscillator needs time in the millisecond range to provide a stable system clock.
- Extended Standby: Compared to the stand-by mode, the Timer2 is active.
Activating sleep modes
Control sleep modes via the SMCR
The sleep modes are controlled by corresponding entries in the Sleep Mode Control Register SMCR. The Bits SM0… SM2 set the mode, the SE bit (sleep enable) starts sleep mode.
The Sleep Mode Control Register SMCR
Saving energy with the Power Reduction Register
Depending on the sleep mode and the desired wake-up method, you can reduce power consumption even further by manually shutting off some components. This is controlled by the Power Reduction Register PRR:
The Power Reduction Register PRR
Bits that are set switch off the corresponding component:
PRTWI: switches off the Two-Wire Interface (I2C). After waking up, it must be reinitialised.
PRTIM2: turns off Timer2 in synchronous mode.
PRTIM0/PRTIM1: these bits control Timer0 and Timer1.
The Timers0/1/2 continue their work after waking up without any further action.
PRSPI: turns off the SPI interface. SPI must be reinitialised after waking up.
PRUSART0: turns off the serial port, i.e. RX/TX (Universal Synchronous and Asynchronous serial Receiver and Transmitter). The USART interface must be reinitialised after waking up.
PRADC: turns off the A/D converter
What is BOD?
The term "black-out" refers to a full loss of power. This is an expression that I believe everyone is familiar with. On the other hand, a brown-out occurs when the microcontroller's supply voltage falls below a certain threshold. This usually happens when the battery powering your project runs out. When a microcontroller receives insufficient voltage, it behaves in unpredictable ways.
Turning off BOD will save power.
With the pico power variants of the AVR microcontrollers, the brown-out detector can be switched off. You can recognise the pico power models by the “P” in the name, e.g. the ATmega328P. The MCU Control Register MCUCR controls the BOD:
Other Ways to reduce power consumption
Lowering the Clock Frequency
Lowering the clock frequency in continuous awake mode saves power. However, you've noticed that the microcontroller's power consumption is frequency-independent, at least in power-down mode. If you're going to put the microcontroller to sleep and only need to wake it up for a few minutes to perform something, a high clock frequency is preferable.
Lowering the operating voltage
A microcontroller acts like a capacitor or – more exact – like many small capacitors and their charge depends on the operating voltage. This is called parasitic capacities. In addition, there are leakage currents, e.g. from conductor track to another. In power-down mode, you can reduce the power consumption of the ATmega328P from 0.15 mA (programmed via Arduino IDE) to 0.12 mA when voltage is reduced from 5V to 3.3V.
- External Interrupt
- Watchdog Timer