KY-021 Mini Magnetic Reed Switch Module – Magnetic Proximity Sensor for Arduino & ESP32
The KY-021 Mini Magnetic Reed Switch Module is a compact magnetic sensor designed to detect the presence or absence of a nearby magnet without physical contact.
Featuring a magnetically operated reed switch, the module uses two metal contacts sealed inside a glass capsule. When a suitable magnetic field approaches the sensor, the contacts close, producing a change in the digital output signal.
The KY-021 is ideal for Arduino, ESP32, Raspberry Pi, door and window detection, robotics, security systems, and DIY electronics projects.
Key Features
-
Model: KY-021
-
Sensor Type: Magnetic Reed Switch
-
Detection Method: Magnetic Field Proximity
-
Output Type: Digital (HIGH/LOW)
-
Switch Configuration: Normally Open (Typical)
-
Operating Voltage: Typically 3.3V–5V DC
-
Contact Type: Mechanical Reed Switch
- Non-Contact Magnetic Activation
-
3-Pin Interface: Signal (S), VCC (+), GND (-)
- Low Power Consumption
- Compact PCB Design
- Suitable for Arduino, ESP32, and Raspberry Pi Projects
Technical Specifications
| Parameter |
Specification |
| Model |
KY-021 |
| Product Type |
Mini Magnetic Reed Switch Module |
| Sensor Technology |
Magnetic Reed Switch |
| Detection Type |
Magnetic Proximity |
| Switch Configuration |
Normally Open (Typical) |
| Operating Voltage |
Typically 3.3V–5V DC |
| Output Type |
Digital |
| Output States |
HIGH / LOW |
| Switching Mechanism |
Magnetically Operated Metal Contacts |
| Number of Pins |
3 |
| Pin Configuration |
S / + / - |
| Detection Distance |
Depends on Magnet Strength and Orientation |
| Board Dimensions |
Approximately 18.5 × 15mm |
| Interface |
Digital GPIO |
| Contact Material |
Sealed Metallic Contacts |
Pin Configuration
| Pin |
Function |
| S |
Digital Signal Output |
| + |
Power Supply |
| - |
Ground |
Arduino Connection Example
| KY-021 |
Arduino Uno |
| S |
D3 |
| + |
5V |
| - |
GND |
The Arduino monitors the digital output to detect when a magnet approaches or moves away from the reed switch.
Arduino Example Code
const int reedPin = 3;
void setup() {
pinMode(reedPin, INPUT);
Serial.begin(9600);
}
void loop() {
int reedState = digitalRead(reedPin);
if (reedState == HIGH) {
Serial.println("Sensor HIGH");
} else {
Serial.println("Sensor LOW");
}
delay(100);
}
The HIGH and LOW states depend on the module's internal circuit and whether the reed switch contacts are open or closed.
Applications
- Door and Window Security Sensors
- Magnetic Proximity Detection
- Arduino and ESP32 Projects
- Raspberry Pi GPIO Input
- Robotics and Automation
- Magnetic Position Detection
- Smart Home Systems
- Alarm and Security Systems
- Object Counting with Magnets
- Educational STEM Projects
- DIY Electronics and Prototyping
Important Notes
-
The KY-021 is a magnetic reed switch sensor, not a Hall effect sensor.
- It uses mechanical contacts that open or close in response to a magnetic field.
- The module typically contains a normally open reed switch that closes when a suitable magnet approaches.
- Detection distance depends on the magnet's strength, orientation, and proximity.
- The sensor does not measure magnetic field strength or provide an analog output.
- Mechanical contact bounce may occur during switching. Software debouncing is recommended when accurate event counting is required.
- The glass reed switch capsule is fragile and should be handled carefully.
-
For ESP32 and Raspberry Pi, ensure the output voltage does not exceed 3.3V.
- Verify the supplied module's pin configuration and pull-up or pull-down arrangement before connecting it to a microcontroller.
- The KY-021 is designed for low-voltage signal detection, not direct switching of high-power electrical loads.
Package Includes
1 × KY-021 Mini Magnetic Reed Switch Module