//MAG-SW demo - connect one wire to free GPIO, connect the other to GND //In this demo I have connected it to GPIO32 of ESP32-POE if you use other //GPIO change the first line const int DOOR_SENSOR_PIN = 32; // GPIO pin connected to the MAG-SW int doorState; void setup() { Serial.begin(115200); // initialize serial pinMode(DOOR_SENSOR_PIN, INPUT_PULLUP); // set Arduino pin to input pull-up mode } void loop() { doorState = digitalRead(DOOR_SENSOR_PIN); // read state if (doorState == HIGH) { Serial.println("Door is open"); } else { Serial.println("Door is closed"); } }