Skip to content

Circuit-Digest/Arduino-Sleep-Modes-and-How-to-use-them-to-Save-the-Power

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Arduino Sleep Modes and Power Optimization

Arduino Sleep Modes

Project Overview

This project demonstrates how to use Arduino sleep modes to significantly reduce power consumption in battery-powered or continuously running devices. By implementing sleep modes, you can nearly double the runtime of your Arduino projects. The project showcases a weather station using DHT11 sensor that periodically wakes up to read temperature and humidity data, then goes back to sleep to conserve power.

Features

  • Multiple Sleep Modes: Demonstrates Idle sleep mode with ATmega328P
  • Periodic Wake-Up: Arduino wakes every 8 seconds to read sensor data
  • Power Consumption Monitoring: Uses USB ammeter to measure actual power savings
  • Temperature & Humidity Monitoring: Integrates DHT11 sensor for weather data
  • LED Indicator: Built-in LED shows active/sleep status
  • Significant Power Savings: Reduces active time to only 24 seconds per minute

Arduino Sleep Modes Explained

The ATmega328P (used in Arduino UNO, Nano, and Pro Mini) supports six sleep modes:

  1. Idle Mode - Stops CPU, keeps peripherals running
  2. ADC Noise Reduction Mode - Optimized for analog readings
  3. Power-Down Mode - Stops all clocks except async modules
  4. Power-Save Mode - Like Power-Down but keeps Timer/Counter running
  5. Standby Mode - Like Power-Down but keeps external oscillator running
  6. Extended Standby Mode - Like Power-Save but keeps external oscillator running

This project uses Idle Mode which stops the CPU while allowing peripherals to operate, achieving substantial power savings with easy wake-up capabilities.

Components Required

Component Quantity Description
Arduino UNO 1 Main microcontroller board
DHT11 Sensor 1 Temperature and humidity sensor
USB Ammeter 1 For measuring power consumption
Breadboard 1 For prototyping
Connecting Wires As needed Jumper wires

Hardware Connections

DHT11 to Arduino

  • VCC → Arduino 5V
  • GND → Arduino GND
  • DATA → Arduino Digital Pin 2

Power Monitoring Setup

  • Arduino plugged into USB Ammeter
  • USB Ammeter plugged into laptop/power source USB port

Software Requirements

Required Libraries

  1. DHT Library - For DHT11 sensor interface

    Download from Arduino Library Manager or GitHub
    
  2. LowPower Library - For sleep mode control

    https://github.com/rocketscream/Low-Power
    

Installation

  1. Download and install both libraries in Arduino IDE
  2. Go to SketchInclude LibraryAdd .ZIP Library
  3. Select the downloaded library files

Code Examples

Arduino Weather Station WITH Sleep Mode

#include <dht.h>
#include <LowPower.h>

#define dataPin 2
dht DHT;

void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
}

void loop() {
  Serial.println("Get Data From DHT11");
  delay(1000);
  
  // Turn on LED and read sensor
  digitalWrite(LED_BUILTIN, HIGH);
  int readData = DHT.read11(dataPin);
  float t = DHT.temperature;
  float h = DHT.humidity;
  
  Serial.print("Temperature = ");
  Serial.print(t);
  Serial.print(" C | ");
  Serial.print("Humidity = ");
  Serial.print(h);
  Serial.println(" % ");
  delay(2000);
  
  // Enter sleep mode
  Serial.println("Arduino:- I am going for a Nap");
  delay(200);
  digitalWrite(LED_BUILTIN, LOW);
  
  // Sleep for 8 seconds
  LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, 
                TIMER0_OFF, SPI_OFF, USART0_OFF, TWI_OFF);
  
  Serial.println("Arduino:- Hey I just Woke up");
  Serial.println("");
  delay(2000);
}

Arduino Weather Station WITHOUT Sleep Mode (Comparison)

#include <dht.h>

#define dataPin 2
dht DHT;

void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  
  int readData = DHT.read11(dataPin);
  float t = DHT.temperature;
  float h = DHT.humidity;
  
  Serial.print("Temperature = ");
  Serial.print(t);
  Serial.print(" C | ");
  Serial.print("Humidity = ");
  Serial.print(h);
  Serial.println(" % ");
  
  delay(2000);
}

How It Works

Sleep Mode Operation

  1. Active Phase (24 seconds/minute):

    • Wake up from sleep
    • Turn ON built-in LED
    • Read temperature and humidity from DHT11
    • Print data to Serial Monitor
    • Turn OFF LED
  2. Sleep Phase (36 seconds/minute):

    • Enter Idle sleep mode for 8 seconds
    • CPU stops, peripherals turned off
    • Minimal power consumption
    • Automatic wake-up after timeout

Power Optimization Strategy

The code enables Idle sleep mode using:

LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, 
              TIMER0_OFF, SPI_OFF, USART0_OFF, TWI_OFF);

This command:

  • Sets sleep duration to 8 seconds
  • Turns OFF ADC (Analog to Digital Converter)
  • Disables all timers (TIMER0, TIMER1, TIMER2)
  • Disables SPI communication
  • Disables USART (Serial)
  • Disables TWI (I2C/Two-Wire Interface)

USB Ammeter Specifications

The USB ammeter is used to measure real-time power consumption:

  • Voltage Range: 3.5V to 7V
  • Current Rating: Up to 3A
  • Display: 4-digit seven-segment display
  • Update Rate: Values update every 3 seconds
  • Measurement: Voltage and current consumption

Power Consumption Results

By implementing sleep modes, the Arduino:

  • Active Time: Only 24 seconds per minute
  • Sleep Time: 36 seconds per minute
  • Power Savings: Approximately 50% reduction
  • Battery Life: Nearly doubles device runtime

Testing Instructions

  1. Upload Code: Load the sleep mode code to Arduino via Arduino IDE
  2. Connect USB Ammeter: Plug Arduino into USB ammeter
  3. Connect Power: Plug USB ammeter into laptop/power source
  4. Monitor Serial: Open Serial Monitor at 9600 baud rate
  5. Observe LED: Watch built-in LED for active/sleep indication
  6. Read Ammeter: Note current consumption during active vs sleep phases

Wake-Up Methods

Arduino can be woken from sleep using:

  • Timer Overflow - Automatic wake after set duration
  • External Interrupts - Pin change interrupts
  • Internal Interrupts - Watchdog timer
  • Hardware Reset - Reset button
  • Brown-Out Detection - Voltage monitoring

Example: Interrupt-Based Wake-Up

void loop() {
  // Attach interrupt to wake up
  attachInterrupt(0, wakeUp, LOW);
  
  // Sleep indefinitely until interrupt
  LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
  
  // Detach interrupt after wake
  detachInterrupt(0);
  
  // Resume operations
}

Sleep Mode Comparison

Sleep Mode CPU Flash Timers ADC USART Wake-Up Time
Idle OFF OFF ON ON ON Fast
ADC Noise OFF OFF ON ON ON Fast
Power-Down OFF OFF OFF OFF OFF 6 cycles
Power-Save OFF OFF Timer2* OFF OFF 6 cycles
Standby OFF OFF OFF OFF OFF 6 cycles
Ext. Standby OFF OFF Timer2* OFF OFF 6 cycles

*Timer2 continues running in Power-Save and Extended Standby modes

Applications

  • Battery-Powered Weather Stations
  • Remote Sensor Nodes
  • IoT Devices with Periodic Data Transmission
  • Solar-Powered Arduino Projects
  • Long-Term Environmental Monitoring
  • Wildlife Tracking Devices

Advantages

✓ Significant power savings (up to 50% or more)
✓ Extended battery life for portable projects
✓ Reduced heat generation
✓ Suitable for solar/battery operation
✓ Easy implementation with LowPower library
✓ Flexible wake-up options

Tips for Maximum Power Savings

  1. Use Power-Down Mode when possible (lowest consumption)
  2. Disable BOD (Brown-Out Detection) during sleep
  3. Turn OFF unused LEDs including power LED
  4. Use efficient voltage regulators (LDO regulators)
  5. Optimize sleep/wake cycles based on application needs
  6. Remove USB-Serial chip for ultra-low power (Pro Mini)
  7. Use external interrupts for event-driven wake-up

Troubleshooting

Issue Solution
Serial Monitor not working after sleep USART is disabled in sleep - data lost during sleep
Timer functions not working Timers disabled in Idle mode - use different sleep mode
Can't wake from Power-Down Ensure external interrupt or watchdog is configured
High power consumption Check for active peripherals, disable unused modules

Learn More

License

This project is open-source and available for educational and commercial use.

Credits

Project Tutorial: CircuitDigest


Note: For detailed circuit diagrams, component specifications, and video demonstration, visit the full tutorial.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages