â Back to Course
Deep Sleep with Timer Wake-Up
â° Deep Sleep with Timer Wake-Up - Battery Life from Days to Months
â° What You'll Learn:
- ðī Put ESP32 into deep sleep between readings (2.5ΞA)
- â° Wake up at regular intervals using timer
- ð Adjust sleep duration based on soil moisture or battery level
- ðū Use RTC memory to preserve data across sleep cycles
⥠Power Comparison
| Mode | Current | Battery Life (2600mAh) |
|---|---|---|
| Always Active | 150mA | 17 hours |
| Deep Sleep (15 min wake) | 0.15mAh/cycle | 6+ months |
ðĄ Key Insight:
Deep sleep reduces power from 150mA to 2.5ΞA - a 60,000x reduction! A sensor waking for 3 seconds every 15 minutes lasts 6+ months on batteries.
ð Basic Timer Deep Sleep
#include <WiFi.h>
RTC_DATA_ATTR int bootCount = 0;
void setup() {
Serial.begin(115200);
bootCount++;
Serial.printf("Wake #%d\n", bootCount);
// Read sensors and send data
readSensors();
sendToCloud();
// Sleep for 5 minutes
esp_sleep_enable_timer_wakeup(5 * 60 * 1000000ULL);
esp_deep_sleep_start();
}
void loop() {}
ð Smart Sleep (Adjust by Conditions)
RTC_DATA_ATTR int lastMoisture = 0;
void setup() {
int moisture = readSoil();
float battery = readBattery();
int sleepMin = 15;
if (battery < 3.3) sleepMin = 60; // Low battery
else if (moisture < 30) sleepMin = 5; // Very dry
else if (moisture > 70) sleepMin = 30; // Very wet
// Send only if changed
if (abs(moisture - lastMoisture) > 5) {
sendData(moisture);
lastMoisture = moisture;
}
esp_sleep_enable_timer_wakeup(sleepMin * 60 * 1000000ULL);
esp_deep_sleep_start();
}
ðĄ Recommended Intervals:
- Soil moisture: 10-30 minutes
- Weather station: 5-15 minutes
- Low battery: 60 minutes (emergency mode)
- Very dry soil: 5 minutes (monitor closely)
ð Case Study - 14x Battery Life:
A soil sensor woke every 1 minute â battery lasted 3 days. Changed to 15-minute wake â battery lasted 6 weeks (14x improvement).
ðŊ Quick Reference:
esp_sleep_enable_timer_wakeup(us)â Set timeresp_deep_sleep_start()â Enter deep sleepRTC_DATA_ATTRâ Variables survive sleep- 5 minutes = 5 * 60 * 1000000 microseconds
ðĄ 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.
×