Overview
The reed switch is the simplest magnetic sensor there is: two ferromagnetic contacts sealed inside a small glass tube filled with inert gas. Bring a magnet within range and its field magnetizes the contacts so they attract and snap together, closing the circuit; take the magnet away and the springy reeds separate again. No power supply, no signal conditioning, no standby current — it is a switch that a magnet presses for you, straight out of the same playbook as commercial door and window alarm sensors.
This is the normally-open (NO) type: the circuit is open at rest and closes when a magnet is near, typically within 10-20 mm depending on the magnet's strength and orientation. Wiring to a microcontroller takes two connections — one lead to a GPIO with an internal pull-up enabled, the other to ground. The pin then reads HIGH with no magnet and LOW when the magnet arrives. Because the switch itself consumes zero current while open, it is a favorite for battery-powered projects that sleep until a door moves.
Uses are everywhere: door and window monitors, mailbox and drawer alarms, lid-open detection on enclosures and 3D printers, bike wheel speed counting (magnet on a spoke), fill-level floats, and end-stop sensing — anywhere "did the magnet arrive or leave" answers the question. Handle the glass body gently: grip the leads with pliers when bending, never bend at the glass seal.
At a Glance
Specifications
| Parameter | Value |
| Switch Type | Normally open (NO), single pole single throw |
| Construction | Ferromagnetic reed contacts hermetically sealed in glass |
| Actuation Distance | ~10 - 20 mm with a typical neodymium magnet |
| Max Switching Power | ~10 W |
| Max Switching Current | ~0.5 A (small signal loads) |
| Max Switching Voltage | ~100 - 200V DC (use low-voltage logic in practice) |
| Contact Resistance | ~0.1 Ω closed |
| Operate / Release Time | Under ~0.5 ms, with brief contact bounce |
| Mechanical Life | Millions of operations at signal-level loads |
| Standby Current | Zero — ideal for battery projects |
Pinout Diagram
There is no pinout to memorize — the reed switch has two identical leads with no polarity, so it can be wired either way around. What matters is the state logic shown below: contacts open with no magnet, closed when a magnet's field reaches the reeds. Sensitivity is best when the magnet approaches side-on along the tube's axis; a stronger magnet extends the trigger distance.
Wiring Guide
The same two-wire recipe works on every board: one lead to a GPIO configured with an internal pull-up, the other lead to ground. Magnet absent = pin reads HIGH; magnet present = switch closes to ground = pin reads LOW. No resistors needed — the microcontroller's internal pull-up does the work.
Arduino Wiring
| Reed Switch Lead | Arduino Pin | Details |
|---|---|---|
| Lead 1 | D2 | Configured INPUT_PULLUP |
| Lead 2 | GND | Either lead — no polarity |
ESP32 Wiring
| Reed Switch Lead | ESP32 Pin | Details |
|---|---|---|
| Lead 1 | GPIO 25 | Internal pull-up in code |
| Lead 2 | GND |
Raspberry Pi Wiring
| Reed Switch Lead | Raspberry Pi Pin | Details |
|---|---|---|
| Lead 1 | Pin 11 (GPIO 17) | Internal pull-up in code |
| Lead 2 | Pin 6 (GND) |
Raspberry Pi Pico Wiring
| Reed Switch Lead | Pico Pin | Details |
|---|---|---|
| Lead 1 | GP15 (pin 20) | Internal pull-up in code |
| Lead 2 | GND (pin 38) |
Code Examples
Each example implements a door/window monitor: internal pull-up enabled, a short debounce to ride out contact bounce, and a message only when the state changes.
Arduino
// Reed Switch Door Monitor - Arduino Example
// Lead 1 -> D2, Lead 2 -> GND (either way around)
const int reedPin = 2;
int lastState = HIGH;
void setup() {
Serial.begin(9600);
pinMode(reedPin, INPUT_PULLUP); // HIGH = open, LOW = magnet present
Serial.println("Monitoring door...");
}
void loop() {
int state = digitalRead(reedPin);
if (state != lastState) {
delay(30); // debounce contact bounce
state = digitalRead(reedPin);
if (state != lastState) {
if (state == LOW) {
Serial.println("CLOSED - magnet present");
} else {
Serial.println("OPEN - magnet away!");
// trigger your alarm/notification here
}
lastState = state;
}
}
delay(10);
}
ESP32 (MicroPython)
# Reed Switch Door Monitor - ESP32 MicroPython Example
# Lead 1 -> GPIO 25, Lead 2 -> GND
from machine import Pin
import time
reed = Pin(25, Pin.IN, Pin.PULL_UP) # 1 = open, 0 = magnet present
last = reed.value()
print("Monitoring door...")
while True:
state = reed.value()
if state != last:
time.sleep_ms(30) # debounce
state = reed.value()
if state != last:
if state == 0:
print("CLOSED - magnet present")
else:
print("OPEN - magnet away!")
last = state
time.sleep_ms(10)
Raspberry Pi (Python)
#!/usr/bin/env python3
# Reed Switch Door Monitor - Raspberry Pi Example
# Lead 1 -> GPIO 17 (pin 11), Lead 2 -> GND (pin 6)
import RPi.GPIO as GPIO
import time
REED_PIN = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(REED_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
last = GPIO.input(REED_PIN)
print("Monitoring door (Ctrl+C to stop)...")
try:
while True:
state = GPIO.input(REED_PIN)
if state != last:
time.sleep(0.03) # debounce
state = GPIO.input(REED_PIN)
if state != last:
if state == GPIO.LOW:
print("CLOSED - magnet present")
else:
print("OPEN - magnet away!")
last = state
time.sleep(0.01)
except KeyboardInterrupt:
print("Stopped by user")
finally:
GPIO.cleanup()
Raspberry Pi Pico (MicroPython)
# Reed Switch Door Monitor - Pico MicroPython Example
# Lead 1 -> GP15, Lead 2 -> GND
from machine import Pin
import time
reed = Pin(15, Pin.IN, Pin.PULL_UP) # 1 = open, 0 = magnet present
last = reed.value()
print("Monitoring door...")
while True:
state = reed.value()
if state != last:
time.sleep_ms(30) # debounce
state = reed.value()
if state != last:
if state == 0:
print("CLOSED - magnet present")
else:
print("OPEN - magnet away!")
last = state
time.sleep_ms(10)