How to calculate local sidereal time on an Arduino or other PIC microcontroller

What is local sidereal time?

Local sidereal time is a crical piece of information required for telescope pointing. IF you are making an Arduino control syste for your mount, you will need to start with this calculation. Local sidereal time links time and Right Ascension. 00:00 LST is defined as the time at which the 0h line of RA passes the meridian in your location. Therefore you can use it to calculate the current hour angle for a target of known RA at your location.

How is it caculated

There are three parts

This is complicated on an 8bit microcontroller like the Arduino because normally you only have 4 byte floats to work with and no 8 byte doubles.

double M,Y,D,MN,H,S;
double A,B,C,E,F;

//fill integers with data from real time clock, or other wource
M = (int) month;
Y = (int) year+2000;
D = (int) dayOfMonth;
MN = (int) minute;
H = (int) hour;
S = (int) second;

if (M<3) {M+=12; Y-=1;}

A = (long)Y/100;
B = (long)A/4;
C = (long)2-A+B;
E = (long)(365.25*(Y+4716));
F = (long)(30.6001*(M+1));
CurrentJDN = C+D+E+F-1524.5;

//calculate terms required for LST calcuation and calculate GMST using an approximation
Current_d = CurrentJDN - 2451545.0;
Current_T = Current_d / 36525;

HourLastUpdatedJDN = hour;
DayLastUpdatedJDN = dayOfMonth;

H = H + ((double)MN/60) + ((double)S/3600);

float GMST;
float Term3;

GMST = Term1 + Term2 + Term3;

//add on longitude to get LST
LST = GMST + location->GetLong_over15;

//reduce it to 24 format
int LSTint;
LSTint = (int)LST;
LST = LST - (double) LSTint * 24;


What do I use it for on my Arduino Mega?

My homemade mount code on the Arduino Mega 1280 uses calls to this routine more than any other function in the C code. Every aspect of doing calculations on the Arduino Mega boards for astronomy requires you to know local sidereal time.

For example, when I turn the mount on it is in a polar home position with an hour angle of +90 degrees. At this point Arduino reads the current encoder count on the polar axis as zero. Arduino