Interfacing Reed Switch with Arduino

Reed Switch

A Reed Switch is an electromechanical switch that opens or closes its contacts when exposed to a magnetic field. It is widely used in security systems, door sensors, and position detection applications due to its simplicity and reliability.

Working Principle of Reed Switch

The Reed Switch consists of two thin metal reeds inside a sealed glass tube. When a magnet comes close, the reeds either make or break contact depending on the switch type (normally open or normally closed), allowing current to flow or stop.

Types of Reed Switches

Normally Open (NO) Reed Switch

  • No connection when magnet is absent.
  • Magnet comes close, contacts close.
  • Circuit becomes complete, and current flows.

Normally Closed (NC) Reed Switch

  • Circuit is closed in default state.
  • Magnet approaches, contacts open.
  • Current flow stops when magnet is near.

Requirements

1. Arduino Board

2. Reed Switch (Module or raw)

3. Pull-up Resistor (10K if raw switch)

4. Jumper Wires

Pin Configuration of Reed Switch

Reed Switch Module

  • VCC: Connect to 5V on Arduino (if module includes pull-up).
  • GND: Connect to GND on Arduino.
  • OUT: Connect to a digital pin to read the switch state.

Raw Reed Switch

  • Connect one leg to 5V through a pull-up resistor.
  • Connect the other leg to a digital input pin.
  • Monitor the voltage drop when the switch activates.

Wiring the Reed Switch to Arduino

To connect a Reed Switch to Arduino, connect one terminal to GND and the other to a digital input pin with an internal or external pull-up resistor. When a magnet approaches, the switch closes, and the pin reads LOW. When the magnet moves away, the pin returns to HIGH.

Algorithm

  1. Initialize Components

    • Connect the Reed Switch to a digital pin and GND.
    • Use a pull-up resistor if necessary to ensure stable input readings.
  2. Write the Code

    • Set the digital pin as INPUT in the setup() function.
    • Use digitalRead() in the loop() function to detect state changes.
    • Execute a task (e.g., print message) when state changes.
  3. Detect Magnetic Field

    • Bring a magnet close to the switch.
    • Check for LOW or HIGH readings depending on wiring.
    • Trigger an action like LED blink or buzzer alert.
  4. Test the Setup

    • Upload code to the Arduino.
    • Move a magnet near and away from the switch.
    • Observe the readings and response in the serial monitor or output device.
1const int reedPin = 2;
2
3void setup() {
4  pinMode(reedPin, INPUT);
5  Serial.begin(9600);
6}
7
8void loop() {
9  int reedState = digitalRead(reedPin);
10  
11  if (reedState == HIGH) {
12    Serial.println("Reed Switch: CLOSED (Magnet Detected)");
13  } else {
14    Serial.println("Reed Switch: OPEN");
15  }
16
17  delay(500);
18}
19

Applications of Reed Switches

  • Door and window sensors in security systems
  • Magnetic position detection
  • Counting the number of wheel revolutions
  • Smart home automation triggers
  • Bicycle speedometers
  • Industrial machine monitoring

Conclusion

Interfacing a Reed Switch with Arduino is a straightforward way to detect magnetic fields and trigger actions. Whether you're building a security system, smart appliance, or automation project, Reed Switches offer a low-cost and reliable solution.