This sensor uses infrared light to detect obstacles. If the emitted infrared light hits an obstacle, it is reflected and detected by the photodiode. The distance that has to be reached for detection can be adjusted with the two controllers.

This behavior can be used, for example, in control systems such as those used by robots to stop autonomously in front of an obstacle.

State 1: There is no obstacle in front of the detector [LED on the module: Off] [Sensor Signal= Digital On]

State 2: Detector has detected obstacle [LED on module: On] [Sensor Signal= Digital Off]

This sensor also has an enable line. This line can be used to activate or deactivate the detection of the sensor. In the delivery state of the sensor, however, the enable line is deactivated and the sensor is therefore permanently active. If the functionality of the enable line is desired, the jumper EN (green in the picture) must be removed and a corresponding control signal must be applied to the enable pin.

Please note: The sensor is additionally equipped with two adjustable controllers. Via these the measurable distance as well as the sensitivity of the sensor can be adjusted.

Pin assignment

Code example Arduino

Connection assignment Arduino

Arduino Sensor
- Enable
5 V +V
Ground GND
Pin 10 Signal

The program reads the current state of the sensor pins and displays in the serial console whether the obstacle detector is currently in front of an obstacle or not.

int Led  =  13;// Declaration of the LED output spin
int Sensor  =  10;  // Declaration of the sensor input spin
int  val;  //  Temporary  Variable
void setup  ( )
  pinMode (Led, OUTPUT);  // Initialization output spin
  pinMode (Sensor, INPUT);  //  Initialization sensor pin
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);
    digitalWrite (Led, HIGH);

Sample program download

Code example Raspberry Pi

Pin assignment Raspberry Pi

Raspberry Pi Sensor
- Enable
3,3 V +V
Ground GND
GPIO 24 [Pin 18] Signal

The program reads the current status of the sensor pin and outputs in the serial console whether the obstacle detector is currently in front of an obstacle or not.

#Modules required are imported and set up
import RPi. GPIO  as  GPIO
import time
GPIO.setmode (GPIO.BCM) 
# Here the input pin to which the sensor is connected is declared.
GPIO.setup (GPIO_PIN, GPIO.IN , pull_up_down = GPIO.PUD_UP) 
# Pause between output is defined (in seconds) 
delayTime  =  0.5
print ("Sensor test [push CTRL+C to stop the test]") 
# Main program loop
    while True:
        if GPIO.input(GPIO_PIN) == True:
            print ("No obstacle") 
            print ("obstacle detected") 
        print ("---------------------------------------")
        # Reset + Delay
        time.sleep (delayTime) 
# Tidying up after the program has been terminated
except KeyboardInterrupt:
    GPIO.cleanup ()

Sample program Download

[](/files/ files/ sensors/KY-032 /

To start with the command:

sudo python3

Code example Micro:Bit

Connection assignment Micro : Bit:

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

Sample program download