I.Objective
II.Parts and Devices
III.Hardware Installation
IV.Circuit Connection
V.Software Installation
VI.How to play

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



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.

If you are interested in C++ programming, this project has a C++ solution in following link:
https://osoyoo.com/2020/11/08/osoyoo-raspberry-pi-v2-0-car-lesson-2-line-tracking-c-language/



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 25cm Female to Female Cable 1 Click here to buy
3 Philips screwdriver 1 Click here to buy


Step 1: You must complete hardware and software installation in  Lesson 1 basic frame work

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



Step1: Connect GND-VCC pin of tracking sensor module to GND-5V of PCA9685 compatible module; connect IR1, IR2, IR3, IR4, IR5 pins to GPIO5, GPIO6,  GPIO13, GPIO19, GPIO26 of Raspberry pi with 7pin 25cm 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 and hold the car and adjust the potentiometer on the tracking sensor with Philips screwdriver until you get the best sensitivity status: the signal indicate LED light will turn on when sensor is above black track, and the signal LED will turn off when the sensor is above white ground



Download the python code by typing following command in your Raspberry Pi terminal:

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

Turn on the battery of your car and put the car on the black track line:
Now you can run the line tracking python program by typing following command in terminal,

python3 picar-line-tracking.py

Your car will move along the black track line.