Reed Switch Module(KY-025)
A switch module that operates magnetically.
Specifications
- Operating Voltage: 3.3V ~ 5V
- Note: Although it has an analog output terminal, it only outputs 0 or 1023.
Example Hardware Used
- Arduino Board
- Jumper Cables
- LED (5mm)
- Reed Switch Module
Connection
Reed Switch | LED | Arduino | ||
GND | - | GND | ||
+ | D8 | |||
+ | 5V | |||
DO | D7 |
Example Code
This code turns on an LED depending on the state of the reed switch.
int reed = 7;
int led = 8;
void setup() {
pinMode(reed, INPUT);
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
}
void loop() {
if (digitalRead(reed) == HIGH) {
digitalWrite(led, HIGH);
} else {
digitalWrite(led, LOW);
}
}