โ Back to Course
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
| Mode | Current | Wake Sources | RAM Retention | Best For | |||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Active | 80-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:
๐ 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:
๐ Case Study - 2+ Years on Two AA Batteries:
A soil moisture sensor in remote Kenya needed long battery life:
"We check data weekly and haven't replaced batteries in 20 months." - Field Technician, Kenya
๐ Key Takeaways:
Pro tip: Always test your sleep current with a multimeter - you should see microamps, not milliamps!
๐ก Key Takeaways:
×
|