The line sensor
Invent Logo

If you've still got the obstacle sensor attached, remove it and attach the magnet module again underneath.

The magnet module actually has sensors on that point down towards the floor that can detect lines, so it's actually mainly used as a line sensor.

N.B. You can't use the obstacle sensor on top and the line sensor underneath at the same time. These modules both use the same input/output 'pins'.

The line sensor
How it works

These are the two sensors on the line sensor module. They work in the same way as the obstacle sensor. They transmit some invisible infrared light and see how much bounces back.

We'd expect these sensors to show a high number when there is a white object underneath them and a low number for a black object.

How it works
Testing it

Let's test out the line sensor to see how it works. Do you remember how we used the 'Print' block to print out the amount of light from the obstacle sensor?

You'll find there's a 'Line sensor' block you can use. You will recall that we need to put the print statement inside an infinite loop.

Do this now, and move the line sensor over a line on a black / white object, like the line on the activity mat if you have one.

Testing it
Exploring Mars

Your next challenge is to explore Mars and then return to base (which is the bottom of the activity mat shown here with the white strip).

Hint: You'll need an infinite loop and to check one of the light sensors to decide if you need to go straight ahead or turn.

Exploring Mars
Following the planet surface

We're now going to send our robot out to explore Mars! Your challenge is to use the line sensor to follow the outside of the planet surface. Choose which way you will circumnavigate Mars (clockwise or anticlockwise) and write a program.

Hint: You'll need an endless loop and you'll want to check one of the line sensors continually, either choosing to go forwards a little, or to turn a little towards the planet surface if you're veering off into space!

Following the planet surface
The race track

Can you write a program to follow a race track using both the left and right line sensors?

Hint: You'll of course need an infinite loop, and you'll need to check both sensors. You want both sensors on the BLACK line. Consider what you want the robot to do in the four situations that are possible - both sensors on the black line, just the left one, just the right one, and neither of them (just in case it veers off!) If you want another hint have a peek at the next step.

The race track
Hint

Here's the start of the program that just checks one of these four situations. You'll see how we've used the 'and' block. See if you can replicate this code first. Then, duplicate the 'if' block three more times and modify the code inside for the other three possibilities that the line sensor sees. Of course you'll need to change the 'Move' block for the other three.

Hint: You'll see here we've used the 'no wait' option as we want the robot to start moving 5cm if it's on the black line, but then not to wait before checking the sensors again. If you just moved a fixed 5cm, then every time you came to a turn you will find that your robot overshoots the corner.

Hint
Mega track 1

Your teacher might have a larger race track activity mat you can try your robot on. If so you can try a larger race.

Hint: If you haven't discovered it yet, there is a 'Speed' block that can change the speed of your robot. By default, the robot's speed is '5' but it can go up to '10'!

Is there any improvement you can make in your algorithm to go around the track faster? It's time for experimentation!