Line-Following Robot
Summary
Overview
Have your students read about autonomous (also called self-driving or driverless) cars in the news? How can you build a car or a robot that will stay on the road without a human driver? In this project, your students will find out by building a robot that can automatically follow a line around a homemade race course, while learning about the electromagnetic spectrum and electronic circuits.Learning Objectives
- Learn to assemble and troubleshoot an electronic circuit
- Observe how infrared radiation is reflected and absorbed by different materials
- Understand how a simple line-following robot works
NGSS Alignment
This lesson helps students prepare for these Next Generation Science Standards Performance Expectations:- MS-PS4-2. Develop and use a model to describe that waves are reflected, absorbed, or transmitted through various materials.
Science & Engineering Practices | Disciplinary Core Ideas | Crosscutting Concepts | |||
Science & Engineering Practices | Planning and Carrying out Investigations. Collect data to produce data to serve as the basis for evidence to answer scientific questions or test design solutions under a range of conditions. Analyzing and Interpreting Data. Analyze and interpret data to provide evidence for phenomena. |
Disciplinary Core Ideas | PS4.B: Electromagnetic Radiation. When light shines on an object, it is reflected, absorbed, or transmitted through the object, depending on the object's material and the frequency (color) of the light. |
Crosscutting Concepts | Structure and Function. Structures can be designed to serve particular functions by taking into account properties of different materials, and how materials can be shaped and used. |
Materials

- BlueBot: 4-in-1 Robotics Kit, available our partner Home Science Tools. (Also available as a Classroom Kit specially priced for teachers)
- Additional parts and tools to assemble the robot (not included in the kit):
- Small Phillips-head screwdriver
- Double-sided foam tape
- Popsicle sticks or building toy pieces like LEGO® or K'nex®
- Optional: small needle-nose pliers and/or tweezers (make it easier for some students to handle small circuit components)
- Materials to make a line-following racecourse:
- White poster board or butcher paper. Clear tape can be used to connect multiple pieces edge-to-edge to make a larger course.
- Different colored materials to make the line, such as colored electrical tape or permanent markers
Disclaimer: Science Buddies participates in affiliate programs with Home Science Tools, Amazon.com, Carolina Biological, and Jameco Electronics. Proceeds from the affiliate programs help support Science Buddies, a 501(c)(3) public charity, and keep our resources free for everyone. Our top priority is student learning. If you have any comments (positive or negative) related to purchases you've made for science projects from recommendations on our site, please let us know. Write to us at scibuddy@sciencebuddies.org.
Background Information for Teachers
This section contains a quick review for teachers of the science and concepts covered in this lesson.This project provides a very simplified introduction to how real-world autonomous (also called driverless or self-driving) cars work. Autonomous cars need to navigate a very complicated environment, including reacting to other cars, driving on roads with different types of lines (or no lines at all), and obeying all traffic signals and signs. They do this using a variety of electronic sensors, like cameras and radar, with computers to process all the information. The robot your students will build in this project uses two electronic sensors to automatically follow a dark line on a white background. This is conceptually similar (but not identical) to how a real autonomous car might monitor lane lines to make sure the car does not drift out of its lane.
The robot uses infrared (IR) light sensors. Infrared light is part of the electromagnetic spectrum, just outside the range of human vision. Each sensor contains an infrared emitter, which sends out infrared light, and an infrared detector, which measures whether infrared light is bounced back. Just like the colors of visible light that we can see, and all other types of electromagnetic radiation, infrared light is reflected by some surfaces, and absorbed or transmitted by others. The sensors have a very short range (a few millimeters), which means they can be used to detect nearby objects that reflect infrared light, as shown in Figure 1.

A sensor for the line-following robot consists of an infrared emitter and an infrared detector. When the IR emitter shines a light on a bright surface the reflection is bounced into the IR detector. When the IR emitter shines a light on a dark surface, the IR light is absorbed and does not reflect any light towards the IR detector. When the IR detector doesn't detect any IR light then the sensor knows it is on a dark surface.
Figure 1. Schematic of the IR light sensors.
The robot drives by using two sensors and differential steering, meaning it has two wheels that are driven independently by two different motors (unlike a car, which has a steering wheel that turns both front wheels). When both wheels spin, the robot drives forward. When the left sensor sees a dark surface, the left wheel stops and the right wheel keeps spinning, so the robot turns left (and vice versa for the right sensor). That means the robot can follow a line, as shown in Figure 2.

Two infrared sensors are placed on the front of a line-following robot chassis and spaced apart slightly wider than the width of the black line. As the two sensors scan either side of a black line the light will be reflected off the white surface and the sensors will send power to the motors. When a line begins to curve left, the left IR sensor will detect the dark surface and cut power to the left wheels which cause the robot to begin turning towards the left. When the robot is turned far enough left that the sensor is no longer over the black line, than the left motor will receive power again. The same situation applies for a line curving right and the right IR sensor and motor.
Figure 2. Following a line with two IR sensors.
The robot's circuit contains other electronic components like resistors, transistors, and diodes that allow the sensors to control the motors. You do not need to understand exactly how the circuit works in order to build it and do the project. For a detailed technical explanation of how the circuit works, including a circuit diagram, see this page.
This project requires use of a breadboard, a tool for quickly and easily prototyping electronic circuits. If you have never used a breadboard before, we highly recommend watching the following video before doing the activity with your class. There are several common mistakes that students make when using breadboards, and being familiar with them will help you facilitate troubleshooting during class. You can also ask your students to watch the video as a homework assignment before class.