OC
OceanRemote
Low-code IoT platform
โ† Back to Course

ESP32 Sleep Modes Overview

ESP32 Sleep Modes Overview

๐Ÿ’ค ESP32 Sleep Modes - Maximizing Battery Life

๐Ÿ”‹ What You'll Learn in This Lesson:

  • ๐Ÿ’ค Choose the right sleep mode for your application
  • ๐Ÿ“Š Reduce power from 150mA to 2.5ฮผA (60,000x reduction!)
  • ๐Ÿ”„ Preserve data using RTC memory across deep sleep
  • โฐ Wake ESP32 on timer, button press, or sensor trigger

ESP32 has several sleep modes that dramatically reduce power consumption. A 2600mAh battery lasts only 17 hours in active mode but can last over 10 years in deep sleep! The key is sleeping between readings.

๐Ÿ“Š Sleep Mode Comparison

ModeCurrentWake SourcesRAM RetentionBest For
Active80-240mA
๐Ÿ’ก Key Insight:

The 60,000x power reduction from active mode to deep sleep means a battery that lasts 1 day in active mode would last over 100 years in deep sleep! But your sensor still needs to wake up to take readings.

๐Ÿ“Š Deep Sleep Code - Most Common for Sensors

#include <esp_sleep.h>

// RTC memory survives deep sleep!
RTC_DATA_ATTR int bootCount = 0;

void setup() {
    Serial.begin(115200);
    bootCount++;
    
    Serial.printf("Boot #%d\n", bootCount);
    
    // Read sensors (takes ~1 second)
    int moisture = analogRead(32);
    float temp = readTemperature();
    
    // Send data (connect WiFi, send, disconnect)
    sendToCloud(moisture, temp);
    
    // Go to deep sleep for 1 hour
    // 1 hour = 1 * 60 * 60 * 1,000,000 microseconds
    esp_sleep_enable_timer_wakeup(3600000000);
    esp_deep_sleep_start();
    
    // Code here NEVER runs - ESP32 is sleeping!
}

void loop() {
    // This never runs - everything in setup()
}
    

๐Ÿ“Š Power Consumption Calculation

โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
                    BATTERY LIFE CALCULATION
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

  2600mAh battery, reading every 15 minutes:
  
  Active mode (5 seconds): 150mA ร— 5 sec = 0.208mAh
  Deep sleep (895 sec):     2.5ฮผA ร— 895 sec = 0.00062mAh
  Total per 15min cycle:                   = 0.2086mAh
  
  Cycles per day: 96
  Daily power use: 96 ร— 0.2086 = 20mAh/day
  
  โšก Battery life = 2600mAh รท 20mAh/day = 130 DAYS!
  
  Increase to 1 hour intervals โ†’ 2+ years battery life!

โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
๐Ÿ’ก RTC Memory - Data That Survives Deep Sleep:
  • RTC_DATA_ATTR - Variables kept in RTC memory (8KB available)
  • Use for: Boot counters, sensor calibrations, timestamps, error logs
  • Don't use for: Large arrays, strings, or non-critical data
  • Regular variables are LOST - only RTC_DATA_ATTR survives

๐Ÿ“– Wake Sources - Triggering from Sleep

// Timer wake (most common for sensors)
esp_sleep_enable_timer_wakeup(3600000000);  // 1 hour

// External GPIO wake (button or sensor trigger)
esp_sleep_enable_ext0_wakeup(GPIO_NUM_0, LOW);  // Wake on button press

// Touch wake (no external button needed)
touchSleepWakeUpEnable(T0, 40);  // Wake on touch

// Light sleep with timer (faster wake, more power)
esp_light_sleep_start();
    
โš ๏ธ Common Deep Sleep Mistakes:
  • โŒ Calling delay() after sleep start โ†’ Code after esp_deep_sleep_start() never runs
  • โŒ Using Serial.print() after wake โ†’ Works but uses power, keep minimal
  • โŒ Not disabling WiFi before sleep โ†’ WiFi must be off first
  • โŒ Using analogRead() with deep sleep โ†’ Works, but takes 1-2 seconds
๐Ÿ“– Case Study - 2+ Years on Two AA Batteries:

A soil moisture sensor in remote Kenya needed long battery life:

  • Challenge: No power lines, batteries hard to replace
  • Solution: Deep sleep between readings (wake every 4 hours)
  • Setup: Wake โ†’ read sensor โ†’ send data (10 sec) โ†’ deep sleep
  • Result: 2,500mAh batteries lasted over 2 years!
  • Savings: No battery changes needed for entire growing season

"We check data weekly and haven't replaced batteries in 20 months." - Field Technician, Kenya

๐ŸŽ‰ Key Takeaways:
  • โœ… Deep sleep = 2.5ฮผA (60,000x less than active mode)
  • โœ… Use RTC_DATA_ATTR to preserve data across sleep cycles
  • โœ… 15-minute readings = 130 days battery life
  • โœ… 1-hour readings = 2+ years battery life
  • โœ… Timer wake is best for regular sensor readings

Pro tip: Always test your sleep current with a multimeter - you should see microamps, not milliamps!

Sleep ModeCurrentWake TimeBest For
Modem Sleep10-30mA<1msWiFi with low latency
Light Sleep0.8-2mA~1ms1-60 second intervals
Deep Sleep2.5-10ฮผA~2ms1 minute+ intervals
Hibernation2.5ฮผA~10msHours/days intervals
๐Ÿ’ก Key Takeaways:
  • Apply these concepts directly to your farm or project.
  • Take notes on important details for the quiz.
  • Use the button below to track your progress.