Get Help
Edge Avoidance (miniBloq)
Introduction
In this tutorial, you’ll learn how to make Sparki avoid falling off a table using the sensors on the underside of the robot:
What You’ll Need
- A Sparki
- A table (preferably a light colored non-transparent one).
How It Works
Sparki has an array of infrared sensors underneath that it uses to detect if there is anything underneath it. We’re going to program Sparki so that it knows it should stop moving and turn around if it detects something underneath it. This will help Sparki not fall off tables. Here you can see the sensors in the bottom of the robot:
Infrared reflectance sensors on Sparki’s underside
Infrared reflectance sensors can be thought of as infrared light (which humans can not see), and some special eyes that look at that light. The eyes are made out of a photo-sensible material (a material which changes its electrical properties in response to changes in the incident light) and an LED (or Light Emitting Diode):
Here are the parts again, but with pictures showing what you’d normally think of them as!
When the infrared light shines off the edge of the table, almost nothing comes back!
Programming It With Sparki



- The angle belonging to the turnLeft and turnRight blocks, which has a value of 20 (degrees).
- The distance belonging to the moveBackward block, which has a value of 5 (centimeters).


Extra Activities
As you might figure out, this code really does not like corners as those will trigger both of the sensors at the same time! Can you think of some code modifications that would help Sparki not get stuck on corners?Related Lessons
To learn more about the infrared sensors and other similar activities, take a look at the following lessons:SparkiDuino Programming Environment
