Visual Basic Sun Tracking / Heliostat Program

Subscribe to my Feed!

Update: This program is basically the older version of the Arduino Sun Tracking / Heliostat Program. This program is less capable but still probably useful to someone. The source code in particular could come in handy. I’m not using it anymore though, so you won’t likely see it updated again.

Bug: There is a known bug in the calculations which find the altitude and azimuth for the heliostat. It only occurs when using angles that are far away from zero, so in most instances you can avoid it. The Arduino Sun Tracking / Heliostat Program does not suffer from this issue, so you should be able to translate the code from it if this is an problem for you.


Here is a program that will calculate the angles needed to correctly position a heliostat. It will then send signals through the computer’s parallel port in order to control the stepper motors which will move the heliostat to its correct orientation.

The program can also be used to track the sun directly so that it can be used with solar concentrators or solar panels.

The program’s name is “Sun Tracker.” It is named after what it does. (I have a serious lack of imagination when it comes to naming things.)

The program is still beta, and I already know that there are some problems with it. It gets the job done though, so I don’t complain. Here is a quick overview of what this program can do.

With this free Sun Tracking / Heliostat Program, you can:

1. Control up to two heliostats with a PC.

2. Program up to 10 targets for each heliostat. Simply click on the target you want to reflect the light towards, and it will automatically adjust to the correct angles.

3. Choose the sun as a target for either heliostat (or both) turning it into a sun tracking machine.

4. Add homing switches to your heliostat so that you can automatically reset its position with just a click of the mouse.

Installing the Program

The program’s current version is 0.9.1 and you can download it by clicking here.

Unzip the “Sun Tracker” folder and open it.

The first thing you should do is find the file named “inpout32.dll” and move it to the directory C:\WINDOWS\system32.


Finally, click “Sun Tracker.application” to install and run the program. It should now appear under the start menu.

If you need to uninstall it, you can do so under add or remove programs in control panel.

Source Code

If you are interested in taking a look at the source code, you can find it on this page. Sun Tracker Program’s Source Code

Making sure that Your Parallel Port Works

One thing that you want to check before you get too far is if your parallel port on your computer works correctly with this program. I have a separate tutorial to help you check it on this page Making sure that Your Parallel Port Works.

Main Interface

This is the main interface for the Sun Tracker Program. Here, you can program in the name, altitude, and azimuth for up to ten targets. Before it will work correctly though, you will need to do go through “Settings” first.

Note: The program may appear as though it has crashed when moving the heliostat(s). Simply wait patiently until it is finished for control to be restored.


Setting up the Sun Tracking / Heliostat Program

Setting up the Sun Tracking / Heliostat Program only takes a couple of minutes once you know what you are doing. If your unfamiliar with things like stepper motors, gear ratios, and driver boards though, the “Settings” window might seem a little daunting. Try not to look at it all at once. Instead, focus on little sections of it at a time.

If you look closely, you will notice that both the left and right sides of the settings window are almost identical. The only difference is that one side is for Machine#1 and the other side is for Machine#2.

settings []

If you look even closer, you will see that the setup for both the altitude and the azimuth stepper motors is also identical. For the rest of this tutorial, we will focus on just one stepper motor column as the process is same for each.

First though, we will take a look at the middle column.

Time Interval

The first option under “settings” is to change time interval. The sun moves across the sky slowly, so updating the position of the heliostat every second is overkill. If you were to replace the 1 with 60, it would be updated only once a minute. However, this is optional. Although increasing the time interval uses less of your computer’s resources, it will also make the program seem less responsive when switching to different targets. You will likely have to wait for the time to elapse before it will move.


Where to Find Your Latitude and Longitude

Check out the page How to Find Your Latitude and Longitude for information on finding your latitude and longitude.

Decimal Degrees

If they haven’t been already, the latitude and longitude must be converted into decimal degrees.

For example: N 30 11′ 15.9″ will instead be 30.187750

Here is a website which will do the conversions for you.

Positive or Negative Lat and Long



Make sure you type in the latitude as…

a  Negative number if you’re in the Southern hemisphere

a  Positive number if you’re in the Northern hemisphere.


Make sure you type in the longitude as…

a Negative number if you’re in the Western hemisphere
a Positive number if you’re in the Eastern hemisphere.

North is Zero


Selecting the “North is Zero” option will make it so that the azimuth’s “zero” will be at north instead of the default south. If you live in the northern hemisphere (positive latitude), you would want to leave this box unchecked.

If you live in the southern hemisphere, you would want to go ahead and select it. (I haven’t tested this option personally because I live in the northern hemisphere, so be careful with it. I need someone in the southern hemisphere with a heliostat or sun tracking machine to confirm that it works.)

This will make the starting position of the heliostat flip 180 degrees and point north instead of south. That way, it will be facing in the general direction of the sun in the southern hemisphere.

Steps per Revolution

The first thing you need to do to set up your stepper motors is to input their “Steps Per Revolution.” This number will depend on your driver board, so you should check its documentation for the correct setting. A few examples of typical “Steps/Rev.” input are: 200, 400, 800, 1600.

stepper motor setup

Step Pin# and Direction Pin#

The correct “Step Pin#” and “Direction Pin#” can be found with your driver boards documentation. An example of a driver board would be the Hobby CNC EZ Driver Board kit, which is what I personally am using right now.

For this board, it says pin 2 is a step pin and pin 3 is a direction pin. I can only use these pins for the altitude stepper motor though. For the azimuth stepper motor, I use pin 4 for the step pin and pin 5 for the direction pin. This driver board is able to drive three stepper motors, but I only need two, so I have pins 6 and 7 left unused.

Reverse Direction

The “Reverse Direction” checkbox is pretty straight forward. If you find that one of your stepper motors is moving in the direction opposite from what you want, either select of deselect this box to fix it.

stepper speed and direction


Motor Speed

The “Motor Speed” box will make the stepper motor go either faster or slower. The speed also depends on your computer as well. A faster computer will naturally try to run the stepper motors at a faster speed while a slower computer will do the opposite.

If your motors are spinning either too fast or too slow and you can’t adjust them enough in the program, let me know. I might need to make some changes to the program to compensate.

Limit Switch

Setting up limit switches on your machine is optional but useful. Here, you can tell the program where your home switches are located. This will allow the program to “Automatically Realign” the heliostat. The “Automatically Realign” feature is explained later in this tutorial.

limits on off

limit switch location

Gear Ratio

Note: Ignore these instructions if your machine has a lever arm set up.
The “Gear Ratio” text box allows you to input the correct gear ratio for each axis. For example, if it takes the stepper motor 100 rotations for the heliostat to turn 360 degrees, then you would want to input 100 here.

altitude gear ratio

Lever Arm Set Up

If your heliostat or sun tracking design uses lever arms to move the machine, select the “Lever Arm Yes/No” checkbox. If it doesn’t use lever arms, leave the box unchecked and skip to the “Back to the Main Interface” section below.

lever arm yes or no

Next, you will need to set the gear ratio (look above “Lever Arm Yes/No”) to the number of threads per inch your leadscrew has. For example, the leadscrews on my heliostat have 18 threads per inch, so I would want to type 18 here.

Note: I am using inches, but you can also use metric units.

After you have set the gear ratio, you will then need to input lengths A and B in the lever arm set up.

length a and b

If you look at the picture below, you will see what is meant by lengths A and B. This picture is of the heliostat’s side perspective. The leadscrew is set up to tilt the mirror either forward or backward which will either increase or decrease its altitude.

Note: I am only using the altitude in the examples, but the process for the azimuth is the same.

heliostat setup

Length A is the distance from the mirror’s pivot point to the end of the leadscrew.

Length B is the distance from the mirror’s pivot point to where the stepper motor rotates.

Note: Length A and Length B can be reversed. It doesn’t matter which box you put them in.

The next thing to do is to decide whether the lever arm’s “triangle” will turn into either an acute triangle or an obtuse triangle when the heliostat’s altitude moves in a positive direction.

acute yes or no

Let me try and clarify this with a couple of pictures. If you look at the picture on the left, you will see that the mirror has rotated up in the positive direction. In doing so, the triangle created by the end of leadscrew, mirror pivot, and stepper motor points has turned from the 90 degree triangle seen above into an acute triangle.

If you look at the picture on the right, however, you will see that the leadscrew attaches to the mirror on its opposite side. In this example, rotating the mirror in the positive direction will turn the triangle created by the end of leadscrew, mirror pivot, and stepper motor points into an obtuse triangle.


Selecting the “Acute Yes/No” checkbox simply lets the Sun Tracker program know which side of the mirror the leadscrew attaches. Checked means acute, unchecked means obtuse.

One final and important note regarding the starting position of the heliostat is that the angle for both the altitude and azimuth lever arms must be at 90 degrees at this position. If they aren’t, the heliostat will not work correctly.

The starting position of the heliostat is where both the altitude and the azimuth of the mirror equal zero. The altitude is at zero when the mirror is plumb. The azimuth is at zero when the mirror runs parallel to geographic east and west.

To achieve this, the heliostat must be aligned properly when you are setting it up.


Back to the Main Interface

Now that you are finished programming in the settings for your machine(s), we will see what the main interface has to offer.


Manually Realign

“Manually Realign” is used when your heliostat doesn’t have limit switches. The idea is to move it most of the way with the stepper motors before doing the final, more precise, alignment by hand.

Once the precise alignment is finished, you can also use the manually realign feature to verify that your heliostat is working correctly. For example, if you tell the heliostat to move +5 degrees along the azimuth and it moves -5 degrees, you would know that you need to reverse the motor direction in settings.


If you type in -10 under “Altitude” and press “Go” the heliostat’s altitude will move down 10 degrees. If you are already at -10 degrees and press go again, nothing will happen.

If you then type -20 and press “Go” the heliostat will move down another 10 degrees, not 20 degrees like you might expect.

If you are at -20 degrees and type -10 the heliostat will actually move UP 10 degrees.

The direction the heliostat moves is based off of its initial position.

Once you are finished manually adjusting the heliostat, click “Reset to Zero” to finalize the position as zero for both the altitude and the azimuth.

Automatically Realign

If you have limit switches on your heliostat, you can use the “Automatically Realign” button instead of realigning it manually. Simply push this button and the heliostat will move toward the limit switch until it triggers it. Once triggered, it will move in the opposite direction until it reaches its home position.

Note: I will have more information on how to do this when I finally get my tutorial together for building a heliostat, so hold tight.

Reporting Problems and Offering Suggestions

Here is a thread on the forums where you can report any problems with this program. I can’t absolutely guarantee that I will be able to fix them, but I will try.

Additionally, even if it works perfectly for you, please let me know. It would put my mind at ease knowing that it works the way it is supposed to. :)

Subscribe to my Feed!