The sensor module detects whether there is a light-reflecting or light-absorbing surface in front of the sensor. What is currently the case, the module outputs at its digital output, as shown in the pictures below. The sensitivity (resulting minimum distance) of the sensor can be regulated with the controller.

This behavior can be used in controllers, such as those used in robots, in order to be able to follow a line autonomously.

Condition 1 : Line tracker is above a line (non-reflective surface) [LED on the module: Off] [Sensor Signal= Digital On]

Condition 2 : Line tracker is outside a line (reflective surface) [LED on module: One] [Sensor Signal= Digital Off]

Pin assignment

Code example Arduino

Connection assignment Arduino

Arduino Sensor
5V +V
Mass 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,3V +V
Mass 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.py

Code example Micro:Bit

Pin assignment Micro : Bit:

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

This is a MakeCode example for Micro: Bit which essentially does the same as the examples of the other two variants. However, this example is closer to the Raspberry Pi example than the Arduino example.

Sample program download

microbit-KY-033.zip