I am building a ESP-07 based IOT device, that detects the status of 4 doors. The device must connect to WiFi and send an http request, when 1 of 4 doors is opened. I want to place a reed switch, for example on each door. The battery consumption should be minimal, so I thought of using deepsleep () or something similar to keep the device asleep most of the time, or keep it completely off (like most Dash buttons does).

I have studied several options, but almost all use a single GPIO to wake up the device. For example, this option wakes the device up if D3 goes high, and sleep if D3 is low. #include #include #define WAKE_PIN D3

const char* ssid = "SSID";
const char* pass = "PASSWORD";

extern "C" {
    #include "gpio.h"

extern "C" {
    #include "user_interface.h"

void setup(){
    WiFi.begin(ssid, pass);
    uint8_t i = 0;
    while (WiFi.status() != WL_CONNECTED && i++ < 10) delay(250);
    digitalWrite(LED_BUILTIN, LOW);
    gpio_init(); // Initilise GPIO pins

void loop(){
    Serial.println("Do something...");

void sleep(){
    Serial.println("Going to sleep...");
    wifi_fpm_set_sleep_type(LIGHT_SLEEP_T); // set sleep type
    gpio_pin_wakeup_enable(GPIO_ID_PIN(WAKE_PIN), GPIO_PIN_INTR_HILEVEL); 
    wifi_fpm_open(); // Enables force sleep
    wifi_fpm_do_sleep(0xFFFFFFF); // Sleep for longest possible time
    Serial.println("Woke up!");

Here, GPIO_ID_PIN(2) corresponds to GPIO2 on ESP8266-01 , GPIO_PIN_INTR_LOLEVEL for a logic low, can also do other interrupts.

My question is:

Can I use more than one GPIO, that is, one of 4 GPIOs to wake up the device?

I have the problem of knowing which of the four doors has been opened!

The other option I have thought is to use a latch circuit that turns on the (previously turned off) device using a single GPIO. Something like this:

Latch circuit

What I meant is that ESP-07 can latch its own power on (and off) using an MOSFET pair connected in parallel with the physical (momentary contact) power switch. When the power switch is pressed (or a door is opened), one of the first things the ESP8266 needs to do is latch the power on. When the current iteration of this programm is done, it simply turns it's own power off again.

#define POWER_SW   2   // GPIO connected to POWER_LATCH

void LatchOn() {
    pinMode(POWER_SW, OUTPUT); 
    digitalWrite(POWER_SW, HIGH);

void LatchOff() {
    digitalWrite(POWER_SW, LOW);

What I want to know is how I can use more than one signal from each of the 4 doors, or, use 4 GPIOs to activate the latch circuit. I tried with one single door connected to the GPIO that wakes the chip up. I want to extend the functionality of my program so that any of the 4 doors turns the chip on.

Thanks in advance!

I have opened a thread about this topic in Arduino Forum as well.

  • 1
    do you have the option of using a logic IC? Jan 17 '18 at 15:59
  • Sounds good! Any ideas? Jan 17 '18 at 16:06
  • 1
    Idea: Wire the four door-GPIOs together with an OR gate, connect that to your wakeup pin, but still connect all door-GPIOs to 4 different GPIO pins on your ESP8266. When a wakeup is triggered (because ANY of the door GPIOs were triggered), read the state of the 4 door-GPIOs, act on it, then go back to sleep. You can use simple diode-ORs or CMOS (N)OR logic gates for this. Jan 17 '18 at 17:51
  • 1
    Also asked at stackoverflow.com/q/48279829
    – per1234
    Jan 17 '18 at 19:55
  • A friend from Arduino Forum told me that I can use a bunch of diodes to have all door switches trigger two pins: the shared wake-up pin, and a unique one for each switch. I have no idea how I could do that. Any idea of what a circuit with these characteristics would look like? Thanks in advance. Jan 18 '18 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.