# Difference between revisions of "Solar Arduino tracker"

German version Sonnenstandsberechner (für sun tracker devices)

# General considerations

For calculating the solar position with a microcontroller (on a fixed geographic place) you have to solve two problems: The controller needs a time device (typically a battery buffered chip like in a PC) and it needs a reasonably simple algorithm to calculate solar azimuth and elevation from date, time and geographic position (longitude and latitude). An algorithm which works on a PC might have problems on a microcontroller. For instance, on Arduino you must take into account that double data type has the same precision as float (IEEE 23 bit mantissa)

## Get the Time

timer chip DS1307 with Arduino

To get Greenwich Time (aka UT) I use a DS1307 chip. Following the description of http://www.glacialwanderer.com/hobbyrobotics/?p=12 it worked immediately. Did not find any 2.2K resistors, 4.7K ones are just as fine. I have taken the code from that site and tucked the complexity into an Arduino libary (DS1307H.h)

## Calculate Azimuth and Elevation

The formulas for exact calculation of solar azimuth and elevation are very involved. However, for practical purposes like sun tracking of a heliostat there are simpler ones available. Widely used formulas for solar tracking are the one from the so called PSA-algorithm. It has been made avaible from Plataforma Solar de Almeria (Spain) and you can download it here as C++ code. There are adaptions neccessary for Arduino, though. The formulas for calculating the Julian Day are not working properly on Arduino due to reduced double precision. Therefore, I have adapted them, expecting only Julians dates starting from 1.Jan. 2000. These calculations I have put into another library (Helios.h)

 SolarTracker4Arduino.zip (14KB) [info]Version from 09.03.2011

Once you got it running, verify the calculated positions, for instance with solar position calculator from sunearthtools. (Attention: SolarTracker4Arduino does NOT account for daylight saving time (DST), you have to determine UT as if there was no DST at all.)

## SPA Algorithm

A much more accurate solar algorithm seems to be from Reda, I.; Andreas, A. (2003): Solar Position Algorithm for Solar Radiation Applications. NREL Report No. TP-560-34302, Revised January 2008. The algorithm is supposed to work for the years -2000 to 6000, with uncertainties of +/-0.0003 degrees. In this paper methods have been worked out according to the book from Jean Meeus: Astronomical Algorithms, Willmann-Bell, Richmond 2000 (2nd ed., 2nd printing) a well known text book for astronomic calculations. The calculations are, however, very extensive; for Arduino I chose the simpler PSA. Implementations and references for both algorithms I found thanks to the code from Klaus Brunner. It was also a valuable help for debugging the Arduino implementation.

--Hannes.hassler 13:36, 3 March 2011 (CET)