Saving power helps your Arduino run longer on batteries. It also keeps your project cool and efficient.
Reducing power consumption tips in Arduino
// Example: Using sleep mode to save power
#include <avr/sleep.h>
void setup() {
// Prepare to sleep
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
}
void loop() {
// Go to sleep
sleep_cpu();
// Arduino sleeps here until an interrupt wakes it
}Sleep modes help Arduino use less power by turning off parts it doesn't need.
You can choose different sleep modes depending on how much power you want to save.
// Turn off unused modules power_adc_disable(); power_spi_disable(); power_timer0_disable();
// Reduce clock speed to save power // Not all boards support this // Example for AVR boards CLKPR = (1 << CLKPCE); CLKPR = (1 << CLKPS1) | (1 << CLKPS0); // Divide clock by 8
// Use sleep mode with interrupt to wake up attachInterrupt(digitalPinToInterrupt(2), wakeUp, LOW); set_sleep_mode(SLEEP_MODE_PWR_DOWN); sleep_enable(); sleep_cpu();
This program puts the Arduino to sleep to save power. It wakes up when you press a button connected to pin 2. It also turns off some parts to save more power.
#include <avr/sleep.h> #include <avr/power.h> void wakeUp() { // This function is called when Arduino wakes up } void setup() { pinMode(2, INPUT_PULLUP); // Button on pin 2 attachInterrupt(digitalPinToInterrupt(2), wakeUp, LOW); // Turn off ADC and SPI to save power power_adc_disable(); power_spi_disable(); // Set sleep mode to power down set_sleep_mode(SLEEP_MODE_PWR_DOWN); sleep_enable(); Serial.begin(9600); Serial.println("Going to sleep..."); } void loop() { sleep_cpu(); // Arduino sleeps here sleep_disable(); Serial.println("Woke up!"); delay(1000); // Wait a bit before sleeping again sleep_enable(); }
Always test your sleep and wake-up code carefully to avoid your Arduino getting stuck asleep.
Turning off unused modules can save a lot of power but make sure you turn them back on if needed.
Using interrupts to wake up is better than constantly checking inputs in a loop.
Use sleep modes to reduce power when Arduino is idle.
Turn off unused hardware modules to save energy.
Use interrupts to wake Arduino from sleep efficiently.
Practice
Solution
Step 1: Understand power saving basics
Sleep modes reduce power by pausing the CPU when it is not needed.Step 2: Evaluate other options
Increasing clock speed or keeping hardware enabled increases power use; running without power is impossible.Final Answer:
Using sleep modes to pause the CPU when idle -> Option CQuick Check:
Sleep modes = power saving [OK]
- Thinking higher clock speed saves power
- Believing all hardware should stay enabled
- Ignoring the need for a power source
Solution
Step 1: Identify sleep mode function
The functionsleep_mode()is used to put the microcontroller into sleep mode.Step 2: Check other functions
digitalWrite()controls pins,delay()pauses code,pinMode()sets pin mode; none put it into sleep.Final Answer:
sleep_mode() -> Option DQuick Check:
sleep_mode() = enter sleep [OK]
- Confusing delay() with sleep functions
- Using digitalWrite() to control power
- Not knowing pinMode() sets pin direction
void setup() {
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
// No sleep mode used
}
void loop() {
// Empty loop
}Solution
Step 1: Analyze pin state
Pin 13 is set to LOW, so it does not consume extra power from that pin.Step 2: Check for sleep mode
No sleep mode is used, so the CPU runs continuously, consuming normal power.Final Answer:
Power consumption remains high because no sleep mode is used -> Option AQuick Check:
No sleep mode = normal power use [OK]
- Assuming LOW pin means zero power
- Thinking empty loop stops CPU
- Believing pin 13 blinks automatically
void setup() {
sleep_enable();
sleep_mode();
sleep_disable();
}
void loop() {
// do nothing
}Solution
Step 1: Review sleep sequence
sleep_enable() and sleep_mode() are correctly called to enter sleep.Step 2: Check wake-up mechanism
Without an interrupt or event to wake the CPU, it may stay asleep indefinitely or behave unexpectedly.Final Answer:
The code does not put the CPU to sleep properly because it lacks an interrupt to wake up -> Option AQuick Check:
Sleep needs wake interrupt [OK]
- Thinking sleep_disable() must come before sleep_mode()
- Ignoring the need for wake interrupts
- Assuming pinMode() affects sleep functions
Solution
Step 1: Identify hardware disabling functions
Functions likepower_adc_disable()turn off specific hardware modules to save power.Step 2: Evaluate other options
Increasing clock speed uses more power; keeping all modules enabled wastes energy; digitalWrite() controls pins, not modules.Final Answer:
Use power_adc_disable() to turn off the analog-to-digital converter when not needed -> Option BQuick Check:
Disable unused hardware = power_adc_disable() [OK]
- Thinking digitalWrite() disables hardware modules
- Believing higher clock speed saves power
- Not disabling unused modules wastes battery
Ready to prove it?
Pass the test and this pattern moves unknown
