Get Help
Wall Avoidance (miniBloq)
Introduction
Sparki can use its ultrasonic sensor to avoid running into walls. In this lesson you will program Sparki to do just that!
What You’ll Need
- A Sparki.
-
- Some space for it to run around in and some walls. You can also use solid objects like cardboard boxes for your walls. Try to have hard walls (instead of soft things like pillows or cloth) since the ultrasonic range finder thinks those are easier to see.
How It Works
Here is the ultrasonic sensor or ultrasonic range finder. Sparki uses it to see what is in front of it in a similar way to how a dolphin or a bat uses echolocation. If you are not familiar with this sensor, please read this previous lesson.


- Center the ultrasonic sensor (so it points to the front).
- Change the color of the LED to green.
- Make Sparki go forward.
- Sense distance with the rangefinder.
- When Sparki’s rangefinder finds an obstacle:
- Make Sparki beep using the buzzer.
- Change the LED to red.
- Make Sparki move backward.
- Make Sparki turn.
Coding the Wall Avoidance Program
Now that we know what to do, let’s figure out how to do it using the blocks that miniBloq provides:- Center the ultrasonic sensor so it points to the front:

- Change the color of the LED to green (later in this same lesson, we will see the values needed for this block’s parameters in order to turn the RGB LED green):

- Make Sparki go forward:

- Sense distance with the rangefinder:

- Make Sparki beep:

- Change the LED to red (later in this same lesson, we will see the values needed for this block’s parameters, in order to turn the RGB LED red):

- Make Sparki move backward:

- Make Sparki turn:

- Change the color of the LED to green.
- Go forward.

- Make the LED red
- Beep
- Move backward
- Turn




Related Lessons
To learn more about the ultrasonic range finder, take a look at the following lessons:- Using the Ultrasonic Distance Sensor
- Also, a similar technique but using different sensors is used in the Edge Avoidance lesson.
SparkiDuino Programming Environment
