Sensor

👀 Infrared Sensor (Tracking Module)

📌 Description

The infrared tracking sensor helps the robot “see” lines or objects on the ground. It shines invisible light and checks how it bounces back. Dark surfaces absorb the light, while bright surfaces reflect it. This way, the sensor knows if it’s over a line or if something is in front.

🎯 Use

In our projects, tracking sensors are used to:

  • Follow a black line on the floor (line‑following robots).
  • Detect if an object is present or not.
  • Help the robot stay on track or avoid going off course.

👉 Think of the tracking sensor as the robot’s guide dog — it helps the robot stay on the path.

Module parameter

Pin name Description
G GND (Power Input Negative)
V VCC (Power Input Cathode)
S Digital signal pins
A Analog signal pins
  • Supply voltage: 3.3V/5V

  • Connection: 2.54mm pin header

  • Installation method: double screw fixing


🖥️ Code Explanation

import machine

pin26 = machine.Pin(26, machine.Pin.IN)   # Sensor connected to pin 26

while True:
    if pin26.value() == 1:                # If sensor sees no object/line
        print('No object detected')       # Print message
    else:                                 # If sensor sees something
        print('Object detected')          # Print message

Step by Step

  1. import machine → Brings in the tools to control pins.
  2. pin26 = machine.Pin(26, machine.Pin.IN) → Pin 26 is set as input to read the sensor’s signal.
  3. while True: → Loop that repeats forever.
  4. if pin26.value() == 1: → Checks if the sensor does not detect anything.
  5. print('No object detected') → Shows a message on the computer screen.
  6. else: → If the sensor detects something…
  7. print('Object detected') → Shows a message that an object is present.

👉 Together, this program makes the sensor report whether it sees an object or not.


✅ Conclusion of the Test

  • If the computer prints “Object detected” when something is placed in front of the sensor, and “No object detected” when nothing is there, the program is working correctly.
  • This test shows how the robot can read sensor input and communicate results.
  • Later, instead of just printing messages, the robot could use this sensor to follow lines, stop when something is in the way, or change direction.

On this page