Buy from US Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES ここでご購入を!

I. Objective
II. Parts and Devices
III. Hardware Installation
IV. Circuit Connection
V. Software Installation


In this lesson, we use Python to program our Raspberry Pi robot car to automatically drive along a black line in white ground. We will use five IR tracking sensors to detect the line.

You will learn how Python read digital data from GPIO pins.


No. Picture Device Qty. Accessories Link
1 Tracking sensor module 1 M2.5 Plastic Screw x 2
M2.5 Plastic Nut x2
M2.5 Plastic Pillar x 2
Click here to buy
2 7pin 25 cm Female to Female Cable 1 Click here to buy
3 Philips screwdriver 1 Click here to buy


Step 1: You must complete Lesson 1 basic framework

Step 2: Install tracking sensor modules under lower car chassis with 2pcs M2.5 plastic screws, M2.5 plastic pillars and M2.5 plastic nuts.


Step 1: Connect GND-VCC pin of tracking sensor module to OSOYOO PWM HAT with 7pin 25 cm female to female cable, as the following photo shows (Remember : DO NOT remove any existing wires installed in Lesson 1) :

Step 2: Adjust the sensitivity of tracking sensor modules.

Turn on the car, and prepare a black track line on white ground and turn on the car.

Put the car on the black track and white ground repeatedly to adjust the sensitivity of the tracking module.

Please adjust the potentiometer on the tracking sensor and make sure the corresponding indicator LED will be on when the tracking sensor is over black, and the corresponding indicator LED will be off when the tracking sensor is over white.


Step 1: Make sure you have installed rpi.gpio, adafruit-pca9685 library and enable I2C in lesson 1.

Step 2: Turn on the robot car, then download the python code by typing the following command in your Raspberry Pi terminal:

wget http://osoyoo.com/driver/picar/picar-line-tracking.py

Step 3. Put the car on the black track line, then run the line tracking python program (ATTENTION: please select a correct command according to your Pi board),

If you are using Python 2 in Raspberry Pi 3, type:

python picar-line-tracking.py

If you are using Python 3 in Raspberry Pi 4/3A+, type:

python3 picar-line-tracking.py

Your car will move along the black track line.