hi , i'm trying to make a solar tracking system using gps [GY-NEO6MV2] and Astronomical equations to get (Latitude , Longitude year ,month ,day, local hour, minute, second ) from the {gps} and use these data in the Astronomical equations.
The problem is that i'm VERY new to arduino , so i'm looking for help , because i'm facing many problems.
first :
I'm trying to change the time zone to that of my location , and i've looked everywhere for an answer
but i couldn't find the solution.
Here is the GPS code :
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
void setup(){
Serial.begin(9600);
ss.begin(GPSBaud);
}
void loop(){
while (ss.available() > 0){
gps.encode(ss.read());
if (gps.location.isUpdated()){
// Latitude in degrees (double)
Serial.print("Latitude= ");
Serial.print(gps.location.lat(), 6);
// Longitude in degrees (double)
Serial.print(" Longitude= ");
Serial.println(gps.location.lng(), 6);
// Raw latitude in whole degrees
Serial.print("Raw latitude = ");
Serial.print(gps.location.rawLat().negative ? "-" : "+");
Serial.println(gps.location.rawLat().deg);
// ... and billionths (u16/u32)
Serial.println(gps.location.rawLat().billionths);
// Raw longitude in whole degrees
Serial.print("Raw longitude = ");
Serial.print(gps.location.rawLng().negative ? "-" : "+");
Serial.println(gps.location.rawLng().deg);
// ... and billionths (u16/u32)
Serial.println(gps.location.rawLng().billionths);
// Raw date in DDMMYY format (u32)
Serial.print("Raw date DDMMYY = ");
Serial.println(gps.date.value());
// Year (2000+) (u16)
Serial.print("Year = ");
Serial.println(gps.date.year());
// Month (1-12) (u8)
Serial.print("Month = ");
Serial.println(gps.date.month());
// Day (1-31) (u8)
Serial.print("Day = ");
Serial.println(gps.date.day());
// Raw time in HHMMSSCC format (u32)
Serial.print("Raw time in HHMMSSCC = ");
Serial.println(gps.time.value());
Serial.print("Hour = ");
Serial.println(gps.time.hour());
Serial.print("Minute = ");
Serial.println(gps.time.minute());
Serial.print("Second = ");
Serial.println(gps.time.second());
}
}
}
second :
I'm trying to use the data that i get from the gps in the sun position equations , but i couldn't find a prob way to do it.
Here is the sun position code :
#define DEG_TO_RAD 0.01745329
#define PI 3.141592654
#define TWOPI 6.28318531
void setup() {
int hour,minute=0,second=0,month=6,day=21,year,zone=5;
float Lon=-75*DEG_TO_RAD, Lat=40*DEG_TO_RAD;
float T,JD_frac,L0,M,e,C,L_true,f,R,GrHrAngle,Obl,RA,Decl,HrAngle,elev,azimuth;
long JD_whole,JDx;
Serial.begin(9600);
Serial.print("Longitude and latitude "); Serial.print(Lon/DEG_TO_RAD,3);
Serial.print(" "); Serial.println(Lat/DEG_TO_RAD,3);
Serial.println("year,month,day,local hour,minute,second,elevation,azimuth");
for (hour=10; hour<=24; hour++) {
JD_whole=JulianDate(year,month,day);
JD_frac=(hour+minute/60.+second/3600.)/24.-.5;
T=JD_whole-2451545; T=(T+JD_frac)/36525.;
L0=DEG_TO_RAD*fmod(280.46645+36000.76983*T,360);
M=DEG_TO_RAD*fmod(357.5291+35999.0503*T,360);
e=0.016708617-0.000042037*T;
C=DEG_TO_RAD*((1.9146-0.004847*T)*sin(M)+(0.019993-0.000101*T)*sin(2*M)+0.00029*sin(3*M));
f=M+C;
;Obl=DEG_TO_RAD*(23+26/60.+21.448/3600.-46.815/3600*T);
JDx=JD_whole-2451545;
GrHrAngle=280.46061837+(360*JDx)%360+.98564736629*JDx+360.98564736629*JD_frac;
GrHrAngle=fmod(GrHrAngle,360.);
L_true=fmod(C+L0,TWOPI);
R=1.000001018*(1-e*e)/(1+e*cos(f));
RA=atan2(sin(L_true)*cos(Obl),cos(L_true));
Decl=asin(sin(Obl)*sin(L_true));
HrAngle=DEG_TO_RAD*GrHrAngle+Lon-RA;
elev=asin(sin(Lat)*sin(Decl)+cos(Lat)*(cos(Decl)*cos(HrAngle)));
azimuth=PI+atan2(sin(HrAngle),cos(HrAngle)*sin(Lat)-tan(Decl)*cos(Lat));
Serial.print(year); Serial.print(","); Serial.print(month);
Serial.print(","); Serial.print(day); Serial.print(", ");
Serial.print(hour-zone); Serial.print(",");
Serial.print(minute); Serial.print(","); Serial.print(second);
Serial.print(","); Serial.print(elev/DEG_TO_RAD,3);
Serial.print(","); Serial.print(azimuth/DEG_TO_RAD,3);
Serial.println();
}
}
void loop() {}
long JulianDate(int year, int month, int day) {
long JD_whole;
int A,B;
if (month<=2) {
year--; month+=12;
}
A=year/100; B=2-A+A/4;
JD_whole=(long)(365.25*(year+4716))+(int)(30.6001*(month+1))+day+B-1524;
return JD_whole;
}
Thanks in advance