Step 5

Staying in the boundaries

To keep our robot within the boundaries, we use the “DownEye” sensor.

We tell our robot to drive forward until it sees red, then it will reverse before moving on.

Here we have this code repeat/loop for a set amount of time, feel free to change this time.

Once done, go ahead and test it out. The robot should get stuck going back and forth, but we’ll fix this next.

Remember our plan? Now all we need is for our robot to turn until it sees an object with its distance sensor. See if you code this by yourself before moving on to the solution on the next page.