• Arduino
  • Raspberry Pi
  • Raspberry Pi Pico
  • Micro:Bit

When the light barrier of the module is interrupted, the signal coming from the module itself is also interrupted.

Operating voltage 3,3 V - 5 V

Pin assignment

Code example Arduino

Pin assignment Arduino

Arduino Sensor
Pin 10 signal
5V +V
GND GND
Arduino Sensor
Pin 13 LED+
GND LED-

This is a sample program that lights up an LED when a signal is detected at the sensor. The modules KY-011, KY-016 or KY-029 can, for example, be used as LEDs, for example.

int Led = 13 ;// declaration of the LED output pin
int Sensor = 10 ;// Declaration of the sensor input pin
int val; // Temporary variable
  
void setup ()
{
  pinMode (Led, OUTPUT) ; // Initialize output pin
  pinMode (Sensor, INPUT) ; // Initialize sensor pin
  digitalWrite(Sensor, HIGH) ; // Activate internal pull-up resistor
}
  
void loop ()
{
  val = digitalRead (Sensor) ; // The current signal at the sensor is read out
  
  if (val == HIGH) // If a signal could be detected, the LED is switched on.
  {
    digitalWrite (Led, LOW);
  }
  else
  {
    digitalWrite (Led, HIGH);
  }
}

Sample program download

KY010-Arduino.zip

When the light barrier of the module is interrupted, the signal coming from the module itself is also interrupted.

Operating voltage 3,3 V - 5 V

Pin assignment

Code example Raspberry Pi

Pin assignment Raspberry Pi

Raspberry Pi Sensor
GPIO 24 [Pin 18] Signal
3.3 V [Pin 1] +V
GND [Pin 6] GND

This is a sample program that prints a console output when as signal is detected at the sensor.

from gpiozero import DigitalInputDevice
import time

# The input pin to which the sensor is connected is declared here.
# In addition, the PullUP resistor at the input is also deactivated
sensor = DigitalInputDevice(24, pull_up=False)

print("Sensor test [press CTRL+C to end the test]")

# This output function is executed when a signal is detected
def ausgabeFunktion():
    print("Signal recognized")

# When a signal is detected (rising signal edge), the output function is triggered
sensor.when_activated = ausgabeFunktion

# Main program loop
try:
    while True:
        time.sleep(1)

# Clean up after the program has been completed
except KeyboardInterrupt:
    print("Program was terminated by the user")

Sample program download

KY010-RPi.zip

To start with the command:

sudo python3 KY010-RPi.py

When the light barrier of the module is interrupted, the signal coming from the module itself is also interrupted.

Operating voltage 3,3 V - 5 V

Pin assignment

Codeexample Micro:Bit

Pin assignment Micro:Bit:

Micro:Bit Sensor
Pin 1 Signal
3 V +V
GND GND

This is a sample program that outputs text serially when a signal is detected at the sensor.

Sample program download

microbit-KY-010.zip

When the light barrier of the module is interrupted, the signal coming from the module itself is also interrupted.

Operating voltage 3,3 V - 5 V

Pin assignment

Code example Raspberry Pi Pico

Pin assignment Raspberry Pi Pico

Raspberry Pi Pico Sensor
GPIO18 Signal
3.3V +V
GND GND

This is a sample program that counts up and outputs serial text when a signal is detected at the sensor.

# Load libraries
from machine import Pin, Timer

# Initialization of GPIO as input
sensor = Pin(18, Pin.IN, Pin.PULL_DOWN)

# Create timer
timer = Timer()

# Set counter to 0
counter = 0

# Function: Count steps
def step(timer):
    global counter
    counter = counter + 1
    print(counter)

# Function: Barrier
def barrier(pin):
    # Debounce function: Set timer
    timer.init(mode=Timer.ONE_SHOT, period=100, callback=step)

# Initialization interrupt
sensor.irq(trigger=Pin.IRQ_FALLING, handler=barrier)

Example program download

KY010-Pico.zip