Skip to content
SensorsMotion

Magnetic Reed Switch Door/Window Sensor

Simple, reliable open/close detection for DIY alarms.

Reed Switch practical reference

A reed switch is a simple electromechanical switch made of two ferromagnetic metal reeds sealed inside a glass tube. The reeds snap together to close the circuit whenever a magnet passes near them, and spring apart when the magnet moves away. With no power draw and no moving parts beyond the reeds themselves, it's the classic low-cost sensor for detecting whether a door or window is open or closed in DIY security systems, and for simple proximity or rotation-counting triggers.

Key specifications

  • Switch type: Normally-open (NO) magnetic reed switch — normally-closed (NC) variants also exist
  • Operating voltage: Passive component — rated for typical logic-level or low-voltage switching, commonly up to 100-200V depending on part
  • Switching current: ~0.5A max typical for small glass reed switches
  • Actuation distance: ~10-15mm typical, depends on magnet strength and reed sensitivity rating
  • Response time: Sub-millisecond mechanical closure, effectively instantaneous for most microcontroller polling rates
  • Interface: Simple digital I/O — read as a plain HIGH/LOW switch input with a pull-up or pull-down resistor
  • Package: Often sold pre-wired in a two-part door/window sensor housing with the matching magnet included

Pinout and connection notes

Wire one lead to a digital input pin and the other to GND, then enable the microcontroller's internal pull-up resistor (INPUT_PULLUP) so the pin reads HIGH when open and LOW when the magnet closes the switch — this avoids needing an external resistor for a simple door/window sensor build.

  • Lead 1: One side of the switch contact — wire to a digital input pin
  • Lead 2: Other side of the switch contact — wire to GND (or VCC, depending on pull configuration)

Integration checklist

  1. Confirm the exact part number and breakout-board revision.
  2. Verify supply voltage, current demand, logic levels, and signal direction against the datasheet.
  3. Check controller pin assignments and bus address or interface mode against the example code.
  4. Power up with external loads disconnected, then test signals before full integration.
  5. If readings or communication fail, check power and ground first, then pin mapping, interface settings, and library initialization.

Troubleshooting and reproducibility

Record the board used, wiring, library/version, supply arrangement, and measured behavior. Use the selected board-specific wiring example as the source of truth. Never assume visually similar modules share identical voltage tolerance or pin order.

Board Integration

Library

None — built-in digitalRead by —

No library needed; uses core Arduino functions only.

Wiring

Component pinArduino Uno pinNote
Leg 1D2Configure as INPUT_PULLUP — no external resistor needed.
Leg 2GNDReed switches have no polarity.

Swipe sideways to see every column →

C++
  • This is a passive mechanical switch, not a powered sensor — no VCC connection needed, just the pin and GND.
  • Works with a small magnet mounted on the moving part (door, drawer, etc.) passing near the switch body.
  • Bounces like any mechanical switch — add a short debounce delay if you are counting open/close events rather than just reading state.
View full Arduino Uno guide