What to expect
In this activity, we will connect the servo motors and light sensors to the driver expansion board. We will also program the micro:bit to operate the desktop light tracker.
Connections
In the last activity, we started and built most of the tracker frame needed to assemble the desktop tracker. In this activity, we will finish building and learning the program to operate the desktop tracker.
Materials
Light Tracker Assembly kit (bagged laser-cut pieces)
Wiring harness (included in bag)
3 light sensors (included in small box)
2 servo motors (re-used from Unit 2)
1 micro:bit
1 motor driver expansion board
Screws
Screwdriver (re-used from Unit 1)
Instructions
Part 1: Light sensor installation
Figure 1. Photosensitive Light Sensor
The desktop light tracker can track any light source because of the light sensors, as shown in Figure 1. This sensor can be programmed to gauge the amount of light and move the servo motors based on the light level.
Figure 2. Light Sensor Installation
Screw on three photosensitive light sensors on the board. When you put them on, ensure that the hole on the light sensor is over the hole on the board, as shown in Figure 2.
Figure 3. Nylon Bolt and Nut
2. To screw each of them on, use the screws and bolts provided, as shown in Figure 3.
Figure 4. Light Sensors on the Board
3. Repeat this process for all three light sensors.
Figure 5. Light Sensor Partition Assembly
4. Install the light sensor partitions to divide the top sensors (P0 & P1) to the bottom (P2) and the left sensor (P0) to the right (P1), as shown in Figures 4 and 5.
Part 2: Wiring the light sensors
In this part, we will wire ground, power, and VCC from the light sensors and connect them to the driver expansion board.
Three pins on the light sensor will be connected to the driver expansion board, Ground(GND), Signal (VCC), and Power (P). It is very important that the colors are on the correct pin, or else the desktop light tracker cannot function properly.
You are provided with 3 sets of color wires. Please ensure each light sensor is connected to the matching slot on the expansion board. For example, P0 (top left) sensor wires must be connected to the P0 slot on the board.
Figure 6. P2 Light Sensor Wire Connection
Figure 7. P2 Light Sensor Wires Connected to the Expansion Board
Here, we will use the P2 light sensor as an example. Please use the color wires to connect each light sensor component to the driver expansion board, as shown in Figure 6 and Figure 7.
GND: White
VCC: Black
POWER: Gray
Do the same for P0 and P1 sensors using the color wires suggested below.
P0 Light Sensor
GND: Orange
VCC: Yellow
POWER: red
P1 Light Sensor
GND: Blue
VCC: Purple
Power: Green
Part 3: Adding Servo Pins
Next, we will connect all the wires we installed from the previous parts and put them into our driver expansion board.
Figure 8. S2 Servo Motor Connection to the Expansion Board
First, we will connect our bottom servo (S2) to the driver expansion board using the assigned S2 pins on the board, as shown in Figure 8. The brown pin should be on GND (Black pin on the board). The red pin should be on Vin (Red pin on the board). The yellow pin should be on P (Green pin on the board)
Figure 9. S1 Servo Motor Connection to the Expansion Board
2. For the S1 servo motor, we will do the same but add the servo motor (one on top) into the S1 pins on the board, as shown in Figure 9.
Part 4: The driver expansion board installation
In this part of the activity, we will add the driver expansion board to our desktop tracker.
Figure 10. Driver Expansion Board Installation
Connect the driver expansion board to the 5V battery pack by unscrewing the two connectors on the side of the ON/OFF switch and connecting the wires to the board, as shown in Figure 10.
Figure 11. Expansion Board Installation
2. Next, attach the driver expansion board on the baseboard of the tracker using the bolts and nuts provided, as shown in Figure 11.
Figure 12. Coding for Initial Setup
Part 5: Programming the tracker
To operate the desktop light tracker we will program the micro:bit for the tracker to follow the light source. You can download the code for the tracker operation here.
At the beginning, we will determine the initial position of the tracker, as shown in Figure 12. This gives you a chance to calibrate the hardware of the tracker to set its initial position before it tracks the light source.
Figure 13. Light Sensor Input Calculation
2. The next part of the coding shows how three light sensors are used to determine the tracker movement direction using two servos, as shown in Figure 13. First, the average input value of the two top sensors (P0 and P1) and the input value of the bottom sensor (P2) will determine the vertical movement of the tracker (S1). Similarly, the average input value of the left sensor (P0) and the bottom sensor (P2) and the average input value of the right sensor (P1) and the bottom sensor (P2) will determine the horizontal movement of the tracker (S2).
Figure 14. Programming Vertical Movement of the Tracker
3. Next, we are getting into the part to program the tracker to control the vertical movement. As shown in Figure 14, it is programmed to move upward using the servo (S1) if the top sensor input value (aTOP) is higher than the bottom sensor input value (aBOTTOM). Vice versa, it will move downward if the bottom sensor input value (aBOTTOM) is higher than the top sensor input value (aTOP).
Figure 15. Programming Horizontal Movement of the Tracker
4. The next part of the program tells the tracker to control the horizontal movement, as shown in Figure 15. It is programmed to move to the left using the servo (S2) if the left sensor input value (aLeft) is higher than the right sensor (aRight). Vice versa, it will move to the right if the right sensor input value (aRight) is higher than the left sensor input value (aLeft).
Figure 16. Tolerance and Debouce
5. The last part of the coding shows the debounce adjustment. This determines how fast the tracker will move and update its position. This can be adjusted by pressing the “B” button, as shown in Figure 16. In the same way, the tolerance of the sensor can be adjusted by pressing the “A” button, as shown in Figure 16.
Figure 17. Desktop Light Tracker Initial Position
6. At the end of this activity, your desktop tracker should look like the one in Figure 17. To start the tracker, you need to turn on the switch on the battery pack and the driver expansion board. After turning on the tracker, if its initial position doesn’t look like the one shown in Figure 17, we need to calibrate the tracker to set up its initial position.
Figure 18. The Top Servo (S1) Calibration for the Light Sensor Cluster
7. Remember that we have two servos to calibrate. The servo motor on top (S1) controls the vertical movement of the tracker. The light sensor cluster plate should face up at the initial position. If this is not the case, you can take it apart, as shown in Figure 18, and put it back in the correct position, as shown in Figure 17.
Figure 19. The Top Servo (S2) Calibration for the Circle Board
8. The servo motor at the bottom (S2) controls the horizontal movement of the tracker. The circle board on the servo (S2) should be positioned as shown in Figure 17. If it is not positioned properly, you can take the circle board out, as shown in Figure 19, and then put it back in place to position it as shown in Figure 17.
Figure 20. Testing the Light Tracker with a Halogen Lamp
9. Now, you are ready to go! Once you press “A” button on the micro:bit, it should start tracking the light source. You can try the tracker with a flashlight on your cell phone or a halogen lamp provided, as shown in Figure 20. For the optimum operation of the tracking capability, you can try to turn off the light in the room.
Wrap Up
We wired and programmed the tracker to point to the light source in this activity.
We will use our skills from the last activity as an extension activity. You can position the light on the summer/winter solstice and spring/fall equinox to replicate the light tracker movement as a solar tracking system.
Think about it
What would the angle of your tracker be if it was the winter solstice?
What would the angle of your tracker be if it were the spring/fall equinox?
What would the angle of your tracker be if it was the summer solstice?
What was your favorite part of this activity?