Back to Sensors & Actuators Series

Reed Switch: Magnetic Contact Sensor

April 10, 2026 Wasil Zafar 7 min read

Reed switch deep dive — magnetic contact detection, debouncing, Arduino code, and security system/smart home applications.

Contents

  1. Working Principle
  2. Electrical Characteristics
  3. Interfacing with MCU
  4. Calibration
  5. Code Example
  6. Real-World Applications
  7. Limitations

Working Principle

A reed switch is a magnetically operated electromechanical switch consisting of two thin ferromagnetic reeds sealed in a glass envelope filled with inert gas. When a magnet comes within range (typically 10–30 mm), the magnetic field magnetises the reeds, pulling them together to close the circuit. Remove the magnet and the reeds spring apart, opening the circuit.

Reed switches come in two types: Normally Open (NO) — closed when magnet present; and Normally Closed (NC) — opened when magnet present. For security applications, NO is standard (alarm triggers when magnet is removed/door opens).

Electrical Characteristics

ParameterTypical Value
Contact ConfigurationSPST-NO (Normally Open, most common)
Operating Range10–30 mm (depends on magnet strength)
Max Switching Voltage100–200 V DC
Max Switching Current0.5–1.0 A
Contact Resistance<100 mΩ (closed)
Operate Time~0.5 ms
Release Time~0.1 ms
Bounce Time~1 ms (needs debouncing)
Lifecycle>107 operations (mechanical endurance)

Interfacing with an MCU

Connect one reed switch terminal to a GPIO pin and the other to GND. Enable the MCU’s internal pull-up resistor (or use an external 10 kΩ pull-up to VCC). When the magnet is away (NO switch open), the pin reads HIGH; when the magnet is close (switch closed), the pin reads LOW. Use a 100 nF capacitor across the switch for hardware debouncing.

Magnet selection: Use a rare-earth neodymium magnet (N35 or stronger) for reliable operation. Ferrite magnets have weaker fields and require closer placement. Align the magnet parallel to the reed switch axis for maximum sensitivity.

Calibration

  • Range testing: Determine the operate distance and release distance (hysteresis) for your specific magnet/switch combination
  • Debouncing: Implement software debounce (10–50 ms delay) or use a hardware RC filter to eliminate contact bounce false triggers
  • Orientation: The magnet must approach along the switch’s sensitive axis (lengthwise); perpendicular approach reduces effective range by ~50%

Code Example

/*
 * Reed Switch — Door/Window Contact Sensor
 * Wiring: Pin 1 → D3 (with internal pull-up), Pin 2 → GND
 *         Magnet mounted on door/window
 */
#define REED_PIN 3
#define DEBOUNCE_MS 50

bool lastState = HIGH;   /* Open (magnet away) */
unsigned long lastChange = 0;

void setup() {
    Serial.begin(9600);
    pinMode(REED_PIN, INPUT_PULLUP);
    Serial.println("Reed Switch Door Sensor Ready");
}

void loop() {
    bool current = digitalRead(REED_PIN);

    if (current != lastState &&
        (millis() - lastChange) > DEBOUNCE_MS) {
        lastChange = millis();
        lastState = current;

        if (current == LOW) {
            Serial.println("CLOSED — door/window shut");
        } else {
            Serial.println("OPEN — door/window opened!");
            /* Trigger alarm, send notification, etc. */
        }
    }
    delay(10);
}

Real-World Applications

Security Systems, Smart Home & Speed Measurement

Reed switches are ubiquitous in door/window alarm contacts, laptop lid detection (sleep when closed), bike speedometers and odometers (magnet on spoke), water/gas meter pulse counting, security systems (tamper detection), elevator position sensing, and smart home door sensors (Zigbee/Z-Wave modules use reed switches internally).

SecuritySmart HomeSpeedometerMetering

Limitations

  • Mechanical wear: Contact surfaces degrade after 107+ operations; high-current switching accelerates wear.
  • Contact bounce: ~1 ms bounce produces spurious pulses; must debounce in software or hardware.
  • Magnetic interference: Strong external magnetic fields (motors, speakers) can trigger false activations.
  • Fixed range: Detection range is fixed by the magnet strength and switch sensitivity; cannot be adjusted electronically.
  • Glass fragility: The glass envelope is delicate; handle carefully during mounting.