KY-039 Heartbeat Sensor Module
The KY-039 is a heartbeat sensor module that uses an infrared LED and a phototransistor to detect pulse signals. It provides an analog output corresponding to the heartbeat, making it suitable for health monitoring and related applications.

On this page
KY-039 pinout
The KY-039 is a 3-pin optical heartbeat/pulse sensor module:
| Pin | Type | Description | Notes |
|---|---|---|---|
| VCC | Power | Power supply | 3.3V or 5V |
| GND | Power | Ground connection | |
| S (Signal) | Communication | Analog output | Voltage varies with pulse/heartbeat |
Interface: Analog output (pulse waveform)
Sensor: IR LED + phototransistor for optical pulse detection
Detection: Measures blood flow variations in fingertip
Power: 3.3V or 5V operation
Output: Analog voltage waveform corresponding to heartbeat
Applications: Heart rate monitors, fitness trackers, health monitoring, biofeedback systems
Wiring the KY-039 to ESP32
To interface the KY-039 with an ESP32 for heartbeat detection:
| KY-039 pin | ESP32 pin | Purpose |
|---|---|---|
| VCC | 3.3V | Power supply |
| GND | GND | Ground |
| S (Signal) | GPIO34 | Analog input (ADC pin) |
Placement: Place finger between IR LED and phototransistor
ADC Pins: Use GPIO32-39 for analog input on ESP32
Voltage: 3.3V recommended for ESP32
Signal Processing: Requires filtering and peak detection in software
Pressure: Apply gentle, steady pressure for best readings
KY-039 code examples
KY-039 Arduino example
Copy#define SENSOR_PIN 34 // KY-039 signal pin (GPIO34 / ADC1_CH6, matches the wiring above)
void setup() {
Serial.begin(115200);
Serial.println("KY-039 Heartbeat Sensor Test");
}
void loop() {
int sensorValue = analogRead(SENSOR_PIN); // 0-4095 on the ESP32's 12-bit ADC
Serial.println(sensorValue);
delay(10);
}This Arduino code initializes the analog pin connected to the KY-039 sensor. It reads the analog value corresponding to the heartbeat signal and prints it to the serial monitor every 10 milliseconds. Users can observe the serial plotter to visualize the heartbeat waveform.
KY-039 ESP-IDF example
Copy#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/adc.h"
#define SENSOR_CHANNEL ADC1_CHANNEL_6 // GPIO34
void app_main(void) {
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(SENSOR_CHANNEL, ADC_ATTEN_DB_11);
printf("KY-039 Heartbeat Sensor Test\n");
while (1) {
int raw = adc1_get_raw(SENSOR_CHANNEL);
float voltage = raw * (3.3 / 4095.0);
printf("Analog Voltage: %.2f V\n", voltage);
vTaskDelay(pdMS_TO_TICKS(10));
}
}This ESP-IDF code configures GPIO34 as an analog input for the KY-039 heartbeat sensor. It reads the analog voltage corresponding to the heartbeat signal and prints it to the console every 10 milliseconds, allowing for real-time monitoring of the pulse waveform.
KY-039 ESPHome example
Copysensor:
- platform: adc
pin: GPIO34
name: "KY-039 Heartbeat Sensor"
update_interval: 10ms
filters:
- multiply: 3.3
- lambda: |-
return x * 1000; // Convert to millivoltsThis ESPHome configuration sets up the KY-039 sensor connected to GPIO34. It reads the analog value every 10 milliseconds, converts it to millivolts, and makes it available as a sensor named "KY-039 Heartbeat Sensor" for further processing or visualization.
KY-039 PlatformIO example
Copy[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino#include <Arduino.h>
#define SENSOR_PIN 34
void setup() {
Serial.begin(115200);
Serial.println("KY-039 Heartbeat Sensor Test");
}
void loop() {
int sensorValue = analogRead(SENSOR_PIN);
float voltage = sensorValue * (3.3 / 4095.0) * 1000; // Convert to millivolts
Serial.printf("Analog Voltage: %.2f mV\n", voltage);
delay(10);
}This PlatformIO code sets up GPIO34 as an analog input for the KY-039 heartbeat sensor. It continuously reads the sensor value, converts it to millivolts, and prints it to the serial monitor every 10 milliseconds to capture the heartbeat waveform.
KY-039 MicroPython example
Copyimport machine
import time
SENSOR_PIN = machine.ADC(machine.Pin(34))
SENSOR_PIN.atten(machine.ADC.ATTN_11DB)
while True:
sensor_value = SENSOR_PIN.read()
voltage = (sensor_value / 4095) * 3300 # Convert to millivolts
print("Analog Voltage:", voltage, "mV")
time.sleep(0.01)This MicroPython script configures GPIO34 as an ADC input for the KY-039 heartbeat sensor. It continuously reads the sensor value, converts it to millivolts, and prints the voltage every 10 milliseconds for real-time heartbeat monitoring.
KY-039 specifications
About the KY-039
The KY-039 works in transmission mode: an IR LED and a phototransistor face each other with a fingertip held between them, and as blood pumps through the tissue with each heartbeat it changes how much IR light makes it through to the phototransistor. That modulation riding on top of the transmitted light is the pulse signal, and by the module’s own documentation it’s a genuinely weak one - reliable readings depend on snug, consistent finger placement (taping the sensor to a fingertip helps) positioned over a decent-sized blood vessel, and on keeping stray ambient light, including flicker from 50/60 Hz mains-powered lighting, from reaching the phototransistor and swamping the real signal.
Getting from that raw analog output to an actual heart rate takes real signal processing in software - filtering out noise and detecting peaks - and even then this is a toy-grade optical pulse sensor with no calibration or certification behind it, not a medical-grade PPG part. It’s a fun way to visualize a heartbeat waveform or trigger something on a pulse, but nothing here should be trusted for actual health monitoring.
KY-039 troubleshooting
No Signal Detected
›
Issue: The sensor does not output any signal when a finger is placed between the IR LED and phototransistor.
Solutions:
- Ensure the module is properly powered with the correct voltage (3.3V or 5V).
- Verify all connections are secure and correctly wired.
- Make sure the finger is positioned correctly between the IR LED and phototransistor.
- Check for ambient light interference and consider shielding the sensor from external light sources.
Unstable or Noisy Readings
›
Issue: The sensor outputs fluctuating or noisy signals.
Solutions:
- Implement signal filtering in the software to smooth out the readings.
- Ensure the environment is free from electrical noise or interference.
- Check for any loose connections or faulty components on the module.
Where to buy the KY-039

Resources
Similar sensors




