Documentation

Normally Open Reed Switch Magnetic Sensor for Arduino, Raspberry Pi & ESP32 | ShillehTek Product Manual
Documentation / Normally Open Reed Switch Magnetic Sensor for Arduino, Raspberry Pi & ESP32 | ShillehTek Product Manual

Normally Open Reed Switch Magnetic Sensor for Arduino, Raspberry Pi & ESP32 | ShillehTek Product Manual

shillehtek

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

Type
Normally open (NO), SPST
Actuation
Magnet within ~10-20 mm
Power Required
None — passive contacts
Switching Rating
~10 W max, small signals
Polarity
None — leads interchangeable
Body
Sealed glass tube

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.

Normally open reed switch diagram showing open contacts with no magnet and closed contacts when a magnet is near

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
Tip: Mount the switch on the frame and the magnet on the moving part (door, lid, wheel). Align them so the closed position brings the magnet within a centimeter of the glass tube.

ESP32 Wiring

Reed Switch Lead ESP32 Pin Details
Lead 1 GPIO 25 Internal pull-up in code
Lead 2 GND
Tip: A reed switch on an RTC-capable GPIO makes a superb deep-sleep wake source — the ESP32 can sleep at microamps and wake the instant a door opens, since the switch itself draws nothing.

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)
Note: Because the switch only ever connects the pin to ground, there is no voltage-level concern on any board — one of the perks of a passive sensor.

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_arduino.ino
// 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_esp32.py
# 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)

reed_switch_rpi.py
#!/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_pico.py
# 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)

Frequently Asked Questions

Which lead is positive?
Neither — a reed switch is just two contacts, completely non-polarized, so the leads are interchangeable. Wire one to your GPIO and one to ground in either order.
From how far away will a magnet trigger it?
Typically 10-20 mm with a small neodymium magnet, less with weak fridge-style magnets. Orientation matters: fields aligned along the tube's axis work best. If your gap is larger, use a bigger magnet, stack two, or reposition so the magnet passes closer — trigger distance is set by the magnet as much as the switch.
Can it switch a load directly, like an LED strip or a pump?
Only small loads: stay under roughly 0.5 A and 10 W, and avoid inductive loads (motors, relay coils) whose sparks erode the contacts. The right pattern for anything bigger is reed switch → GPIO → transistor/MOSFET or relay module. Never switch mains voltage with a bare glass reed switch.
Is this normally-open or normally-closed — and what if I need the opposite?
This one is normally open: open circuit until a magnet closes it. If your logic wants the opposite behavior, simply invert in code — with the pull-up wiring here, HIGH means "no magnet" and LOW means "magnet present," so both interpretations are one comparison away. True NC reed switches exist but are rarely necessary for microcontroller projects.
How fragile is the glass, really?
The tube survives normal handling but not lead-bending stress at the seal. When you need to bend or trim leads, grip the lead between the glass and the bend point with needle-nose pliers so no force reaches the seal. Mount with adhesive, heat-shrink, or a dab of hot glue rather than clamping the glass itself.
Why do I sometimes get multiple triggers from one door movement?
Two reasons: mechanical contact bounce (microseconds to milliseconds of chatter as the reeds meet) and the magnet lingering at the trigger boundary. The debounce delay in the examples handles the first; mounting so the magnet moves decisively past the switch — rather than hovering at the edge of range — handles the second.
Reed switch or Hall effect sensor — which should I use?
Reed: zero power, zero code overhead, works with any microcontroller or even no microcontroller at all — ideal for battery door sensors and simple alarms. Hall sensor: no moving parts, immune to contact bounce, faster, and (in linear versions like the 49E) reports field strength — better for high-speed counting and analog sensing. For a door monitor, the reed switch's zero standby current usually wins.

Related Tutorials