mBot Line Counting

LOWER SECONDARY

Grade Level

COMPUTER SCIENCE

Subjects

mBot

Product

40MINS

Estimated duration
Longer description

The line follower sensor is usually used to follow a line, but in this lesson we are going to learn how it can be used to count lines instead. For this we are going to need a variable to count with. What other things do we need in the program? Write down some pseudocode before moving on.


Declare a variable.

Move forward.


Loop:


---- If we see a line


---- ---- Add one to the variable.


End Loop

At the end of this program, the number of lines that the mBot passed over should be held in the variable. We can write this in mBlock code. I decided to move forward and count lines for 10 seconds:

basic-program

There are 2 problems with this code at the moment. The first one is that there is no way to read the count variable. Read the challenges and see if you can identify and solve the second problem.

Challenge:

  1. Add a way to be able to verify the value of the variable.
  2. With this code, the value of the variable recorded will not be correct. Can you figure out why? And how to correct this?

Construct Your Dreams!