Serial at 115200 baudTap a part to see what it does.
Tap the parts to see what each one does. A teaching simulation, not a circuit simulator.
Build it step by step
0 of 4 doneFix the switch
Switch on the frame, magnet on the door, gaps lined up within about 15 mm.
Wire the switch
One wire to GPIO27, one to GND.
LED and buzzer
LED on GPIO25 through 220 Ω; buzzer through a 2N2222 on GPIO26.
Upload and test
Open the door, wait 30 seconds, close it.
How do you build a door open notifier?
A magnetic reed switch tells an ESP32 when a door opens. An LED lights at once, and a buzzer sounds if the door stays open longer than 30 seconds. You need ESP32 DevKit V1, Door reed switch MC-38, Active buzzer 5 V, NPN Transistor 2N2222, Resistor 1 kΩ, LED 5 mm red, Resistor 220 Ω and Breadboard 830 Tie Points. It takes 4 steps and about 40 minutes.
- Level
- Beginner
- Time
- About 40 min
- Parts
- 8
Parts list
- Development BoardsBuyESP32 DevKit V1 × 1
- SensorsBuy
- Motors & ActuatorsBuy
- SemiconductorsBuyDrives the buzzer
- PassivesBuyResistor 1 kΩ × 1
- SemiconductorsBuyLED 5 mm red × 1
- PassivesBuyResistor 220 Ω × 1
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Reed switch wire 1 | ESP32 GPIO27 | INPUT_PULLUP |
| Reed switch wire 2 | GND | Closes when the door is shut |
| GPIO25 → 220 Ω → LED → GND | Open light | |
| GPIO26 → 1 kΩ → 2N2222 base | Buzzer from 5V (VIN) to collector, emitter to GND | Buzzer switch |
Code
No libraries. Change LIMIT for a shorter or longer grace period. To get a phone alert, combine with the MQTT build.
Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
const int REED = 27, LED = 25, BUZZ = 26;
const unsigned long LIMIT = 30000;
unsigned long openedAt = 0;
bool wasOpen = false;
void setup() {
Serial.begin(115200);
pinMode(REED, INPUT_PULLUP); pinMode(LED, OUTPUT); pinMode(BUZZ, OUTPUT);
}
void loop() {
bool open = digitalRead(REED) == HIGH; // magnet away = switch open = HIGH
if (open && !wasOpen) { openedAt = millis(); Serial.println("Door opened"); }
if (!open && wasOpen) Serial.printf("Door closed after %lu s\n", (millis() - openedAt) / 1000);
wasOpen = open;
digitalWrite(LED, open);
bool tooLong = open && millis() - openedAt > LIMIT;
digitalWrite(BUZZ, tooLong && (millis() / 500) % 2); // beep on and off
delay(20);
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual ESP32 Dev Module with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
Door opened
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Open the door | LED lights at once, serial prints "Door opened" |
| Leave it open 30 s | Buzzer beeps on and off |
| Close it | LED and buzzer stop, serial shows how long it was open |
If it does not work
LED on when the door is shut
Your switch is normally closed: swap HIGH for LOW in the open test.
Random triggers
Long wires pick up noise: add 100 nF from GPIO27 to GND.
Buzzer quiet
Power it from 5V through the transistor, not from the 3.3 V pin.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the door open notifier?
ESP32 DevKit V1, Door reed switch MC-38, Active buzzer 5 V, NPN Transistor 2N2222, Resistor 1 kΩ, LED 5 mm red, Resistor 220 Ω and Breadboard 830 Tie Points. NPN Transistor 2N2222: Drives the buzzer.
How long does the door open notifier take to build?
About 40 minutes for a beginner maker, in 4 steps.
How do I know the door open notifier works?
Open the door: LED lights at once, serial prints "Door opened". Leave it open 30 s: Buzzer beeps on and off. Close it: LED and buzzer stop, serial shows how long it was open.
LED on when the door is shut: what should I check?
Your switch is normally closed: swap HIGH for LOW in the open test.
Random triggers: what should I check?
Long wires pick up noise: add 100 nF from GPIO27 to GND.
Buzzer quiet: what should I check?
Power it from 5V through the transistor, not from the 3.3 V pin.
