Get Help
Follow and Avoid Light (miniBloq)
In this tutorial, we’ll cover how to program Sparki to follow or avoid light.What You’ll Need
- A Sparki.
- A source of light (like a flashlight from the Sparki Materials Pack).
How It Works
Sparki has three light sensors that it can use to sense light: Each of Sparki’s light sensors can measure how much light is hitting them. The idea behind this follow light example is that the light is strongest on the sensor nearest to the light. Just like being further away from someone yelling makes it quieter, being further away makes the light dimmer:
Strength of light is proportional to distance from the source
Programming It With Sparki
We’ll conduct three if tests. Each test will determine if the sensor in that test is getting more light than either of the two other sensors. If that sensor is getting more light than the other two, it will move in that sensor’s direction:
Sparki will move in the direction of the strongest light source
Following Light
The following blocks can be used to return the reading of the left, center and right light sensors:

Here is a miniBloq program that makes Sparki follow a light source:
Just a note about the blocks used to rotate and move Sparki forward: as you can see in the code above, they receive a 0 (zero) number as the parameter. This means that they will rotate or move indefinitely, until they receive a new moving command. So, if we have Sparki rotate to the left with its degrees parameter set at 0, it will continue rotating in that direction until a move forward, backward or rotate right block is executed in the program.
Avoiding Light
Of course, the same logic (and nearly the same program) can be used to have Sparki avoid light instead of following it:
Here is the miniBloq program to do it:
SparkiDuino Programming Environment
This lesson is also available for the SparkiDuino Programming Environment. SparkiDuino will allow you to program your Sparki using standard Arduino syntax.
