Purple Sky Profile Header
How easy is it for you to walk along and follow a line that is painted on the ground? Simple, right? You might be able to follow a line without giving it much thought, but how could a robot do that? In this project, you will build your own automatic line-following robot that can race around a track that you create. This technology has plenty of real-world applications—maybe one day you could help design self-driving cars!
AREAS OF SCIENCE
Build a line-following robot and make adjustments so it can follow a line on the floor without going off-course.
Have you ever walked along a line painted on the ground at a playground? Or have you ridden your bike along a trail, or ridden along a road in a car, with an adult driving? All of these things might seem pretty easy to do—you hardly have to think about them at all (although if you are going too fast or not paying attention, you might go off the trail or crash your bike!). How can you make a robot automatically follow a trail? There are many types of automatic, line-following or self-driving robots, ranging from the simple one you will build in this project (which follows a black line on a white floor), to completely automatic self-driving cars that can handle much more complex tasks, like stopping at red lights and avoiding other cars. These more-advanced cars and robots use sensors, like cameras, to observe the world around them and know how to react—just like you use your eyes (or a visually impaired person would use a cane and their sense of touch) to observe a trail or path in front of you. The robot you build in this project will use two sensors and a simple circuit that allows it to steer left and right to follow a line. Figure 1 shows what the robot will look like, and this video shows a demonstration of how it works.
line-following-robot

Figure 1. The line-following robot that you will build in this project.

So, how is the robot able to automatically track a dark line? The robot relies on a sensor that detects infrared (IR) light (which is part of the electromagnetic spectrum, just outside the range of visible light that humans can see). The sensor consists of two parts: an IR emitter which sends out IR light, and an IR detector, which detects incoming IR light. As shown in Figure 2, when combined, these two parts can be used to detect a nearby bright object, like white paper. The IR emitter sends out IR light, which bounces back off the white paper, and is "seen" by the IR detector. If the surface is too dark, the IR light will be absorbed by the surface instead of bouncing back from it, so the IR detector will not "see" any IR light.



infrared-light-object-sensor

Figure 2. An illustration of how the IR sensors in this project work. The IR emitter emits IR light. Bright surfaces will reflect this light back toward the IR detector and trigger the sensor, while dark surfaces will not.

Now you understand how an IR sensor can be used to detect a black line, but how do you actually get a robot to drive along and follow the line? You will need to use two of the sensors, one placed on either side of the line, as shown in Figure 3. Through an electronic circuit, each sensor controls the speed of one of the robot's two wheels. When both sensors "see" white, both wheels spin at full speed, causing the robot to drive straight. When one sensor sees the black line, it causes one of the robot's wheels to slow down, which makes the robot turn so it can continue to follow the line. For example, if the left sensor "sees" black, the left wheel slows down; this causes the robot to turn left. As shown in Figure 3, this allows the robot to automatically follow a curved track!

line-tracking-robot-steering

Figure 3. An illustration of how the line-following robot steers. It uses two IR sensors to detect the line. When a sensor "sees" the dark line, the circuit slows down the wheel on that side of the robot, causing the robot to turn.

In this robotics project, you will follow step-by-step instructions to build your own line-following robot. It turns out that the position of the IR sensors has a big impact on the robot's performance. If they are too close together (or too far apart), or too close to the floor (or too far above it), the robot might have trouble following the line. It could even overshoot a curve and crash! So, you will follow the Engineering Design Process to adjust your robot's sensors. Can you get it to drive without crashing?

Technical Note

The rest of the Introduction contains more details about the electronic components used in the circuit. The following information is provided as a reference, and you do not need to fully understand it in order to do the project. If are ready to just start building the robot, you can move on to the Procedure.

If you would like to read the rest of the Introduction, it will help if you are familiar with basic electronics terms like voltage, current, and resistance. Science Buddies has many beginner and intermediate level electronics projects, an Electronics Primer, and an Electricity, Magnetism, & Electromagnetism Tutorial that can help you learn more about these topics. You can also refer to the Bibliography for more information.

For a complete technical explanation of how the circuit works, including a circuit diagram, see the Help section.

The circuit you will build in this project uses a variety of electronic components. All of the components are combined on a chassis, or plastic base for the robot, which includes wheels. Some of the components, like batteries and switches, you probably use every day (even if you do not notice it). Others, like diodes and transistors, might be new to you if you have not done an electronics project before. Table 1 has pictures and descriptions of each component you will use in this project. For a more detailed explanation of what each component does in the circuit, see the Help section.

General robotics and electronics terms:

  • Sensor
  • Circuit
  • Infrared (IR) light
  • Electromagnetic spectrum
  • IR emitter
  • IR detector
  • Voltage
  • Current
  • Resistance
  • Chassis

Circuit components:

  • Battery pack
  • Breadboard
  • Switch
  • Jumper wires
  • Male-female jumper wire
  • DC motor
  • MOSFET
  • Transistor
  • Diode
  • Resistor
  • Ohm (Ω)
  • IR sensor
  • Light-emitting diode (LED)
  • Phototransistor

Advanced terms (see Help section)

  • Base
  • Collector
  • Emitter
  • Bipolar transistor
  • Field-effect transistor
  • Gain
  • Gate
  • Drain
  • Source
  • Threshold voltage
  • Saturation
  • N-channel MOSFET
  • P-channel MOSFET
  • Current-limiting resistor
  • Pull-down resistor
  • What real-life conditions and obstacles do self-driving cars have to deal with?
  • What types of sensors do self-driving cars use to help them drive?
  • How are real-world self-driving cars different from the robot you will build in this project?
  • How can an IR light sensor be used to detect a dark line and help a robot follow it?
  • How do you think changing the IR sensors' distance from the ground will affect the robot's steering?
  • How do you think changing the horizontal distance between the IR sensors will affect the robot's steering?

Itemname

Battery pack

Picture

4xAA-battery-holder-picture

Descripton

This is the power supply for your robot. Battery packs come in all shapes and sizes. The one in this project holds 4 AA batteries.

Breadboard

breadboard-picture

A breadboard allows you to quickly and easily connect wires and electronic components in order to build a circuit. The connections are not permanent, so you can easily move things around if you make a mistake.

Switch

spdt-switch-new

You use switches every day to turn lights and appliances on and off. This is a tiny switch that fits on a breadboard, to let you turn your robot on and off.

Jumper wire

jumper-wires

Jumper wires are short wires used to make electrical connections on a breadboard. They come with many colors of plastic insulation, which makes it easy to color-code and organize complicated circuits.

DC Motor

DC-motor-picture

Electrical current causes a motor to spin. Two motors drive the robot's wheels. This type of motor runs on direct current (DC) from a battery (as opposed to alternating current [AC] from a wall outlet).

MOSFET

MOSFET-picture

A MOSFET is a special type of transistor, which acts like a control valve to let electrical current flow. As an analogy, think of how a valve can control the flow of water through a garden hose. In this circuit, the MOSFETs control the flow of current through the motors. See the Help section for more detailed information about MOSFETs, including what MOSFET stands for.

Diode

diode-picture

A diode is like a one-way valve for electricity. It only lets current flow in one direction. In this circuit, diodes are used to protect the MOSFETs from voltage spikes that can be caused by abruptly stopping the motors.

Male-female jumper wire

M-F-jumper-wires

This is a special type of jumper wire that comes with a female connector on one end and a male connector on the other end.

Resistor

resistor

As the name implies, a resistor resists the flow of electrical current. Electrical resistance is measured in ohms (Ω). Resistors come in many different values, marked by color-coded bands. In this project you will use 220 Ω resistors and 4.7 kΩ resistors.

IR sensor

IR-sensor

The IR sensor consists of two parts, an emitter and a detector. The emitter is an IR light-emitting diode (LED), which emits IR light. The detector is an IR phototransistor, which is activated by the light. When combined, these two parts allow the sensor to detect nearby reflective objects, as shown in Figure 2.

Table 1. Pictures and descriptions of each circuit component used in this project.

How are all these components combined to control the motors and make the robot steer? While the full details are in the Help section, there are two things that will help you understand the basics of how the robot works:

  • The MOSFETs act like valves that control flow of electricity through the motors. When a MOSFET's input receives a high voltage, it makes a motor turn on, which spins a wheel. When a MOSFET's input receives a low voltage, it makes the motor shut off, so the wheel stops.
  • The IR sensor can be set up so it outputs a high voltage when it "sees" white, and a low voltage when it "sees" black.

Can you imagine how these two things could be set up to control a motor, and spin a wheel, based on whether or not the sensor sees a black line? You will need to connect the output of the sensor to the input of the MOSFET. Figure 4 shows a simplified diagram of this process (remember to refer to the Help section for the full explanation).

line-following-robot-block-diagram
Figure 4. A block diagram of the robot's operation (this is a simplified diagram that excludes some components; see the Help section for the actual circuit diagram).