KY-010 Photo Interrupter Module

View on Amazon
Overview
About KY-010 Photo Interrupter Module
The KY-010 Photo Interrupter Module is a digital sensor that detects the presence or absence of an object within its slot. It consists of an infrared emitter and receiver facing each other, forming a light barrier. When an object passes through the slot, it interrupts the infrared beam, causing a change in the output signal. This module operates at a voltage range of 3.3V to 5V, making it compatible with various microcontrollers such as Arduino and ESP32. Itβs commonly used in applications like object counting, edge detection, and motor speed measurement.
Get Your KY-010
π‘ Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
KY-010 Specifications
Complete technical specification details for KY-010 Photo Interrupter Module
π Technical Parameters
KY-010 Pinout
The **KY-010** is a 3-pin photo interrupter (optical light barrier) module:
Visual Pinout Diagram

Pin Types
Quick Tips
**Interface**: Digital output (light barrier detection),π‘ **Sensor**: Infrared emitter/receiver pair with slot
**Detection**: Beam interruption changes output state,β‘ **Power**: 3.3V or 5V operation
**Slot**: Object must pass through optical slot,π― **Applications**: Object counting, speed measurement, edge detection, position sensing
Pin Descriptions
| Pin Name | Type | Description | Notes |
|---|---|---|---|
1 Pin (-) | Power | Ground connection | |
2 Pin (+) | Power | Power supply | 3.3V or 5V |
3 Pin (S) | Communication | Digital signal output | Changes state when beam interrupted |
Wiring KY-010 to ESP32
To interface the **KY-010** with an **ESP32** for optical interruption detection:
Visual Wiring Diagram

Connection Status
Protocol
Pin Connections
| KY-010 Pin | Connection | ESP32 Pin | Description |
|---|---|---|---|
1 Pin (-) Required | GND | Ground | |
2 Pin (+) Required | 3.3V or 5V | Power supply | |
3 Pin (S) Required | GPIO15 | Digital input (any GPIO) |
**GPIO Selection**: Any digital GPIO pin works, GPIO15 is just an example
**Voltage**: Use 3.3V for ESP32 compatibility
**Object Detection**: Output changes when object blocks IR beam in slot
**Counting**: Ideal for counting objects on conveyor or rotating disk
KY-010 Troubleshooting
Common issues and solutions to help you get your sensor working
Common Issues
Issue: The module does not detect any object passing through the slot.
Solutions:
- Ensure the module is properly powered with the correct voltage.
- Verify that the signal pin is correctly connected to the microcontroller's GPIO pin.
- Check for any obstructions or debris within the slot that could affect detection.
Issue: The module outputs signals without any object present.
Solutions:
- Ensure there is no ambient infrared light interfering with the sensor.
- Check for loose connections or unstable power supply.
- Verify that the microcontroller's input pin is properly configured with pull-up or pull-down resistors as needed.
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-010 Programming Examples
Ready-to-use code examples for different platforms and frameworks
int sensorPin = 10; // Sensor connected to digital pin 10
int ledPin = 13; // LED connected to digital pin 13
int sensorValue = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH); // Enable internal pull-up resistor
Serial.begin(9600);
}
void loop() {
sensorValue = digitalRead(sensorPin);
if (sensorValue == HIGH) {
digitalWrite(ledPin, HIGH); // Turn on LED
Serial.println("Object detected");
} else {
digitalWrite(ledPin, LOW); // Turn off LED
}
delay(100);
}This Arduino code sets up the KY-010 sensor on digital pin 10 and an LED on pin 13. The internal pull-up resistor is enabled for the sensor pin. When an object interrupts the sensor's beam, the LED lights up, and a message is printed to the serial monitor.
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#define SENSOR_PIN GPIO_NUM_15
#define LED_PIN GPIO_NUM_2
void app_main(void) {
// Configure sensor pin as input with pull-up resistor
gpio_config_t sensor_io_conf = {
.pin_bit_mask = (1ULL << SENSOR_PIN),
.mode = GPIO_MODE_INPUT,
.pull_up_en = GPIO_PULLUP_ENABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE
};
gpio_config(&sensor_io_conf);
// Configure LED pin as output
gpio_config_t led_io_conf = {
.pin_bit_mask = (1ULL << LED_PIN),
.mode = GPIO_MODE_OUTPUT,
.pull_up_en = GPIO_PULLUP_DISABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE
};
gpio_config(&led_io_conf);
printf("KY-010 Photo Interrupter Module Test\n");
while (1) {
int sensor_value = gpio_get_level(SENSOR_PIN);
if (sensor_value == 1) {
gpio_set_level(LED_PIN, 1); // Turn on LED
printf("Object detected\n");
} else {
gpio_set_level(LED_PIN, 0); // Turn off LED
}
vTaskDelay(pdMS_TO_TICKS(100));
}
}This ESP-IDF code configures the KY-010 Photo Interrupter Module on GPIO15 and an LED on GPIO2. The sensor pin is set up as an input with an internal pull-up resistor, while the LED pin is configured as an output. The main loop continuously checks if an object interrupts the infrared beam. If an object is detected, the LED turns on, and a message is printed to the console.
binary_sensor:
- platform: gpio
pin:
number: GPIO15
mode: INPUT_PULLUP
name: "KY-010 Object Detector"
filters:
- delayed_on: 10ms
- delayed_off: 10ms
on_press:
- then:
- lambda: |-
ESP_LOGD("sensor", "Object detected!");This ESPHome configuration sets up the KY-010 Photo Interrupter Module as a binary sensor on GPIO15 with an internal pull-up resistor. It applies filtering to debounce false triggers and logs when an object is detected.
platformio.ini
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduinomain.cpp
#include <Arduino.h>
#define SENSOR_PIN 15
#define LED_PIN 2
void setup() {
pinMode(SENSOR_PIN, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
Serial.begin(115200);
Serial.println("KY-010 Photo Interrupter Module Test");
}
void loop() {
if (digitalRead(SENSOR_PIN) == HIGH) {
Serial.println("Object detected");
digitalWrite(LED_PIN, HIGH);
} else {
digitalWrite(LED_PIN, LOW);
}
delay(100);
}This PlatformIO code configures the KY-010 sensor on GPIO15 and an LED on GPIO2. When an object interrupts the infrared beam, the LED turns on, and a message is printed to the serial monitor.
import machine
import time
SENSOR_PIN = machine.Pin(15, machine.Pin.IN, machine.Pin.PULL_UP)
LED_PIN = machine.Pin(2, machine.Pin.OUT)
while True:
if SENSOR_PIN.value() == 1:
print("Object detected")
LED_PIN.on()
else:
LED_PIN.off()
time.sleep(0.1)This MicroPython script configures the KY-010 Photo Interrupter Module on GPIO15 and an LED on GPIO2. When an object interrupts the sensor's beam, the LED turns on, and a message is printed to the console.
Wrapping Up KY-010
The ESP32 KY-010 Photo Interrupter 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-010 into your ESP32 project and bring your ideas to life!
Explore Alternative Sensors
Looking for alternatives to the KY-010? Check out these similar sensors that might fit your project needs.

KY-018 Photoresistor Module
The KY-018 is a photoresistor module that detects ambient light levels. It outputs an analog signal corresponding to the light intensity,...

KY-022 Infrared Receiver Module
The KY-022 is an infrared receiver module capable of detecting 38kHz IR signals. It's commonly used in projects requiring remote control...

KY-027 Magic Light Cup Module
The KY-027 is a motion detection module featuring a mercury tilt switch and an LED. It detects tilt or orientation changes and can be used...





