KY-025 Reed Switch Module

View on Amazon
Overview
About KY-025 Reed Switch Module
The KY-025 Reed Switch Module is a magnetic sensor that detects the presence of a magnetic field. It features both analog and digital outputs: the analog output provides a voltage corresponding to the magnetic field strength, while the digital output activates when the magnetic field exceeds a user-defined threshold, adjustable via an onboard potentiometer. This module is commonly used in applications such as proximity sensing, position detection, and security systems.
Get Your KY-025
Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
KY-025 Specifications
Complete technical specification details for KY-025 Reed Switch Module
📊 Technical Parameters
KY-025 Pinout
The **KY-025** is a 4-pin reed switch module with dual outputs:
Visual Pinout Diagram

Pin Types
Quick Tips
**Interface**: Dual output (analog + digital with comparator),🧲 **Sensor**: Large reed switch (sealed glass tube with ferromagnetic contacts),📊 **Analog Output**: Continuous voltage level reading
**Digital Output**: Threshold-based trigger (adjustable via potentiometer),⚡ **Power**: 3.3V or 5V operation
**Range**: Typically 10-30mm detection distance (depends on magnet strength),🎯 **Applications**: Door/window sensors, security systems, proximity detection, position sensing
Pin Descriptions
| Pin Name | Type | Description | Notes |
|---|---|---|---|
1 GND | Power | Ground connection | |
2 +V | Power | Power supply | 3.3V or 5V |
3 D0 | Communication | Digital output | HIGH when magnetic field detected |
4 A0 | Communication | Analog output | Voltage reading of reed switch state |
Wiring KY-025 to ESP32
To interface the **KY-025** with an **ESP32** for magnetic detection:
Visual Wiring Diagram

Connection Status
Protocol
Pin Connections
| KY-025 Pin | Connection | ESP32 Pin | Description |
|---|---|---|---|
1 GND Required | GND | Ground | |
2 +V Required | 3.3V or 5V | Power supply | |
3 D0 Optional | GPIO17 | Digital input (any GPIO) | |
4 A0 Optional | GPIO36 | Analog input (ADC pin) |
**Digital Mode**: Use D0 for simple binary detection (magnet present/absent)
**Analog Mode**: Use A0 for continuous monitoring with adjustable sensitivity
**ADC Pins**: Use GPIO32-39 for analog input on ESP32
**Voltage**: 3.3V recommended for ESP32 ADC compatibility
**Adjustment**: Turn onboard potentiometer to set digital trigger threshold
**Reed Switch**: Binary sensor (open/closed) responding to magnetic fields
**LED Indicator**: Onboard LED shows detection status
**Comparison**: Larger reed switch than KY-021, potentially greater detection range
KY-025 Troubleshooting
Common issues and solutions to help you get your sensor working
Common Issues
Issue: The sensor does not provide any output when exposed to a magnetic field.
Solutions:
- Verify all connections are secure and correctly placed.
- Ensure the module is receiving the appropriate voltage (3.3V or 5V).
- Adjust the potentiometer to set the correct sensitivity threshold.
- Test the sensor with a known magnetic source to confirm functionality.
Issue: The analog output fluctuates without any change in the magnetic field.
Solutions:
- Check for electromagnetic interference from nearby devices.
- Ensure that the power supply is stable and free from noise.
- Use shielded cables for analog signal transmission if necessary.
Debugging Tips
Use the Serial Monitor to check for error messages and verify the sensor's output. Add debug prints in your code to track the sensor's state.
Use a multimeter to verify voltage levels and check for continuity in your connections. Ensure the power supply is stable and within the sensor's requirements.
Additional Resources
KY-025 Programming Examples
Ready-to-use code examples for different platforms and frameworks
// Declaration and initialization of the input pins
int analog_input = A0; // Analog output of the sensor
int digital_input = 3; // Digital output of the sensor
void setup() {
pinMode(analog_input, INPUT);
pinMode(digital_input, INPUT);
Serial.begin(9600); // Serial output with 9600 bps
Serial.println("KY-025 Magnetic field detection");
}
void loop() {
float analog_value;
int digital_value;
// Current values are read out, converted to the voltage value...
analog_value = analogRead(analog_input) * (5.0 / 1023.0);
digital_value = digitalRead(digital_input);
//... and printed at this point
Serial.print("Analog voltage value: ");
Serial.print(analog_value, 4);
Serial.print(" V, Threshold value: ");
if (digital_value == 1) {
Serial.println("reached");
} else {
Serial.println("not reached");
}
Serial.println("-------------------------------");
delay(1000);
}This Arduino code reads the analog voltage from the KY-025 sensor's analog output and checks the digital output to determine if the magnetic field strength has surpassed the set threshold. The results are printed to the serial monitor every second.
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/adc.h"
#include "driver/gpio.h"
#define REED_SENSOR_ANALOG_PIN ADC1_CHANNEL_0 // GPIO36
#define REED_SENSOR_DIGITAL_PIN GPIO_NUM_17
void app_main(void) {
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(REED_SENSOR_ANALOG_PIN, ADC_ATTEN_DB_11);
gpio_set_direction(REED_SENSOR_DIGITAL_PIN, GPIO_MODE_INPUT);
printf("KY-025 Magnetic Field Detection\n");
while (1) {
int analog_value = adc1_get_raw(REED_SENSOR_ANALOG_PIN);
int digital_value = gpio_get_level(REED_SENSOR_DIGITAL_PIN);
printf("Analog Value: %d, Digital Threshold: %s\n", analog_value, digital_value ? "Reached" : "Not Reached");
vTaskDelay(pdMS_TO_TICKS(1000));
}
}This ESP-IDF code reads the analog value from the KY-025 sensor using ADC on GPIO36 and monitors the digital output on GPIO17 to determine if the magnetic field threshold is exceeded. The results are printed every second.
sensor:
- platform: adc
pin: GPIO36
name: "KY-025 Magnetic Field Strength"
update_interval: 1s
binary_sensor:
- platform: gpio
pin:
number: GPIO17
mode: INPUT_PULLUP
name: "KY-025 Magnetic Threshold Trigger"This ESPHome configuration reads the KY-025 sensor's analog output on GPIO36 and detects the threshold trigger using GPIO17 as a binary sensor. Updates are logged every second.
platformio.ini
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduinomain.cpp
#include <Arduino.h>
#define REED_SENSOR_ANALOG_PIN A0
#define REED_SENSOR_DIGITAL_PIN 17
void setup() {
pinMode(REED_SENSOR_DIGITAL_PIN, INPUT);
Serial.begin(115200);
Serial.println("KY-025 Magnetic Sensor Test");
}
void loop() {
int analog_value = analogRead(REED_SENSOR_ANALOG_PIN);
int digital_value = digitalRead(REED_SENSOR_DIGITAL_PIN);
Serial.printf("Analog: %d, Digital: %s\n", analog_value, digital_value ? "Threshold Reached" : "Not Reached");
delay(1000);
}This PlatformIO code reads the KY-025 sensor's analog output and monitors the digital threshold trigger. The values are printed every second.
import machine
import time
REED_SENSOR_ANALOG_PIN = machine.ADC(machine.Pin(36))
REED_SENSOR_ANALOG_PIN.atten(machine.ADC.ATTN_11DB)
REED_SENSOR_DIGITAL_PIN = machine.Pin(17, machine.Pin.IN, machine.Pin.PULL_UP)
while True:
analog_value = REED_SENSOR_ANALOG_PIN.read()
digital_value = REED_SENSOR_DIGITAL_PIN.value()
print("Analog:", analog_value, "Digital:", "Threshold Reached" if digital_value else "Not Reached")
time.sleep(1)This MicroPython script reads the KY-025 sensor's analog signal using ADC on GPIO36 and monitors the digital output on GPIO17. The readings are printed every second.
Wrapping Up KY-025
The ESP32 KY-025 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.
Best Practices
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Safety First
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.
Ready to Start Building?
Now that you have all the information you need, it's time to integrate the KY-025 into your ESP32 project and bring your ideas to life!








