Enter ESP Deep Sleep
Power down most of the chip between readings.
Enter ESP Deep Sleep is a free Arduino & IoT Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Arduino & IoT Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Deep Sleep Is
Deep sleep powers down almost the entire chip, leaving only a tiny timer awake. Current can drop from milliamps to mere microamps. 😴
Sleep, Then Restart
Unlike a pause, deep sleep clears most memory. When the ESP wakes, it restarts from the top of setup, just like a fresh power-on.
The Microamp Difference
An awake ESP32 may draw 80mA, but in deep sleep it can sip under 20microamps. That gap is what turns days of life into months.
Sleep on the ESP32
On the ESP32, one call sends the chip to deep sleep. You pass the sleep time in microseconds and the chip powers down instantly.
esp_deep_sleep_start();Set a Timer Wakeup
Before sleeping, tell the ESP32 how long to nap with a timer. The value is in microseconds, so multiply seconds by one million.
esp_sleep_enable_timer_wakeup(10 * 1000000);Sleep on the ESP8266
The ESP8266 uses a different call. deepSleep takes microseconds too, putting the chip to rest until the timer fires.
ESP.deepSleep(10e6); // sleep 10 secondsThe Required Wire
On many ESP8266 boards, deep sleep wakeup needs a wire from GPIO16 to RST. Without it the chip naps forever and never returns.
Code After Sleep Never Runs
Any line written after the deep sleep call is unreachable. The chip stops there and only continues by restarting from the top.
Keeping Data Across Naps
Normal variables reset on wakeup. To survive deep sleep, store small values in RTC memory, which stays powered while the chip rests.
RTC_DATA_ATTR int bootCount = 0;Do Your Work First
Since sleep ends the program, finish everything first: read sensors, send data, then call deep sleep as the very last action.
A Tiny Sleep Sketch
This setup arms a 10-second timer and sleeps. Loop stays empty because the chip restarts each cycle, never reaching it.
void setup(){
esp_sleep_enable_timer_wakeup(10*1000000);
esp_deep_sleep_start();
}Quick Check
Let us confirm how deep sleep behaves.
Recap: Deep Sleep Saves
Deep sleep drops current to microamps, then restarts from setup on wakeup. Do all your work first, and use RTC memory to keep values. 🔋
Frequently asked questions
Is the “Enter ESP Deep Sleep” lesson free?
Yes — the full text of “Enter ESP Deep Sleep” is free to read here on the web, and the Arduino & IoT Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Arduino & IoT Academy course, upgrade to CoddyKit PRO.
What will I learn in “Enter ESP Deep Sleep”?
Power down most of the chip between readings. You practise Arduino & IoT Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Arduino & IoT Academy?
No prior experience is required. Arduino & IoT Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Enter ESP Deep Sleep” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Arduino & IoT Academy lesson?
Yes. Every Arduino & IoT Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Where the Power Goes
- Enter ESP Deep Sleep
- Wake on Timer or Pin
- Design a Battery Sensor Node