A Reed Switch is an electromechanical component that operates as an electrical switch when exposed to a magnetic field. It is composed of two ferromagnetic metal contacts (reeds) enclosed within a glass tube, which is filled with an inert gas to prevent corrosion and ensure a long operational life. The contacts are normally open and close when a magnetic field is applied, making the reed switch a useful component for sensing magnetic presence, counting, or as a safety interlock device.
Pin Number | Description |
---|---|
1 | Contact 1 (Reed 1) |
2 | Contact 2 (Reed 2) |
Note: The reed switch is a two-terminal device with no polarity, so the pin numbers are for identification purposes only.
Q: Can a reed switch be used to switch AC loads?
Q: How can I extend the life of a reed switch?
Q: Is there a polarity to be observed when connecting a reed switch?
Below is an example code snippet for using a reed switch with an Arduino UNO. The code will print a message to the Serial Monitor when the reed switch is activated by a magnet.
// Define the pin connected to the reed switch
const int reedPin = 2;
void setup() {
// Initialize the reedPin as an input
pinMode(reedPin, INPUT_PULLUP);
// Begin serial communication at 9600 baud rate
Serial.begin(9600);
}
void loop() {
// Read the state of the reed switch
int state = digitalRead(reedPin);
// Check if the reed switch is closed (magnet is in proximity)
if (state == LOW) {
// Print message to the Serial Monitor
Serial.println("Magnet detected!");
}
// Small delay to debounce and prevent multiple messages
delay(50);
}
Note: The INPUT_PULLUP
mode is used to enable the internal pull-up resistor, which ensures a default high state when the switch is open.