Skip to main content

Sugar - Infrared Patrolling


The module is able to emit and receive infrared light at a close distance, and it implements the function of black line patrol or obstacle detection at an ultra-close distance through the principle of white area reflecting light while black area absorbing light. The digital level will change after the trigger. image.png


Size24 x 24 x 16 mm
Weight5 g
SignalDigital input (with blue indicator light)
1 (blue light off):
- Black line detected
- Reflectance of infrared light is too weak to be detected

0(blue light on)
-  Within detection range and no black line is detected
Detection Range1~14mm

Usage on Microbit


Programming Platform

Microsoft MakeCode for micro:bit Use the Makecode programming platform

Add Sugar Plugin

image-20240311154521941 image.png Search for Sugar in the extensions and click on Add

Sensor Block - Feature Description

Serial NumberSensor Block DiagramSensor Block Function
1image-20240315163952648Read if the sensor detects a black line

Circuit connection


Microbit interfaceWire
Digital line tracking sensor.pngRGB light ringP0White PH2.0-3Pin interface wireuntitled.100.png

Case: Black wire detection



Connect the 3PIN terminal wire to P1 of Robotbit Edu. Turn on the Robotbit power supply and you can see the red light at the bottom of the LED module light up (indicating that the module is powered normally)



Effect Demonstration

When a black line is detected, the Future board screen displays black. When a white area is detected, the Future board screen displays white.

  • The working state of the line tracking sensor is fed back via the blue indicator light.
  • If the blue indicator light is always on regardless of whether a black line is detected, it may be because the program sets the pin to a continuous high level output. Don't worry, just follow the instructions and continue. ::: tracker.mp4

Using Kittenblock

Choose online running or offline uploading to run the program and view the effect

If you are not sure how to run online or upload offline, please refer to Quickstart ::: image-20240315164241812

Black Line Sensor Return Value


  • Return value 0:
    • Within the detection range and no black line is encountered
  • Return value 1:
    • A black line is detected beyond
    • The detection distance cannot reflect infrared
from future import *
from sugar import *
tracker = Tracker('P1')
screen.sync = 0
while True:
if tracker.value() == 1: