I have wanted to thoroughly check the output error of the Arduino Sun Position Calculations for quite some time now, but never had the chance until now. Overall, it’s actually not as bad as I had assumed. It’s not amazing either, but for an 8-bit microcontroller, it’s still impressive.
This page explains how I analyzed the error for the sun position calculations and then shows the results of this analysis in terms of both sun and heliostat tracking.
Note that the error determination given on this page is only valid for the Arduino sun calculations that use the hour angle approximation table. In the near future (if it hasn’t already been done), I will be releasing a version of the Sun Tracking / Heliostat Program that runs on the Arduino Mega which will use a different set of algorithms that are much more accurate. Update: This has already been done, scroll towards the bottom of the page to see the error output for the Arduino Mega.
How These Calculation Errors were Determined
The error values were determined by using a serial connection to feed the output of the Arduino into MatLab. Once this was done, the Arduino’s output values could then be compared with the much more accurate values calculated with MatLab.
These values were generated for the hours 6:00 to 22:00 every day from the beginning of 2012 to the end of 2021, which is ten years. In all, the calculations were checked at 63,240 different times.
These values were also calculated at an arbitrary latitude and longitude (OK, my latitude and longitude); however, the lat and long shouldn’t have an effect on the overall error.
Sun Position Error
The error in the sun’s position summarizes nicely to just two values.
The maximum deviation from the sun is 0.9111 degrees.
The average deviation from the sun is 0.4240 degrees.
It is worth noting that even with an error of 0.9111 degrees a sun tracker will still collect 99.987% of the energy that it would if the error was zero.
The plot of all of the error values is shown below with the number of days from January 1st, 2012 on the x-axis and the absolute error on the y-axis.
This next plot is almost the same as the one above, except that it only goes for 365 days.
The effect the errors in the sun’s calculated position have on the accuracy of a heliostat was determined by finding the distance between the correct target and the target that the heliostat actually reflected the light at.
To clarify, the red dot in the picture below shows where we want the light from the heliostat to go. The yellow dot, however, is where the light actually ends up. The distance between the center of these two dots is the error.
Note that the error in this case is a distance where as when we were checking the sun position calculations we were measuring the error as an angle.
For this test, the target’s altitude and azimuth were both zero degrees, and the target was placed ten units away from the heliostat. Notice that I said “units.” This is because the exact system of measurement does not matter. You could think of these values as being in feet, meters, centimeters, or miles. To keep things straight forward though, we will use meters.
Over the ten year period, we have the following values for the maximum and average error.
Max Error = 0.1473 meters
Average Error = 0.0701 meters
The error scales linearly as the target is moved farther and farther away from the heliostat. So, with the target set 10 meters away from the heliostat the reflected light can be up to 0.1473m away from the target. If the target was moved 5 times further from the heliostat to 50 meters, the reflected light could be up to 5 x 0.1473 = 0.7365m away from the target.
Overall, the accuracy is decent, but not amazing. As long as your target is large enough to accommodate some drift though, it should be perfectly fine for the job.
The image below is an example of how the center of the reflected light will drift throughout the year. If the accuracy was perfect, all of the blue circles would be centered at (0,0). Instead though, the reflected light might be above, below, to the right, or to the left of the target.
This next image is basically the same as the one above except it has all of the values for the full ten years.
Update: Sun Calculations on the Arduino Mega Error Analysis
With its excessive amount of program space, the Arduino Mega allows for the use of more accurate sun position calculations. The Mega is still just an 8-bit microcontroller, but by using the “Arbitrary Precision / Big Number” library it is possible to extend its capabilities to double precision math (or even much further).
Despite this abundance of precision, I still had to take some shortcuts in the code to get everything working. In particular, I had trouble implementing inverse trig functions. They were not built into the library, so I had to write the code from scratch using Taylor series to calculate the values of the inverses.
Everything technically worked, but for whatever reason the use of the Taylor polynomials would grind the whole program to halt after calculating the position of the sun about a half dozen times. I suspect that the issue was perhaps caused by a memory leak, but that is just a guess.
I was able to get around the issue by using the Arduino’s built in inverse trig functions. These functions are less accurate, but as you will see from the tests below, they do not introduce excessive errors to the calculation of the sun’s position or, in turn, the error in a heliostat’s accuracy in reflecting the light at a given target.
How These Calculation Errors were Determined
The way these errors were determined is almost identical to the method described earlier near the top of this page. Instead of calculating the position of the sun between the hours 6 through 22, I did 5 through 22 here (for no particular reason). I also only checked the output over the course of 1 year instead of 10. It would have taken roughly week to go for 1o years since the “Big Number” sun calculations take about 1.2 seconds to calculate the position of the sun just one time. Also, running the calculations for a longer period of time wouldn’t have been especially enlightening in this case.
Note: If you want to better understand the below error output, you can read about it in the previous section on this page. For brevity, I will not repeat it here.
Sun Position Error
The maximum deviation from the sun is 0.0262 degrees.
The average deviation from the sun is 0.0061 degrees.
The below plot shows the number of hours from the beginning of the year on the x-axis and the absolute error on the y-axis.
Again using a target ten units (we’ll say meters just for clarity) away from the heliostat with altitude and azimuth both at zero degrees, we have the following distance errors;
Max Error = 0.0046 meters
Average Error = 0.0011 meters
The below scatter plot shows the errors in the reflected light over the course of the year. (A better explanation for this scatter plot was given previously on this page.)
Overall, the sun position calculations on the Arduino Mega are significantly more accurate than the calculations that are able to fit within the available space of the other Arduino Uno type boards.
Depending on what you are doing though, that extra accuracy might not be needed, so you might prefer to save some money by using the cheaper Arduino Uno type boards.
It’s entirely up to you whichever you decide to use.