OC
OceanRemote
Low-code IoT platform
← Back to Course

External Wake-Up and Touch Wake

🔘 External Wake-Up and Touch Wake

Wake ESP32 using external signals - buttons, sensors, or touch pads.

📖 GPIO External Wake-Up:

#define WAKE_PIN GPIO_NUM_33

void setup() {
    Serial.begin(115200);
    
    // Configure wake-up pin
    esp_sleep_enable_ext0_wakeup(WAKE_PIN, 0);  // Wake on LOW
    
    Serial.println("Going to sleep. Press button to wake.");
    esp_deep_sleep_start();
}

void loop() {}
    

📖 Multiple Pin Wake (Any of several pins):

// Wake when ANY of these pins are LOW
uint64_t wakePins = 0;
wakePins |= (1ULL << GPIO_NUM_32);  // Pin 32
wakePins |= (1ULL << GPIO_NUM_33);  // Pin 33
wakePins |= (1ULL << GPIO_NUM_34);  // Pin 34

esp_sleep_enable_ext1_wakeup(wakePins, ESP_EXT1_WAKEUP_ANY_LOW);
    

📖 Touch Wake-Up:

// Touch pins: T0 (GPIO4), T1 (GPIO0), T2 (GPIO2), etc.
#define TOUCH_PIN T0  // GPIO4

void setup() {
    Serial.begin(115200);
    
    // Set touch threshold
    touchAttachInterrupt(TOUCH_PIN, NULL, 40);
    esp_sleep_enable_touchpad_wakeup();
    
    Serial.println("Sleeping. Touch to wake...");
    esp_deep_sleep_start();
}
    

📖 Complete External Wake Example:

#include 

RTC_DATA_ATTR bool buttonPressed = false;

void setup() {
    Serial.begin(115200);
    
    esp_sleep_wakeup_cause_t reason = esp_sleep_get_wakeup_cause();
    
    if (reason == ESP_SLEEP_WAKEUP_EXT0) {
        Serial.println("Button pressed! Taking manual reading...");
        buttonPressed = true;
    }
    
    if (buttonPressed || shouldTakeReading()) {
        readSensors();
        sendData();
    }
    
    // Configure wake on button (GPIO33)
    esp_sleep_enable_ext0_wakeup(GPIO_NUM_33, 0);
    
    // Also wake every 15 minutes
    esp_sleep_enable_timer_wakeup(15 * 60 * 1000000ULL);
    
    Serial.println("Sleeping... Press button or wait 15 minutes");
    esp_deep_sleep_start();
}
    
⚠️ Important Notes:
  • External wake uses RTC pins only (GPIO0, 2, 4, 12-15, 25-27, 32-39)
  • Touch wake works only on specific touch pins (T0-T9)
  • Add pull-up/down resistors for reliable wake-up
  • Debounce external triggers (use capacitor or code)
💡 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.