ESP32 KY-021 Mini Magnetic Reed Switch Module Pinout, Wiring and more

KY-021 Mini Magnetic Reed Switch Module image

KY-021

Protocol: Digital

Overview

The KY-021 is a mini magnetic reed switch module that detects the presence of a magnetic field. It provides a digital signal output, making it suitable for applications like security systems, position sensors, and magnetic field detection projects.

About KY-021 Mini Magnetic Reed Switch Module

The KY-021 Mini Magnetic Reed Switch Module is designed to detect the presence of a magnetic field. It contains a reed switch that closes its contacts when exposed to a magnetic field, allowing current to flow through. This module operates at voltages between 3.3V and 5V, making it compatible with various microcontrollers like Arduino and ESP32. It’s commonly used in applications such as door and window sensors, position detection, and other projects requiring magnetic field detection.

Where to Buy KY-021 Mini Magnetic Reed Switch Module

KY-021 Mini Magnetic Reed Switch Module

Starting from

1$ per unit

Amazon com
Amazon.com Ships worldwide
View Price
Amazon de
Amazon.de Ships to EU
View Price
Aliexpress
AliExpress Best value
View Price

Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.

KY-021 Datasheet and Technical Specifications

Operating Voltage 3.3V - 5V
Output Type Digital
Dimensions 19 x 18.5 x 9 mm

KY-021 Pinout Diagram

The VCC pin is used to supply power to the sensor, and it typically requires 3.3V or 5V (refer to the datasheet for specific voltage requirements). The GND pin is the ground connection and must be connected to the ground of your ESP32.

  • Pin (-): Connects to ground (GND).
  • Pin (middle): Connects to VCC (3.3V to 5V).
  • Pin (S): Outputs the digital signal; connect to a digital input on your microcontroller.

KY-021 Wiring with ESP32

  • KY-021 Pin (-): Connect to ESP32 GND.
  • KY-021 Pin (middle): Connect to ESP32 3.3V.
  • KY-021 Pin (S): Connect to a digital GPIO pin on ESP32 (e.g., GPIO4).

KY-021 Troubleshooting Guide

Common Issues

❌ No Response from Sensor

⚠️ False Triggering

Debugging Tips

🔍 Serial Monitor

⚡ Voltage Checks

KY-021 Code Examples

Arduino Example

C++
🔧

ESP-IDF Example

C++
🏠

ESPHome Example

YAML
🛠️

PlatformIO Example

C++
🐍

MicroPython Example

Python

Conclusion

The ESP32 KY-021 Mini Magnetic Reed Switch Module is a powerful KY-0xx module sensor that offers excellent performance and reliability. With support for multiple development platforms including Arduino, ESP-IDF, ESPHome, PlatformIO, and MicroPython, it's a versatile choice for your IoT projects.

For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.

Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.