You learned how to make the Simple Walker move. As an final challenge, try to make the robot avoid obstacles.


The Simple Walker has an ultrasonic sensor (the eyes) that it can use to detect obstacles.


This sensor works much like the sonar on a boat or the echolocation of a bat. It sends out a sound pulse (at such a high pitch that it is not audible). When this sound pulse hits an object, it is reflected back. By measuring the time it takes for the sound to come back you can compute the distance of the object.


mBlock contains a special block for reading the ultrasonic sensor.


This blocks has two pin numbers defined, trigger and echo. The first one is the pin that tells the sensor to send a sound pulse, and the second is for the sensor to tell the Simple Walker when the sound pulse is received. On the Simple Walker these pin numbers are 10 (trigger) and 16 (echo).

Eventually we want to use the sensor to let the Simple Walker walk around objects. But it might be good to start out with something simpler. The sketch below turns the LED on if it detects an object at less than 10cm.


This sketch introduces some new constructions. We already know the forever and set digital pin block. But the if then else block, the read ultrasonic sensor, and the < block are new. In a nutshell it does the following: read ultrasonic sensor reads the distance to the nearest object in centimeters, if this distance is smaller then 10cm the LED is turned on, else, the LED is turned of. This process is repeated forever.


Puzzle 1

Enter the sketch above into mBlock and see if it works. You will notice that the distance sensor does not always react perfectly. This is normal. No electronic sensor is ever perfect. One of the arts of creating a reliable robot, is to find ways to deal with those imperfections.

Puzzle 2

Get the robot to walk forward until some object gets too close (< 10cm). Stop walking when this happens until the obstacle is taken away.

Puzzle 3

Get the robot to walk forward normally, but walk backward when an object is too close.

Puzzle 4

As an ultimate challenge try to get the robot to pursue its original course after avoiding an object.

The hardest part is not to get the Simple Walker to avoid an obstacle. The hardest part is to get it to return to its original direction. Can you get the Simple Walker to do this?