Your mBot is also equipped with an ultrasonic sensor. This means that it has the ability to sense how far it is from various obstacles. Add the following code to your project:
Then click the Green Flag to start the program. The value picked up by the ultrasonic sensor will now constantly be displayed on the screen (just like we did with the light sensor in the previous stage). While the program is running, try moving the mBot really close to an obstacle (like a wall). This will give you an idea of what the readings are when the mBot gets really close to an object.
Now, you need to program your mBot so that you can drive it around (as normal). However, in addition to this, you need to set it up so that whenever it gets really close to an obstacle, it will stop, beep, and then move backwards for 2 seconds before stopping again.
As in the last stage, you can now get rid of the purple 'say' block. The only purpose of that block was to tell us the value of the sensor when the mBot gets really close to an obstacle. Now that we have that number figured out, we don't need that particular block anymore.
As before, try to figure this out on your own first. Don't give up too easily. If you REALLY need help, let Mr. Locke know and he might show you a hint.
Now, you need to program your mBot so that you can drive it around (as normal). However, in addition to this, you need to set it up so that whenever it gets really close to an obstacle, it will stop, beep, and then move backwards for 2 seconds before stopping again.
As in the last stage, you can now get rid of the purple 'say' block. The only purpose of that block was to tell us the value of the sensor when the mBot gets really close to an obstacle. Now that we have that number figured out, we don't need that particular block anymore.
As before, try to figure this out on your own first. Don't give up too easily. If you REALLY need help, let Mr. Locke know and he might show you a hint.