Activity Programming The Sun Tracker

Once again, we will be building upon our previous program. These additions let us read and compare the voltages generated by the two solar arrays. Remember, you may either follow the directions to build on your program for each experiment, or download the programs from

V In the BASIC Stamp Editor, open DuelingSolarCells.bs2.

V Rename and save the program as SunTracker.bs2.

V Update the title to read as follows:

' Experiments with Renewable Energy v1.0 - SunTracker.bs2 ' Tracks the sun with 2 solar panels attached to a servo motor

V Now add the following code to the end of the Declarations section:

' ----- For Experiment 3: Solar Cell Sun Tracker --------------------------

Servo PIN 12 ' Sun tracker servo on P12

waitCount VAR Nib ' Dampens servo's "hunting"

WaitVal CON 1 ' initial value of waitCount

Now we'll follow up with adding the code for Experiment 3 in the Subroutines section as shown below:

V First add the commented lines to document the subroutine:

Experiment 3: Solar Cell Sun Tracker

Based on the values for CH1 and CH2 from Experiment 2 Determine if the servo should stop, move left or move right

By moving the servo left or right, the individual solar cell voltages will eventually become equal and the program will cause the servo to stop. That is, until the sun moves and the voltages become unequal again thus causing the servo to reposition the solar panels.


V Then fill out the Exp_3 subroutine as shown:


PULSOUT Servo, 750 GOTO Exp_3_Set_Wait_Count


waitCount = waitCount - 1 IF (waitCount <> 0) THEN


PULSOUT Servo, 755 GOTO Exp_3_Set_Wait_Count ENDIF


waitCount = waitCount - 1 IF (waitCount <> 0) THEN


PULSOUT Servo, 74 5 GOTO Exp_3_Set_Wait_Count ENDIF

Exp_3_Set_Wait_Count: waitCount = WaitVal

Exp_3_End: RETURN

V Save your work!

Your Turn: Tracking the Sun

V In the BASIC Stamp Editor, run SunTracker.bs2.

V Note the COM port being used, then close the BASIC Stamp Editor's Debug Terminal.

V Open StampPlot Pro by clicking on Start ^ Programs ^ Parallax Inc ^ StampPlot ^ Experiments with Renewable Energy ^ sic_ewre_exp_3.spm.

V Set the COM port in StampPlot to the same one that was being used by the Debug Terminal.

V Click on the Connect button, and make sure the Enable Plotting box is checked.

V Hold the tracker by the servo so that it is pointing towards your light source, but not directly at it. The servo should begin moving the solar panels, little by little, towards the light.

V While this is happening observe the left and right LEDs on your circuit.

' stop the servo

' and re-initialize the waitCount

' decrement the waitCount

' Exit if not zero, else

' Slowly move the servo left

' and re-initialize the waitCount

' Decrement the waitCount

' Exit if not zero, else

' Slowly move the servo right

' and re-initialize the waitCount

' Re-initialize the waitCount ' and exit

If one LED is illuminated and the other is extinguished, the servo should be moving the solar panels in the direction of the extinguished LED. The servo movement should stop momentarily when both LEDs become illuminated. The servo may now begin to "hunt" or move back and forth in an effort to equalize the left and right solar panel voltages.

V At the same time observe the StampPlot display.

As illustrated in Figure 4-18, the voltages of the left and right solar panels are not equal at first. Then as the servo moves the panels towards the light, the voltages begin to converge culminating in two lines overlaying one another. As we are using a 60 W desk lamp as our "sun" you can see the familiar wave pattern to each trace.

Figure 4-18: Sun Tracker in Tracking Mode i' r i "j

Figure 4-18: Sun Tracker in Tracking Mode

Just for fun, move your sun tracker or your lamp to simulate the changing relative positions that would occur in a system working out of doors with the real sun. Or, set up your experiment outdoors (in dry weather!) or in a window that gets all-day sun as would a south-facing window in the Northern Hemisphere.

The sun tracker works by having the servo move the solar panels in a direction that will equalize both of their voltages. This translates into the servo continuously pointing both solar panels directly at the light source, thus tracking it if it moves. It makes no difference what voltages the solar panels are outputting at the time; the only thing that does matter is that the voltages be the same. Experiment 2 showed that this occurs when the left and right panels are pointing directly at the sun or other bright light source AND when the offset variable is set to calibrate the individual panels. With the correct offset value in the program, both panels will deliver an equally compensated voltage when pointed directly at the light source.

To make the servo track the sun we begin with our declared variables and constants as shown below:

The servo pin 12 instruction allows us to easily control the servo through the BASIC Stamp I/O P12. The waitcount variable, a 4-bit nibble, is used to "dampen" the servo's hunting while waitval is the initial value of waitcount set by the program.

The first three if...then commands evaluate which solar panel is receiving more light, and directs the program to the appropriate label. If the first condition (chi = ch2) is true, the solar panels are generating equal voltage, and the tracker is probably pointing right at the light source, or close to it. The servo does not need to turn and seek the light, so then directs the program to the Exp_3_stop label. If the condition is not true, the program falls to the next if.then statement and tests again; one of the two statements will be true, and the program will go to the corresponding label. If the left panel's voltage is less than the right panel's voltage, the program branches to Exp_3_Move_Left.

Getting Started With Solar

Getting Started With Solar

Do we really want the one thing that gives us its resources unconditionally to suffer even more than it is suffering now? Nature, is a part of our being from the earliest human days. We respect Nature and it gives us its bounty, but in the recent past greedy money hungry corporations have made us all so destructive, so wasteful.

Get My Free Ebook

Post a comment