The sensor module detects whether there is a light-reflecting or light-absorbing surface in front of the sensor. This is output at the digital output of the sensor. This behavior can be used, for example, in controllers such as those used in robots for autonomous line tracking. The sensitivity of the sensor can additionally be adjusted via the two controllers.

State 1: Line tracker is over a line [LED on the module: Off] [Sensor Signal: Digital On].

State 2: Line Tracker is outside a line [LED on the module: On] [Sensor Signal: Digital Off].

Pin assignment

Code example Arduino

Connection assignment Arduino

Arduino Sensor
5 V +V
Ground GND
Pin 10 Signal

The program reads the current state of the sensor pin and displays in the serial console whether the line tracker is currently on the line or not.

int Sensor  =  10;  // Declaration of the sensor input spin
   
void setup  ( )
{
  Serial.begin (9600)  ;  // Initialization  serial output
  pinMode (Sensor, INPUT)   ;  //  Initialization Sensorpin
}
  
//  The program reads the current state of the sensor pin and
// displays in the serial console whether the line tracker is currently 
// on the line or not
void loop  ( )
{
  bool val =  digitalRead (sensor)   ;  //  The current signal on the sensor is read
  
  if   (val  = =  HIGH )  //  If a signal has been detected, the LED is switched on.
  {
    Serial.println (“LineTracker is above the line”);
  }
  else
  {
    Serial.println (“Linetracker is out of line”);
  }
  Serial.println (“------------------------------------”)  ;
  delay (500)  ;  // Pasuse between the measurement of 500ms
}

Sample program Download

KY033-Arduino.zip

Code example Raspberry Pi

Pin assignment Raspberry Pi

Raspberry Pi Sensor
3,3 V +V
Fround GND
GPIO 24 [Pin 18] Signal

The program reads the current state of the sensor pin and displays in the serial console whether the line tracker is currently on the line 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_PIN = 24
GPIO.setup (GPIO_PIN, GPIO.IN , pull_up_down = GPIO.PUD_UP) 
 
# Pause between the output of the result is defined (in seconds) 
delayTime  =  0.5
 
print ("Sensor test [press CTRL+C to end the test]")
 
# Main program loop
try:
    while True:
        if GPIO.input(GPIO_PIN) == True:
            print ("LineTracker is above the line") 
        else:
            print ("Line tracker is out of line")
        print (" ---------------------------------------")
 
        # Reset + Delay
        time.sleep(delayTime)
 
# Clean up after the program is finished
except KeyboardInterrupt:
    GPIO.cleanup ()

Sample program Download

KY033-RPi.zip

To start with the command:

sudo python3 KY033-RPi.py

Code example Micro:Bit

Pin assignment Micro : Bit:

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

Sample program download

microbit-KY-033.zip