Skip to content

ESP32 GPIO Hold During Sleep Not Working

DodaTech Updated 2026-06-26 1 min read

In this tutorial, you'll learn about ESP32 GPIO Hold During Sleep Not Working. We cover key concepts, practical examples, and best practices.

The Problem

ESP32 GPIO pins change state during deep sleep despite setting hold.

Quick Fix

Wrong

gpio_hold_en(GPIO_NUM_2);  // Hold not applied before sleep
GPIO 2 goes LOW during deep sleep even though set HIGH before.
digitalWrite(2, HIGH);  // Set desired state
gpio_hold_en(GPIO_NUM_2);   // Enable hold on this pin
gpio_deep_sleep_hold_en();  // Enable hold for all held pins
esp_deep_sleep_start();
// GPIO 2 stays HIGH during deep sleep
GPIO 2 measures 3.3V during deep sleep (held HIGH).

Prevention

Set output state before enabling hold. Call gpio_deep_sleep_hold_en() to enable holds in sleep. Only RTC GPIOs support hold during deep sleep. Hold keeps both level and direction. Release hold with gpio_hold_dis().

DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.

FAQ

### Which GPIOs support hold during sleep?

Only RTC GPIOs (0, 2, 4, 12-15, 25-27, 32-39) support the hold function during deep sleep.

How do I release a held GPIO?

Call gpio_hold_dis(pin) and then configure the pin normally. You must release hold before changing the pin direction.

Can I hold a pin LOW?

Yes. Set digitalWrite(pin, LOW) then gpio_hold_en(pin). The pin stays LOW during deep sleep.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro