Reed Switch Module Tutorial: Magnetic Detection, Contact Behavior, and Arduino Usage

Advanced Tutorial Views: 1908

This tutorial is a comprehensive, practical guide to the Reed Switch Magnetic Sensor Module (Leobot Product #202). It explains how reed switches work internally, how this module presents the signal electrically, how to wire and debounce it correctly, and how to use it reliably for position sensing, door/window detection, rotation counting, and limit-switch applications.

Reed Switch Module Tutorial: Magnetic Detection, Contact Behavior, and Arduino Usage

This tutorial is a comprehensive, practical guide to the Reed Switch Magnetic Sensor Module (Leobot Product #202). It explains how reed switches work internally, how this module presents the signal electrically, how to wire and debounce it correctly, and how to use it reliably for position sensing, door/window detection, rotation counting, and limit-switch applications.

Tutorial Beginner ? Intermediate Magnetic Sensors Reed Switch Digital Inputs Arduino Automation
What this module is: A magnetic sensing module built around a reed switch. When a magnetic field is brought near the switch, the internal contacts close (or open, depending on type), producing a clean digital signal suitable for microcontroller inputs.
Important characteristic: A reed switch is a mechanical contact. Even though it is sealed in glass, it still exhibits contact bounce and must be debounced in software (or hardware) for reliable digital logic.

1) What a reed switch module does

A reed switch module detects the presence (or absence) of a magnetic field. When a magnet comes close enough, the reed switch changes state, producing a digital signal.

Typical uses include:

  • Door or window open/closed detection
  • End-stop or limit switch sensing
  • Rotation counting with a magnet on a wheel or shaft
  • Tamper or enclosure detection

2) How a reed switch works internally

A reed switch consists of two thin ferromagnetic metal reeds sealed inside a glass tube. In the absence of a magnetic field, the reeds are separated.

  • Magnet near ? reeds magnetize and attract ? contacts close
  • Magnet removed ? reeds demagnetize ? contacts open
Key insight: The switch is actuated by magnetic field strength, not by direct contact. This allows completely contactless sensing with excellent electrical isolation.

3) Module overview and signal conditioning

The reed switch module typically includes:

  • A normally-open reed switch
  • A pull-up resistor (on the board)
  • An indicator LED (shows switch state)
  • Simple header pins for easy connection

When the reed switch closes, the module output changes state and the LED turns on or off accordingly.


4) Pinout and electrical characteristics

Pin Label Description
1 VCC Supply voltage (3.3V – 5V)
2 GND Ground
3 OUT Digital output (HIGH/LOW)
  • Logic-level compatible with most microcontrollers
  • OUT is typically pulled HIGH and goes LOW when magnet is detected (verify on your module)

5) Magnet type, polarity, and distance

Reed switches respond to magnetic field strength, not polarity.

  • Small neodymium magnets work best
  • Detection distance is usually a few millimeters to a few centimeters
  • Stronger magnets increase range but can cause sticking if too close
Avoid overdriving: Very strong magnets held directly against the switch for long periods can magnetize the reeds and cause them to stick closed.

6) Wiring to Arduino


Reed Module VCC ? Arduino 5V (or 3.3V)
Reed Module GND ? Arduino GND
Reed Module OUT ? Arduino D2
    

7) Arduino Example 1: Basic magnetic detection


/*
  Reed Switch Module - Basic Detection
  Product #202
*/

const int REED_PIN = 2;

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

void loop() {
  int state = digitalRead(REED_PIN);

  if (state == LOW) {
    Serial.println("Magnet detected");
  } else {
    Serial.println("No magnet");
  }

  delay(200);
}
    

8) Arduino Example 2: Debounced detection

Because a reed switch is mechanical, it can bounce when opening or closing. This example implements a simple software debounce.


/*
  Reed Switch Module - Debounced Input
*/

const int REED_PIN = 2;
const unsigned long DEBOUNCE_MS = 30;

int lastStable = HIGH;
int lastReading = HIGH;
unsigned long lastChangeTime = 0;

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

void loop() {
  int reading = digitalRead(REED_PIN);
  unsigned long now = millis();

  if (reading != lastReading) {
    lastChangeTime = now;
    lastReading = reading;
  }

  if (now - lastChangeTime > DEBOUNCE_MS) {
    if (lastStable != reading) {
      lastStable = reading;
      Serial.println(lastStable == LOW ? "Magnet ON" : "Magnet OFF");
    }
  }
}
    

9) Arduino Example 3: Rotation or event counting

By placing a magnet on a rotating wheel or shaft, the reed switch can count revolutions or events.


/*
  Reed Switch Module - Event Counter
*/

const int REED_PIN = 2;
volatile unsigned long count = 0;

void onTrigger() {
  count++;
}

void setup() {
  pinMode(REED_PIN, INPUT);
  attachInterrupt(digitalPinToInterrupt(REED_PIN), onTrigger, FALLING);
  Serial.begin(9600);
}

void loop() {
  Serial.print("Count: ");
  Serial.println(count);
  delay(1000);
}
    
Note: For high-speed rotation, a reed switch may not be suitable. Use a Hall sensor or optical encoder instead.

10) Typical real-world applications

  • Door/window alarm systems
  • End-stop detection in DIY machines
  • Water or gas meter pulse sensing
  • Simple speed or usage counters

11) Mounting and alignment guidelines

  • Align magnet movement perpendicular to the reed switch length
  • Secure both magnet and sensor to avoid vibration
  • Test detection distance before final installation
  • Keep away from strong stray magnetic fields

12) Troubleshooting

Always ON or always OFF

  • Magnet too close or too far
  • Incorrect wiring
  • Reed contacts stuck due to strong magnet exposure

False triggering

  • Mechanical vibration
  • Long wires acting as antennas
  • No debounce logic

13) Quick checklist


Reed Switch Module (#202) Checklist
----------------------------------
? Power with 3.3V or 5V
? Verify output polarity (LOW or HIGH when magnet present)
? Use debounce logic for reliable switching
? Choose correct magnet strength and distance
? Avoid strong magnets held permanently against the switch
? Use interrupts only for low-speed events
? Mount securely to avoid vibration
    

Products that this may apply to