The supporting library, TimeLib for Arduino, by PaulStoffregen
A Sun Positioning Algorithm (SPA) utilizing only time and coordinates as the external inputs.
The Sun Positioning Algorithm (SPA) makes use of the local observer time and coordinates to calculate the topocentric solar azimuth and elevation angles based on the algorithm flowchart specified in Figure 1.
To use the Sun Positioning Algorithm routines, import the C++ header:
#include <SolarTracker.h>The time_t variable type is used extensively throughout the algorithm and in other various time computations as defined by ISO C. For additional context visit: https://en.cppreference.com/w/c/chrono/time_t.
The following utility functions are available for computing angles:
This returns the struct object for elevation and azimuth angles
SolarTrackerStruct getSolarPosition(time_t t);This returns the float value for elevation angle
float getSolarElevation(time_t t); //returns a float for elevation angleThis returns the float value for azimuth angle
float getSolarAzimuth(time_t t); //returns a float for azimuth angleThe main compute function for angle calculations is declared as:
calculateSolarPosition(time_t tParam, float Latitude, float Longitude); //performs computation for calculating solar positionThe algorithm is based on various astronomical almanacs that provide a backbone to the mathematical structure of the algorithm. The process of computing angles works in accordance to the following flowchart:
This codebase is copyright Obed Ahmad and licensed with the MIT license.