Ultrasonic motion sensing (Advanced)

In this recipe, we will program the robot to gradually come to a stop using a proportional algorithm. We will also use some more advanced programming blocks such as advanced math, MyBlocks, and writing to datafiles.

Getting ready

Make sure you have your motion sensor attached to the robot with a wire plugging the motion sensor into Port 2.

How to do it...

We are going to start out with some simple code and gradually add complexity to it. As a reminder, let us reexamine some code similar to what we wrote in the Building a robot recipe. In this code, the robot moves forward until the Wait block tells it to stop 25 cm from a wall.

  1. Write, download, and execute this code as shown in the next screenshot:

    As you can see, ...

Get Instant LEGO MINDSTORMS EV3 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.