/*
* This ESP32 code is created by esp32io.com
*
* This ESP32 code is released in the public domain
*
* For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-door-sensor
*/
#define DOOR_SENSOR_PIN 19 // ESP32 pin GIOP19 connected to door sensor's pin
int doorState;
void setup() {
Serial.begin(9600); // initialize serial
pinMode(DOOR_SENSOR_PIN, INPUT_PULLUP); // set ESP32 pin to input pull-up mode
}
void loop() {
doorState = digitalRead(DOOR_SENSOR_PIN); // read state
if (doorState == HIGH) {
Serial.println("The door is open");
} else {
Serial.println("The door is closed");
}
}