Introduction
This magnetic switch (reed switch) consists of two magnetic reeds (usually composed of iron and nickel) sealed in a plastic case. The two magnetic reeds are overlapped but there is a small gap between them. When a suitable external magnetic field comes within 2cm, the two magnetic reeds will contact and conduct, thereby sensing the change in the position of the object. This magnetic control switch has a compact structure and a small weight, which can be installed in a limited space, and is extremely suitable for using in miniaturized equipment. The switching elements of the reed switch are hermetically sealed in an inert gas atmosphere, so that they are never exposed to the external environment and feature a long service life. The switch can be widely used in door/window position limiting device, proximity switches, measuring instruments, automation/security/transportation equipment, smart homes, etc.
Features
- Compact structure and small weight
- Long service life
- Wide voltage operating range
Specification
- Operating Voltage: 0~100V
- Operating Principle: Magnetic sensor
- Output signal: switching value signal
- Size: 6x20x350 mm/0.24×0.79×13.78"
- Color: Black
Tutorial
Requirements
- Hardware
- DFRduino UNO R3 (or similar) x 1
- Magnetic Switch x 1
- Pluggable sensor adapter × 1
- M-M/F-M/F-F Jumper wires
Connection Diagram
Here we use the I/O9 and 13 ports of Arduino UNO for demonstration
Sample Code
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @licence The MIT License (MIT)
* @author [huyujie](yujie.hu@dfrobot.com)
* @version V1.0
* @date 2021-05-13
*/
int ledPin = 13;
int magnet_inputPin = 9;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(magnet_inputPin, INPUT);
}
void loop(){
int val = digitalRead(magnet_inputPin);
if (val == HIGH) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}
Expected Results
When the magnetic switch is close to the magnet, the LED of UNO 13 pin will light up. And the LED will light off when the magnetic switch moves away from the magnet.
FAQ
For any questions, advice or cool ideas to share, please visit the DFRobot Forum.