Students follow a line with one sensor (swinging along its edge), then two sensors (drive straight, steer towards the side that still sees the line), and combine line following with the distance sensor to make a delivery robot that stops when blocked.
Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
Predict and Run 8 min · Investigate 12 min · Modify 10 min · Make 15 min · Real robot 5 min (optional)
The robot has two line sensors under its front. Each is true when it is over the dark line. With one sensor the robot can only swing back and forth along the line's edge. With two, it knows which way it drifted: if only the left sensor still sees the line, the line is to the left, so it steers left (right wheel faster: robot motor tank 10 40). Steering the wrong way is the common slip (Kai's robot).
The simulator's sensors are on/off only. Real sensors measure how much light comes back, which allows smooth steering; that is a good teacher-led extension on real robots. The simulator also adds a small "line assist": after the robot loses the line it slows down for a moment, which helps it find the line again.
The Make combines lessons 3 and 5: the distance question must come first, or the robot would follow the line straight into the box. If the robot does not start on the line, students drag it onto the line, facing along it. MOVE Motor classes can use Kitronik's line-sensor blocks on the real robot; they give a number, so steering on the difference between left and right is a natural extension.
Steering towards the sensor that still sees the line. Ask which side the line is on when only the left sensor sees it.
| What you will see | A question to ask | The fix |
|---|---|---|
| The robot leaves the line at the first bend. | When only the left sensor sees the line, which way is the line? | Steer towards it: left sees the line, steer left (10 40). |
| The robot stops straight away. | Is it on the line? Which case is it in? | Drag it onto the line, facing along it. |
| It drives into the box on the line. | Which question does your if ask first? | Put the distance question first: the first true question wins. |
One possible solution for each task. Other correct programs are fine.

robot.elecfreaksCuteBot.start()
basic.forever(function () {
if (robot.detectLine(RobotLineDetector.Left) && robot.detectLine(RobotLineDetector.Right)) {
robot.motorTank(60, 60)
} else if (robot.detectLine(RobotLineDetector.Left)) {
robot.motorTank(10, 40)
} else if (robot.detectLine(RobotLineDetector.Right)) {
robot.motorTank(40, 10)
} else {
robot.motorStop()
}
})

robot.elecfreaksCuteBot.start()
basic.forever(function () {
if (robot.detectLine(RobotLineDetector.Left) && robot.detectLine(RobotLineDetector.Right)) {
robot.motorTank(60, 60)
} else if (robot.detectLine(RobotLineDetector.Left)) {
robot.motorTank(10, 40)
} else if (robot.detectLine(RobotLineDetector.Right)) {
robot.motorTank(40, 10)
} else {
robot.motorStop()
robot.setColor(0xff0000)
}
})

robot.elecfreaksCuteBot.start()
basic.forever(function () {
if (robot.obstacleDistance() < 10) {
robot.motorStop()
} else if (robot.detectLine(RobotLineDetector.Left) && robot.detectLine(RobotLineDetector.Right)) {
robot.motorTank(40, 40)
} else if (robot.detectLine(RobotLineDetector.Left)) {
robot.motorTank(10, 40)
} else if (robot.detectLine(RobotLineDetector.Right)) {
robot.motorTank(40, 10)
} else {
robot.motorStop()
}
})
Stretch: Count laps: when both sensors lose the line for a moment at a gap, or each time a button is pressed, add 1 and show it. Or: drive the loop the other way.
Support: Give the two-sensor program with the turns removed from the middle branches; students choose the steering for each.
Only the right sensor sees the line. Which way should the robot steer, and why?
Right: the line is on the right, so steering right brings the robot back over it.
Next unit: Modes. One robot, many jobs: a variable chooses between stop, drive and follow. Real-world links: warehouse robots, hospital delivery robots, robot lawn mowers that follow a boundary wire.