A reed switch is an electromechanical device that operates when exposed to a magnetic field. It consists of two ferromagnetic metal contacts (reeds) in a hermetically sealed glass envelope. The contacts are normally open and close when a magnetic field is applied. Reed switches are used in various applications such as proximity sensing, security systems, and switching circuits.
Pin Number | Description |
---|---|
1 | Reed contact 1 (NC) |
2 | Reed contact 2 (NO) |
Note: NC (Normally Closed), NO (Normally Open)
// Example code for using a reed switch with an Arduino UNO
const int reedPin = 2; // Reed switch connected to digital pin 2
const int ledPin = 13; // Onboard LED connected to digital pin 13
void setup() {
pinMode(reedPin, INPUT_PULLUP); // Initialize reed switch pin as input with internal pull-up
pinMode(ledPin, OUTPUT); // Initialize LED pin as an output
}
void loop() {
if (digitalRead(reedPin) == LOW) { // Check if reed switch is closed by magnet
digitalWrite(ledPin, HIGH); // Turn on LED
} else {
digitalWrite(ledPin, LOW); // Turn off LED
}
}
Note: The internal pull-up resistor is used to ensure a stable state when the switch is open.
Q: Can I use a reed switch with AC voltage? A: Yes, but ensure the specifications are within the limits for AC voltage and current.
Q: How can I extend the life of my reed switch? A: Use contact protection circuits, avoid excessive force on the glass envelope, and select a switch with a higher rating than your application requires.
Q: Is there a polarity to a reed switch? A: No, reed switches do not have polarity and can be connected in any direction.