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.
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
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
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);
}
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