DeepSleep Labs

Master ESP32 deep sleep power budgeting with hands-on embedded C and FreeRTOS coaching. Learn to build battery-powered IoT devices that last...
Quezon City, PH
Created byProfile pictureduskyhair34
1 joined
Profile picture
@duskyhair34Profile pictureJun 9

The 3 ESP32 Deep Sleep Mistakes That Drain Your Battery in Days Instead of Months

{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"I've reviewed power budgets for dozens of ESP32-based products. The same three mistakes show up in almost every project that's burning through batteries too fast. Here's what they are and how to fix them."}]},{"type":"heading","attrs":{"level":2},"content":[{"type":"text","text":"Mistake #1: Not isolating GPIO pins before entering deep sleep"}]},{"type":"paragraph","content":[{"type":"text","text":"When the ESP32 enters deep sleep, GPIO pins retain their last state by default. If you have a pin driving HIGH into a pull-down resistor, or a floating input pin oscillating, you're leaking current through the GPIO matrix the entire time the chip is \"sleeping.\""}]},{"type":"paragraph","content":[{"type":"text","marks":[{"type":"bold"}],"text":"The fix:"},{"type":"text","text":" Call "},{"type":"text","marks":[{"type":"code"}],"text":"gpiodeepsleepholddis()"},{"type":"text","text":" and then use "},{"type":"text","marks":[{"type":"code"}],"text":"rtcgpioisolate()"},{"type":"text","text":" on every RTC-capable pin you're not using as a wake source. For non-RTC pins, explicitly set them to a known state before sleep. This alone can drop your deep sleep current from 500µA+ down to the datasheet's 10µA."}]},{"type":"heading","attrs":{"level":2},"content":[{"type":"text","text":"Mistake #2: Using espwifistart() for every transmission"}]},{"type":"paragraph","content":[{"type":"text","text":"A full Wi-Fi connect cycle — scan, authenticate, associate, DHCP — takes 3-7 seconds and pulls 100-350mA the entire time. If you're waking up every 15 minutes to send a sensor reading, that connection overhead dominates your power budget."}]},{"type":"paragraph","content":[{"type":"text","marks":[{"type":"bold"}],"text":"The fix:"},{"type":"text","text":" Cache the BSSID and Wi-Fi channel in RTC memory using "},{"type":"text","marks":[{"type":"code"}],"text":"RTCDATAATTR"},{"type":"text","text":". On wake, pass the cached values to skip the scan phase entirely. Combine this with a static IP to skip DHCP. This cuts reconnection time to ~500ms — an 85% reduction in Wi-Fi energy per cycle."}]},{"type":"codeBlock","attrs":{"language":"c"},"content":[{"type":"text","text":"RTCDATAATTR static uint8t cachedbssid[6];\nRTCDATAATTR static uint8t cachedchannel = 0;\n\nwificonfigt wificfg = { .sta = { .ssid = \"...\", .password = \"...\" } };\nif (cachedchannel != 0) {\n memcpy(wificfg.sta.bssid, cachedbssid, 6);\n wificfg.sta.bssidset = true;\n wificfg.sta.channel = cachedchannel;\n}\nespwifisetconfig(WIFIIFSTA, &wificfg);"}]},{"type":"heading","attrs":{"level":2},"content":[{"type":"text","text":"Mistake #3: Not building a power budget spreadsheet"}]},{"type":"paragraph","content":[{"type":"text","text":"This isn't a code mistake — it's a process mistake. Engineers will optimize individual sleep modes for hours but never calculate whether the total duty cycle actually meets the battery life target. A power budget spreadsheet takes 30 minutes to build and answers the only question that matters: \"Will this last long enough on a single charge?\""}]},{"type":"paragraph","content":[{"type":"text","marks":[{"type":"bold"}],"text":"The formula:"}]},{"type":"codeBlock","attrs":{"language":"text"},"content":[{"type":"text","text":"Average Current = Σ (Istate × tstate) / T_total\n\nExample:\n Active + Wi-Fi: 160mA × 0.8s = 128 mAs\n Sensor read: 30mA × 0.2s = 6 mAs\n Deep sleep: 10µA × 899s = 9 mAs\n ─────────────────────────────────────\n Total cycle: 900s (15 min)\n Average: 143 mAs / 900s = 159µA\n \n With a 2000mAh battery:\n 2000mAh / 0.159mA = 12,578 hours ≈ 524 days"}]},{"type":"paragraph","content":[{"type":"text","text":"That's the difference between \"my battery dies in a week\" and \"my battery lasts over a year.\" And it all comes down to measuring, calculating, and optimizing the right things."}]},{"type":"paragraph","content":[{"type":"text","text":"If you want to go deep on all of this — ULP coprocessor programming, RTC memory patterns, FreeRTOS tick suppression, production-grade Wi-Fi optimization — that's exactly what we cover inside the course."}]}]}