Working Principle
When the door is closed, the magnet remains close to the magnetic reed switch and keeps the switch in its normal state. The ESP32 continuously monitors the reed switch to determine the current position of the door.
When the door opens, the magnet moves away from the reed switch. This causes the switch contacts to change state, producing a change in the digital signal received by the ESP32.
The ESP32 detects this change through its digital GPIO input and recognizes that the door has been opened. The controller then activates the alarm output according to the programmed conditions.
Once the alarm is activated, the buzzer produces an audible warning and the LED illuminates as a visual warning indicator. When the door is closed again, the magnet returns near the reed switch and the system can return to its normal monitoring state.