Reed switch / MC-38 magnetic door sensor
Wire a glass reed switch or MC-38 magnetic door sensor with INPUT_PULLUP, normally-open vs normally-closed, gap distance, debouncing and contact limits.
Community draft — report a mistake
3.3 V or 5 V? It’s a plain switch. Wire one lead to a GPIO with INPUT_PULLUP and the other to GND — it works on every board at any logic level.
A reed switch is two springy contacts sealed in a glass tube. Bring a magnet near and they pull together and close the circuit; take it away and they spring apart. The MC-38 door/window sensor is the same thing in a plastic case with a matching magnet, sold for security systems.
Wire it like a push button: GPIO with INPUT_PULLUP and the other lead to GND. With a normally-open reed, the pin reads LOW when the magnet is near (door closed) and HIGH when the door opens. Some MC-38s are normally closed; test with a multimeter and invert in code if needed.
The contacts are tiny — rated for signals, not loads. Never switch a motor, bulb or mains through a reed switch; use it to tell your board, and let a relay or MOSFET do the switching. For long runs to a door, a 1 kΩ resistor in series and a 100 nF capacitor at the pin keep noise out.
Prices are indicative (Nov 2026) and vary by seller.
Pinout
| Pin | What it does |
|---|---|
WIRE 1 | One side of the reed contact — to the GPIO |
WIRE 2 | Other side of the reed contact — to GND (no polarity) |
Use it with
Common errors
Reads both open and closed as the door moves
Contact bounce. Ignore changes for 20–50 ms after the first edge (or use the Bounce2 library).
Doesn’t switch when the door is closed
The gap is too wide or the parts aren’t aligned. Keep the magnet within about 15 mm of the switch (MC-38), with the marks lined up. Steel doors shorten the range — use a pair rated for metal doors.
Glass reed cracked or stopped working
The glass breaks if you bend the leads right at the body. Hold the lead with pliers between the glass and the bend, and keep heat brief when soldering.