Reed Switch

A reed switch is an electrical switch operated by a magnetic field. It consists of two thin metal reeds sealed in a glass tube. When a magnet is brought near, the reeds attract and close the circuit; removing the magnet opens it. Reed switches are commonly used in security systems, appliances, and proximity sensors due to their simplicity, reliability, and low power consumption.

Electrical reed switch
Fig.: Electrical reed switch
Explanation of the structure of a reed switch
Fig.: Explanation of the structure of a reed switch
Electronic symbol of a reed switch
Fig.: Electronic symbol of a reed switch

Applications

Features/Specifications

Contact Form SPST (Normally Open)
Switching Voltage (Max) 24 VDC
Switching Current (Max) 100 mA
Temperature Range -40°C to +125°C

📄 Reed switch datasheet (97 kB)

Used Components

Setup & Programming

Arduino Uno

The setup for reading a reed switch is analogous to a normal switch, which is connected between VCC and GND. A high-ohm resistor is required to prevent a short circuit and ensure that as little current as possible flows when closing the switch. A connection to a digital input is now placed between the reed switch and the resistor.

Circuit diagram for connecting a reed switch with the Arduino Uno
Fig.: Circuit diagram for connecting a reed switch with the Arduino Uno

The following code reads the state of the reed switch at the input D2 of the Arduino UNO and writes the corresponding transition to the serial console of the Arduino IDE.

#define PIN_REED 2

void setup() {
   pinMode(PIN_REED, INPUT);
   Serial.begin(9600);
}

void loop() {
   static bool switchOn = false;

   if (digitalRead(PIN_REED) == HIGH) {
      if (!switchOn) {
         switchOn = true;
         Serial.println("Switch ON");
      }
   } else {
      if (switchOn) {
         switchOn = false;
         Serial.println("Switch OFF");
      }
   }
   delay(10);
}

ESP32

The setup is almost identical to that of the Arduino, except that a different digital input is selected.

Circuit diagram for connecting a reed switch with the ESP32
Fig.: Circuit diagram for connecting a reed switch with the ESP32
#define PIN_REED 19

void setup() {
   pinMode(PIN_REED, INPUT);
   Serial.begin(9600);
}

void loop() {
   static bool switchOn = false;

   if (digitalRead(PIN_REED) == HIGH) {
      if (!switchOn) {
         switchOn = true;
         Serial.println("Switch ON");
      }
   } else {
      if (switchOn) {
         switchOn = false;
         Serial.println("Switch OFF");
      }
   }
   delay(10);
}

Further information

Last edited by Christian Grieger on 2025-05-12
X
  1. [top]
  2. Applications
  3. Features/Specifications
  4. Used Components
  5. Setup & Programming
  6. Further information