Jump to main content
Your email has not been verified. Verify email now ›

Line-Following Robot

Summary

Grade Range
6th-8th
Group Size
2-4 students
Active Time
2-3 hours
Total Time
2-3 hours
Area of Science
Robotics
Key Concepts
Circuits, electromagnetic spectrum
Credits
Science Buddies is committed to creating content authored by scientists and educators. Learn more about our process and how we use AI.

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

NGSS Alignment

This lesson helps students prepare for these Next Generation Science Standards Performance Expectations:
This lesson focuses on these aspects of NGSS Three Dimensional Learning:

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

Parts from a BlueBot robotics kit sold on the website homesciencetools.com are laid out neatlyImage Credit: Science Buddies

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 [email protected].

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.

Diagram of an infrared light sensor that can detect light bounced off of bright surfaces but not dark surfacesImage Credit: Ben Finio, Science Buddies / Science Buddies

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.

Diagram of a line-following robot using light sensors to turn or remain on a straight pathImage Credit: Ben Finio, Science Buddies / Science Buddies

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.

Additional Background Links

Prep Work (20 minutes)

  • Optional: depending on how much time you will have available during class, you may want to pre-assemble the robot's chassis. This involves using a tiny screwdriver to connect many small screws, and can be difficult for younger students. See the Assemble the Chassis section in the lesson.
  • Print out copies of the student worksheet and wiring diagram.

Engage (10 minutes)

Ask:
How do we avoid crashing into things when we walk around, ride a bike, or drive a car?
Discussion tip:
We use our senses to avoid crashing into things. Humans rely primarily on sight, but we also use other senses like hearing (e.g. you can hear a car approaching from behind you, even though you cannot see it) and touch (a blind person might use a cane to feel for obstacles in front of them).
Ask:
Have you ever seen a self-driving car on the news or in real life? How do these cars sense the world around them?
Discussion tip:
Self-driving cars use a variety of electronic sensors that act sort of like human senses. For example, they might use radar to detect how far away the car directly in front of them is, a camera to look for pedestrians or the lane lines, or GPS to determine what road the car is on.
Ask:
How does a self-driving car use this information to drive and avoid crashing? How is this similar to how humans drive?
Discussion tip:
A computer processes all the information from the sensors and uses it to control the car's engine, brakes, and steering. This is similar to how your brain processes information from your senses and uses that information to control your muscles. For example, if a human driver sees someone run out into the street, their brain will think "hit the brakes!" and send a signal to their leg muscles to press the brake pedal. If the car's camera detects a pedestrian in the street, the computer will send an electronic signal to activate the brakes.
Ask:
In this project, we will build a robot that can automatically follow a dark line on a white background. What is different about black and white materials?
Discussion tip:
White materials reflect all colors of visible light, and black materials absorb it.
Ask:
How could we make the robot follow the line? How would the robot know whether to go straight, turn left, or turn right?
Discussion tip:
Do not limit your students' answers here to the parts you will use in the project (for example, they could suggest using a camera instead of IR sensors). For instance, a student could say, "if the camera looks ahead and sees that the line curves to the left, then the robot should start turning left."

Explain that in this project we will use electronic sensors that can see infrared light, which is invisible to the human eye. We highly recommend using the slideshow to introduce how the robot works and walk your students through assembling it. Now get ready to start building!

Explore (120 minutes)

Assemble the Chassis

First we need to build the robot's chassis (pronounced chass-ee)—its body or frame. Depending on time constraints, you can assemble the chassis yourself before class, or have your students do it during class. Students may need help with certain steps, particularly attaching the motors. The following video shows how to assemble the chassis. Please note:

  • Assembly requires a small Phillips-head screwdriver, not included in the kit.
  • The chassis comes with printed instructions from the manufacturer, but they can be difficult to follow. We highly recommend watching the video for step-by-step instructions.
  • Do not screw the battery pack onto the bottom plate. This makes it difficult to access and replace the batteries. Instead, use double-sided foam tape to attach the battery pack to the top plate.

The following video shows how to assemble the chassis.

Build the Circuit

After assembling the chassis, you need to build the circuit by connecting electronic components on the breadboard. Remember to review this breadboard video if you and your students have never used a breadboard before. Your completed circuit should look like the one in Figure 3.

  • If your students have never used breadboards before, walk the entire class through building the circuit one step at a time using this slideshow.
  • Advanced students can work at their own pace using the printable wiring diagram, which only shows the completed circuit and not step-by-step instructions.
  • Remember that understanding exactly what each component in the circuit does is beyond the scope of this lesson plan. The goal is for students to learn how to follow instructions to assemble a circuit, locate errors if their circuit does not work, and learn what some of the more basic parts do (e.g. the power switch, the motors, and the IR sensors). For a detailed explanation of how the circuit works (for advanced students), see this page.
Breadboard diagram of a battery pack and two motors wired to a line following robot circuitImage Credit: Ben Finio, Science Buddies / Science Buddies
Figure 3. Completed circuit.

Test the Robot

Once your students have finished building the circuit, follow these steps to test the robot:

  1. Hold the robot in one hand so it is off the ground.
  2. Turn the power switch "on" (slide it up towards row 1 on the breadboard).
  3. If you see or smell smoke, immediately turn the robot off and double-check the wiring.
  4. Hold a white piece of paper up in front of the IR sensors and slowly move it towards them.
    Ask:
    What do you think will happen when we move the paper toward the sensor?
    Discussion tip:
    When it is just a few millimeters away, the wheels should start spinning. This occurs because infrared light is reflected back to the sensors off the white paper.
  5. If the wheels spin backwards, reverse the red and black wires for the motors (this just depends on which way you mounted the motors to the chassis; nothing is wrong with your circuit). If the wheels do not spin at all, see the Troubleshooting section.
  6. Try putting the robot down on a piece of white poster board. It should drive forward. If not, you might need to adjust the distance of the IR sensors from the ground. See the Troubleshooting section.

Do an Experiment

Let your students use the accompanying worksheet to plan and conduct an experiment to determine which materials reflect and absorb infrared light. You can guide the discussion as follows:

Ask:
How could we use this robot to determine which surfaces reflect infrared light and which ones absorb it?
Discussion tip:
We know that if we hold a surface that reflects infrared light up to the robot's IR sensors, it should make the wheels spin. If it absorbs infrared light, the wheels will not spin. We can use this knowledge to test whether different surfaces reflect or absorb IR light.
Ask:
What do we have to be careful about?
Discussion tip:
We have to make sure our robot's circuit is connected and working properly. Otherwise, the wheels might not spin for some other reason (for example, a wire came loose, or the surface we are trying to measure is too far away from the sensors).

Follow a Line

Once your students have figured out which materials absorb and reflect infrared light, you can use those materials to make a line-following race course. For example, you can use black electrical tape or permanent marker (absorbs IR light) on white poster board (reflects IR light).

Ask:
How could we make this robot follow a line? Hint: what will happen if only one wheel spins?
Discussion tip:
If only one wheel spins, the robot will turn. We can make the robot follow a line by placing the sensors on either side of a dark line. When one sensor "sees" the line (meaning the robot is about to drive over the line), that wheel will stop spinning, causing the robot to turn back towards the line.
Ask:
How can we test if our robot will follow a line successfully? How should we start out?
Discussion tip:
You should probably start by seeing if your robot can follow a straight line. That will allow you to troubleshoot if any problems arise, before you try more complicated lines and curves (Figure 4). The robot will have trouble with very sharp turns, so make sure you keep the turns gradual.
Two photos of a line-following robot traveling along a straight line on the left and a curvy line on the rightImage Credit: Ben Finio, Science Buddies / Science Buddies A line tracking robot following a black path on a white sheet of paperImage Credit: Ben Finio, Science Buddies / Science Buddies
Figure 4. Simple lines for initial tests (top) and a complete line-following race course (bottom).

Clean Up

  • If you will be using the robots with another class, have students remove all components from the breadboard when they are done, so the next class can build the circuit from scratch.
  • We recommend leaving the chassis assembled to save time in the future. You do not need to disassemble and reassemble it each time.
  • For short-term storage, make sure the robots are turned off (slide power switch down toward row 3 on the breadboard). For long-term storage, remove the batteries from the battery pack.

Troubleshooting

You will probably have some students claim "my robot doesn't work!" The wheels might not spin when you hold paper up in front of the sensors, the wheels might always spin no matter what you do, or maybe only one wheel will spin. All of these problems can usually be traced to a simple problem on the breadboard. Here are some common problems to look out for:

  • Make sure each part is in the correct row. It is easy to misplace a wire by just one row on the breadboard, but one misplaced component will stop the entire circuit from working.
  • Make sure the diodes are not backwards. The gray stripes on the diodes should face towards the left-side power bus.
  • Make sure the transistors are not backwards. The writing on the front of the transistors should face towards the left-side power bus. The large metal tabs should face to the right.
  • Make sure the students used the right resistors. The BlueBot kit comes with four different resistor values, indicated by color-coded bands. This project uses both 4.7 kΩ resistors (yellow, purple, red, gold) and 150 Ω resistors (brown, green brown, gold). If you use the wrong resistors, or get the 4.7 kΩ and 150 Ω resistors mixed up, the circuit will not work properly.
  • Make sure the IR sensors are connected properly. The sensors have a small diagonal notch in one corner of the plastic case, and the pins are numbered 1–4 going clockwise starting from the notch. Connecting the sensor's pins wrong will prevent it from working properly.
  • Make sure the batteries are inserted into the battery pack properly. The "+" signs on the batteries should line up with the "+" signs inside the battery pack.

If the circuit is connected correctly, but the robot still does not drive forward when you put it down on white poster board, you may need to adjust the distance of the IR sensors from the ground. The sensors have a very short range of just a few millimeters. If they are too close to the surface, the detector will be blocked. If they are too far away, not enough light will reflect back to the detector, as shown in Figure 5.

Drawing shows the proper distance an infrared sensor needs to be from the ground in order to function correctlyImage Credit: Ben Finio, Science Buddies / Science Buddies
Figure 5. Adjusting the distance of the sensor from the ground.

If the robot seems to work when you hold it off the ground, but gets stuck or stops for no reason when you put it down, make sure your race course is completely flat. Small bumps or bubbles in poster board can cause the sensors to either get physically stuck, or to get too close to the surface so the detector is blocked.

Finally, if the robot frequently overshoots turns, you can try making the black line wider. This gives the robot more time to "react," since it takes longer for the sensors to drive over the line.

Reflect (10 minutes)

Discuss the following questions as a class:

Ask:
What challenges did we run into when building our robots?
Discussion tip:
Answers will vary depending on the class. Some students might have had trouble getting the circuit working to begin with due to errors when wiring their breadboards. Some students might have had trouble getting the robot to drive at first due to the spacing of the sensors or distance from the ground. Others might have had trouble getting the robot to follow a line if the turns were too sharp.
Ask:
How did we make use of properties of different materials to make our line-following robot course? How does this relate to driving real cars (whether driven by people or autonomous)?
Discussion tip:
We used the fact that some materials reflect infrared light and other materials absorb it. On real roads, certain materials (like paint and road signs) are designed to reflect visible light back towards the driver, to make sure they are easily seen.
Ask:
The robots we built used two sensors pointed directly at the ground to follow a single, solid line. Would this setup work for a real-self driving car? Why or why not? What would we need to change?
Discussion tip:
This setup worked for the race course we built in a classroom, but it is too simple to work on a real road. Real roads have multiple types of lines (different colors, dashed vs. solid, single vs. double etc.), lines that cross each other (e.g. crosswalks at intersections), and some roads have no lines at all! Real self-driving cars need to use cameras to recognize and respond to all the different types of lines on the road.

Assess

You can use this quiz to assess student learning after the activity:

Make Career Connections

Discussing or reading about these careers can help students make important connections between the in-class lesson and STEM job opportunities in the real world.

Career Profile
Automotive engineers have been designing cars that are driven by humans for over a hundred years. Now they face the new challenge of designing autonomous cars, with the goal of dramatically reducing pollution and traffic deaths by making cars that can drive better than people. Are you up for this challenge? If so, you could work for one of many companies designing autonomous cars like Tesla, Google, or Uber! Read more
Career Profile
Robotics engineers use electronic sensors to control all sorts of autonomous vehicles and robots—not just the kind with four wheels. This includes flying vehicles like airplanes and drones, aquatic ones like boats and submarines, and even humanoid or animal-like land robots. All these robots need to be able to sense the world around them to interact with objects and avoid crashing into things. If you want to help make science fiction a reality, consider a career in robotics! Read more

Lesson Plan Variations

  • Your BlueBot kit comes with three other types of sensors: light, motion, and bump. Have your students explore how these sensors could be used in a self-driving car. For example, the motion sensor works by detecting infrared light at a longer distance, so it can see body heat from people and animals. That means it could be used to detect a pedestrian in the road, but not a cardboard box or a rock. Instructions to build a robot using each type of sensor can be found here:
  • There are many popular hobbyist devices like the Arduino®, Raspberry Pi®, and Beaglebone® that you can use to make a programmable robot with more complicated behaviors. For example, you could program a line-following robot to stop and go in reverse if both sensors see black. Can your students make a "smarter" robot by including computer programming? Can they incorporate multiple sensors (like the ones listed above) into a single robot?
Top
Free science fair projects.