Skip to main content

Case 11 PID line inspection


This course aims to enable students to learn and explore concepts such as judgment, branching, and-or-not in program design by making smart racing cars, and understand the working principle of line-following sensors and the basic principles of PID control. Through the practical operation, students will master the PID line inspection algorithm, cultivate logical thinking, problem-solving, and teamwork skills, and further improve the effect of the car's line inspection.

Teaching Objectives

Understand the basic concepts of judgment, branch, and or not in programming design, and be able to apply them to practical problems.

Understand the working principle of the line-following sensor and understand its application in line-following driving.

Grasp the basic principle of PID control algorithm, and be able to apply it to line-following driving.

Teaching Preparation

Cutebot Pro × 1

micro:bit × 1

Teaching process

Course Introduction

Hello everyone! Today we're going to continue our smart car production project, but this time we're going to improve the car's line-following effect. Have you noticed that the car may vibrate or turn frequently during the previous line patrol? In order to make the car run along the black line more smoothly, we will introduce a new concept - PID control. PID control can help us to perform more precise control based on the feedback signal from the sensor.

PID is the abbreviation of Proportional, Integral and Derivative, which are three commonly used adjustment parameters in control systems. By adjusting these parameters properly, we can make the car follow the line better and reduce the deviation.

Inquiry activities

How to use the line tracking sensor and PID control algorithm to make the car run smoothly along the black line? What are your thoughts and guesses?

Try to adjust the parameters in the PID control algorithm, and observe the effect on the car's line patrol effect.

Design and implement other line-following driving strategies, such as adjusting the driving speed according to the curvature of the line, etc.

Group discussions where students are encouraged to share their views and ideas

Sample Code


You can also download the program directly from the following web page.

Case Presentation

Summary and Reflection

Review course content to remind students of what knowledge and skills they have acquired.

Guide students to discuss the problems and difficulties they encountered in the production process, and how to solve these problems.

Encourage students to think about the application fields and future development of smart car production cases.

Outreach Activities

Let students try to improve the line-following function of the smart car so that it can cope with more complex lines and road conditions.

Guide students to design and implement more complex intersection processing algorithms, considering different traffic rules and situations.

Encourage students to think and discuss the practical application and future development prospects of smart racing cars in daily life.