ISS tracker project, Arduino code not working

Thread Starter

lyxm8d

Joined Sep 10, 2022
4
I'm attempting the following project:
https://create.arduino.cc/projecthu...ime-satellite-orbit-follower-tracker-w-5ef735

I've connected everything up properly, all of the components are working. I've uploaded the code to the arduino uno, changing what I think needs to be changed, but the red LED (meaning the ISS is out of range) is on constantly, even when I've changed the current time in the code to when the ISS should be overhead.
I don't have much experience with coding so I'm not sure if there's something I've missed or something else I need to add. I think it's possibly a problem with the integers epos and apos being set to equal zero, as this is what causes the red LED to turn on. This is the code I used (with the changes I've made):

Code:
#include <TimeLib.h>
#include <ArduinoP13.h>
#include <Servo.h>

Servo elevation;
Servo azimuth;

// Current UTC [NOT LOCAL TIME]
int CurrentHour   = 20;
int CurrentMin    = 20;
int CurrentSec    = 00;
int CurrentDay    = 22;
int CurrentMonth  = 9;
int CurrentYear   = 2022;

// Set TLEs of your desired Satellite
const char *tleName = "ISS";
const char *tlel1   = "1 25544U 98067A   22264.34024677  .00027245  00000+0  48016-3 0  9990";
const char *tlel2   = "2 25544  51.6428 220.2201 0002499 280.2153 244.2840 15.50209155360097";



// Set your Callsign and current location details
const char  *pcMyName = "S21TO";     // Observer name
double       dMyLAT   = +53.415150;    // Latitude (Breitengrad): N -> +, S -> -
double       dMyLON   = -2.917480;    // Longitude (Längengrad): E -> +, W -> -
double       dMyALT   = 67;        // Altitude ASL (m)




int rangePin = 7;   // LED for in Range Indication
int NrangePin = 6;  // LED pin for Out of range indication


int epos = 0;
int apos = 0;

double       dSatLAT  = 0;           // Satellite latitude
double       dSatLON  = 0;           // Satellite longitude
double       dSatAZ   = 0;           // Satellite azimuth
double       dSatEL   = 0;           // Satellite elevation

char         acBuffer[20];           // Buffer for ASCII time



void setup()
{
  setTime(CurrentHour,CurrentMin,CurrentSec,CurrentDay,CurrentMonth,CurrentYear);

  elevation.attach(9);
  azimuth.attach(10);

  elevation.write(epos);
  azimuth.write(apos);

  pinMode(NrangePin, OUTPUT);
  pinMode(rangePin, OUTPUT);

  Serial.begin(9600);
  delay(10);

  digitalWrite(NrangePin, HIGH);
  digitalWrite(rangePin, HIGH);
  delay(5000);
  }


void loop()
{

  char buf[80];

  int i;
  int          iYear    = year(2022);        // Set start year
  int          iMonth   = month(9);       // Set start month
  int          iDay     = day(22);         // Set start day
  int          iHour    = hour(14);        // Set start hour [ substract -6 from current time ]
  int          iMinute  = minute(20);      // Set start minute
  int          iSecond  = second(0);      // Set start second



  P13Sun Sun;                                                       // Create object for the sun
  P13DateTime MyTime(iYear, iMonth, iDay, iHour, iMinute, iSecond); // Set start time for the prediction
  P13Observer MyQTH(pcMyName, dMyLAT, dMyLON, dMyALT);              // Set observer coordinates

  P13Satellite MySAT(tleName, tlel1, tlel2);                        // Create ISS data from TLE

  MyTime.ascii(acBuffer);             // Get time for prediction as ASCII string
  MySAT.predict(MyTime);              // Predict ISS for specific time
  MySAT.latlon(dSatLAT, dSatLON);     // Get the rectangular coordinates
  MySAT.elaz(MyQTH, dSatEL, dSatAZ);  // Get azimut and elevation for MyQTH

  Serial.print("Azimuth: ");
  Serial.println(dSatAZ,2);
  Serial.print("Elevation: ");
  Serial.println(dSatEL,2);
  Serial.println("");



  delay(500);


  // Servo calculation
  epos = (int)dSatEL;
  apos = (int)dSatAZ;

  if (epos < 0) {
      digitalWrite(NrangePin, HIGH);
      digitalWrite(rangePin, LOW);
  } else {
      digitalWrite(NrangePin, LOW);
      digitalWrite(rangePin, HIGH);

      if(apos < 180) {
        apos = abs(180 - (apos));
        epos = 180-epos;

      } else {
        apos = (360-apos);
        epos = epos;
      }
      azimuth.write(apos);
      delay(15);  
      elevation.write(epos);       
  }
}

Is there a specific reason why it isn't working? Is there anything I should've changed with the code?

Any help would be appreciated :)

Moderators note : added code tags
 
Last edited by a moderator:
Top