OC
OceanRemote
Low-code IoT platform
← Back to Course

Deep Sleep with Timer Wake-Up

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 Active150mA17 hours
Deep Sleep (15 min wake)0.15mAh/cycle6+ 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 timer
  • esp_deep_sleep_start() → Enter deep sleep
  • RTC_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.