0
0
AutocadHow-ToBeginner · 4 min read

How to Reduce Power Consumption in Arduino: Simple Tips

To reduce power consumption in Arduino, use sleep modes to pause the CPU when idle, disable unused peripherals like ADC and timers, and lower the clock speed if possible. Also, power off or disconnect unnecessary components to save energy.
📐

Syntax

Here is the basic syntax to put an Arduino into sleep mode using the avr/sleep.h library:

  • set_sleep_mode(mode); - Selects the sleep mode.
  • sleep_enable(); - Enables sleep mode.
  • sleep_cpu(); - Puts the CPU to sleep.
  • sleep_disable(); - Disables sleep mode after waking up.

You can also disable peripherals by clearing bits in control registers.

arduino
#include <avr/sleep.h>

void setup() {
  // Setup code here
}

void loop() {
  set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Select power down mode
  sleep_enable();                      // Enable sleep mode
  sleep_cpu();                         // Go to sleep
  sleep_disable();                     // Wake up here
  // Continue running
}
💻

Example

This example demonstrates how to put the Arduino into the deepest sleep mode to save power and wake up using an external interrupt (like a button press).

arduino
#include <avr/sleep.h>
#include <avr/interrupt.h>

const int wakeUpPin = 2; // External interrupt pin

void wakeUp() {
  // This function is called when interrupt occurs
}

void setup() {
  pinMode(wakeUpPin, INPUT_PULLUP); // Use internal pull-up resistor
  attachInterrupt(digitalPinToInterrupt(wakeUpPin), wakeUp, LOW); // Wake on LOW signal
  Serial.begin(9600);
  Serial.println("Setup complete, going to sleep...");
}

void loop() {
  delay(1000); // Wait a bit before sleeping
  Serial.println("Going to sleep now.");
  delay(100); // Allow serial to send

  set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Deepest sleep mode
  sleep_enable();
  sleep_cpu(); // Go to sleep here

  // CPU wakes up here after interrupt
  sleep_disable();
  Serial.println("Woke up!");
  delay(2000); // Wait before next sleep
}
Output
Setup complete, going to sleep... Going to sleep now. Woke up!
⚠️

Common Pitfalls

Common mistakes when reducing power consumption include:

  • Not disabling unused peripherals like ADC, timers, or the analog comparator, which keep drawing power.
  • Forgetting to set unused pins as INPUT_PULLUP to avoid floating inputs that waste power.
  • Using delay() instead of sleep modes, which keeps the CPU running and wastes energy.
  • Not properly configuring interrupts to wake the Arduino from sleep.
arduino
// Wrong way: Using delay instead of sleep
void loop() {
  delay(10000); // CPU still running, wastes power
}

// Right way: Using sleep mode
#include <avr/sleep.h>
void loop() {
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  sleep_cpu();
  sleep_disable();
}
📊

Quick Reference

Summary tips to reduce Arduino power consumption:

  • Use sleep modes like SLEEP_MODE_PWR_DOWN for lowest power.
  • Disable unused modules: ADC (ADCSRA &= ~(1<), analog comparator, timers.
  • Set unused pins to INPUT_PULLUP to prevent floating.
  • Lower clock speed if possible.
  • Power off or disconnect unused sensors and LEDs.

Key Takeaways

Use sleep modes to pause the CPU and save power when idle.
Disable unused peripherals like ADC and timers to reduce current draw.
Set unused pins to INPUT_PULLUP to avoid floating inputs wasting power.
Use interrupts to wake the Arduino from sleep instead of delay loops.
Lower clock speed and disconnect unused components for extra savings.