â Back to Course
Power Saving with Deep Sleep for Battery Operation
ð Power Saving with Deep Sleep
For solar-powered or battery-operated sensors in remote fields, deep sleep is essential. ESP32 can last months on a single charge!
ð Power Consumption Comparison:
- Normal operation: 80-240mA
- WiFi connected: 120-180mA
- Light sleep: ~0.8mA
- Deep sleep: 2.5ΞA (0.0025mA!)
ðĪ Deep Sleep Example:
#includeconst char* ssid = "YOUR_WIFI"; const char* password = "YOUR_PASSWORD"; RTC_DATA_ATTR int bootCount = 0; void print_wakeup_reason() { esp_sleep_wakeup_cause_t reason = esp_sleep_get_wakeup_cause(); switch(reason) { case ESP_SLEEP_WAKEUP_TIMER: Serial.println("Wake up by timer"); break; case ESP_SLEEP_WAKEUP_TOUCHPAD: Serial.println("Wake up by touch"); break; default: Serial.println("Wake up by other reason"); } } void setup() { Serial.begin(115200); delay(1000); bootCount++; Serial.println("Boot number: " + String(bootCount)); print_wakeup_reason(); // Connect to WiFi and send data WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("\nWiFi connected!"); // Read sensors and send to OceanRemote here // ... your data sending code ... Serial.println("Going to deep sleep for 5 minutes..."); esp_sleep_enable_timer_wakeup(5 * 60 * 1000000); // 5 minutes in microseconds esp_deep_sleep_start(); } void loop() { // This will never run }
ð Battery Life Calculation:
With a 2000mAh battery and 5-minute wake intervals:
- Wake time: 5 seconds @ 150mA = 0.21mAh per cycle
- Sleep time: 5 minutes @ 0.0025mA = 0.00021mAh per cycle
- Total per cycle: ~0.21mAh
- Cycles per day: 288
- Battery life: 2000 / (0.21 * 288) = 33 DAYS
- With optimization and larger battery: 6+ MONTHS!
ðĄ Pro Tip: Add a solar panel (6V 2W) with a TP4056 charging module for unlimited battery life!
ðĄ 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.
×