Components and supplies
Arduino Plug and Make Kit
Apps and platforms
Arduino Cloud
arduino IDE
Project description
Code
ISSTracker
csharp
ISS tracker code
1#include "arduino_secrets.h" 2#include "thingProperties.h" 3#include <math.h> 4#include "Arduino_LED_Matrix.h" 5#include "drawings.h" 6#include <ArduinoJson.h> 7#include <ArduinoHttpClient.h> 8#include <Modulino.h> 9 10ArduinoLEDMatrix matrix; 11 12ModulinoPixels leds; 13 14// Keeps track of which direction the ISS should be going on the LED matrix 15bool dirSwitch = false; 16 17// Variables for keeping track of distances 18float distance; 19 20// Enter your coordinates here: 21float myLongitude = 13.048218; 22float myLatitude = 55.594189; 23 24// These variables will hold the ISS coordinates 25float spaceLong, spaceLat; 26String timeOfDay; 27 28void setup() { 29 // Initialize serial and wait for port to open: 30 Serial.begin(9600); 31 // This delay gives the chance to wait for a Serial Monitor without blocking if none is found 32 delay(1500); 33 34 matrix.begin(); 35 36 Modulino.begin(); 37 leds.begin(); 38 39 // Defined in thingProperties.h 40 initProperties(); 41 42 // Connect to Arduino IoT Cloud 43 ArduinoCloud.begin(ArduinoIoTPreferredConnection); 44 45 /* 46 The following function allows you to obtain more information 47 related to the state of network and IoT Cloud connection and errors 48 the higher number the more granular information you’ll get. 49 The default is 0 (only errors). 50 Maximum is 4 51 */ 52 setDebugMessageLevel(2); 53 ArduinoCloud.printDebugInfo(); 54} 55 56void loop() { 57 ArduinoCloud.update(); 58 59 // Calls a function that will get the ISS position 60 getISSposition(); 61 62 isslocation = Location(spaceLat, spaceLong); 63 64 // Calculate distance in km 65 calculateDistanceInKm(); 66 67 // Display time of day with the Modulino pixels 68 displayLEDs(); 69 70 // Checking the distance and drawing on the LED Matrix according to how close the ISS is 71 if (distance > 2500){ 72 matrix.loadFrame(furthestAway); 73 dirSwitch = false; 74 } 75 76 if (distance < 2500){ 77 if(dirSwitch == true){ 78 matrix.loadFrame(leavingFar); 79 } 80 else{ 81 matrix.loadFrame(farAway); 82 } 83 } 84 85 if (distance < 1500){ 86 if(dirSwitch == true){ 87 matrix.loadFrame(leaving); 88 } 89 else{ 90 matrix.loadFrame(gettingCloser); 91 } 92 } 93 94 if (distance < 500){ 95 matrix.loadFrame(contact); 96 dirSwitch = true; 97 } 98 99 delay(15000); 100} 101 102void getISSposition() { 103 int httpPort = 443; 104 char serverAddress[] = "api.wheretheiss.at"; // server address 105 WiFiSSLClient wifi; 106 HttpClient client = HttpClient(wifi, serverAddress, httpPort); 107 108 client.get("/v1/satellites/25544"); 109 110 String result = client.responseBody(); // Collects the API response 111 112 if (result > 0) { 113 DynamicJsonDocument doc(32000); 114 deserializeJson(doc, result); 115 116 //Sorts the information from the API call 117 spaceLong = doc["longitude"]; 118 spaceLat = doc["latitude"]; 119 timeOfDay = String(doc["visibility"]); 120 } 121} 122 123void calculateDistanceInKm() { 124 int R = 6371; // Radius of the earth in km 125 float converter = M_PI/180; 126 float calculateLat = (spaceLat-myLatitude) * converter; 127 float calculateLon = (spaceLong-myLongitude) * converter; 128 float a = sin(calculateLat/2) * sin(calculateLat/2) + cos(myLatitude * converter) * cos(myLongitude * converter) * sin(calculateLon/2) * sin(calculateLon/2); 129 float c = 2 * atan2(sqrt(a), sqrt(1-a)); 130 distance = R * c; // Distance in km 131} 132 133void displayLEDs() { 134 //Sets the leds to yellow 135 if(timeOfDay == "daylight"){ 136 for (int i = 0; i < 8; i++) { 137 leds.set(i, 100, 100, 0, 25); 138 leds.show(); 139 } 140 } 141 //Sets the leds to blue 142 if(timeOfDay == "eclipsed") { 143 for (int i = 0; i < 8; i++) { 144 leds.set(i, BLUE, 10); 145 leds.show(); 146 } 147 } 148}
drawings.h
csharp
LED Matrix drawings
1const uint32_t furthestAway[] = { 2 0x0, 3 0x600, 4 0x60ffffff 5}; 6 7const uint32_t farAway[] = { 8 0xe00c0000, 9 0x600, 10 0x60ffffff 11}; 12 13const uint32_t gettingCloser[] = { 14 0x3c018000, 15 0x600, 16 0x60ffffff 17}; 18 19const uint32_t contact[] = { 20 0xf006000, 21 0x600, 22 0x60ffffff 23}; 24 25const uint32_t leaving[] = { 26 0x3c01800, 27 0x600, 28 0x60ffffff 29}; 30 31const uint32_t leavingFar[] = { 32 0x700300, 33 0x600, 34 0x60ffffff 35};
Downloadable files
ISS tracker schematic
ISS tracker schematic
isstracker_schematic.png
Comments
Only logged in users can leave comments
aq31
6 days ago
the code was not completely good here is the correction: #include "arduino_secrets.h" #include “thingProperties.h” #include <math.h> #include "Arduino_LED_Matrix.h" #include "drawings.h" #include <ArduinoJson.h> #include <ArduinoHttpClient.h> #include <Modulino.h> ArduinoLEDMatrix matrix; Modulino LED pixels; // Keeps track of which direction the ISS should be going on the LED matrix bool dirSwitch = false; // Variables for keeping track of distances float distance; // Enter your coordinates here: float myLongitude = 1.4442469; float myLatitude = 43.6044622; // These variables will hold the ISS coordinates float spaceLong, spaceLat; String timeOfDay; void setup() { // Initialize serial and wait for port to open: Serial.begin(9600); // This delay gives the chance to wait for a Serial Monitor without blocking if none is found delay(1500); matrix.begin(); Modulino.begin(); leds.begin(); // Defined in thingProperties.h initProperties(); // Connect to Arduino IoT Cloud ArduinoCloud.begin(ArduinoIoTPreferredConnection); /* The following function allows you to obtain more information related to the state of network and IoT Cloud connection and errors the higher number the more granular information you’ll get. The default is 0 (only errors). Maximum is 4 */ setDebugMessageLevel(2); ArduinoCloud.printDebugInfo(); } void loop() { ArduinoCloud.update(); // Calls a function that will get the ISS position getISSposition(); // Calculate distance in km calculateDistanceInKm(); // Display time of day with the Modulino pixels displayLEDs(); // Checking the distance and drawing on the LED Matrix according to how close the ISS is if (distance > 2500) { matrix.loadFrame(furthestAway); dirSwitch = false; } else if (distance < 2500) { if (dirSwitch) { matrix.loadFrame(leavingFar); } else { matrix.loadFrame(farAway); } } else if (distance < 1500) { if (dirSwitch) { matrix.loadFrame(leaving); } else { matrix.loadFrame(gettingCloser); } } else if (distance < 500) { matrix.loadFrame(contact); dirSwitch = true; } delay(15000); } void getISSposition() { int httpPort = 443; char serverAddress[] = "api.wheretheiss.at"; // server address WiFiSSLWi-fi client; HttpClient client = HttpClient(wifi, serverAddress, httpPort); client.get("/v1/satellites/25544"); String result = client.responseBody(); // Collects the API response if (result.length() > 0) { DynamicJsonDocument doc(32000); deserializeJson(doc, result); // Extracts the information from the API call spaceLong = doc["longitude"]; spaceLat = doc["latitude"]; timeOfDay = String(doc["visibility"]); } } void calculateDistanceInKm() { int R = 6371; // Radius of the earth in km float converter = M_PI / 180; float calculateLat = (spaceLat - myLatitude) * converter; float calculateLon = (spaceLong - myLongitude) * converter; float a = sin(calculateLat / 2) * sin(calculateLat / 2) + cos(myLatitude * converter) * cos(myLongitude * converter) * sin(calculateLon / 2) * sin(calculateLon / 2); float c = 2 * atan2(sqrt(a), sqrt(1 - a)); distance = R * c; // Distance in km } void displayLEDs() { // Set the LEDs to yellow if (timeOfDay == "daylight") { for (int i = 0; i < 8; i++) { leds.set(i, 100, 100, 0, 25); leds.show(); } } // Set the LEDs to blue else if (timeOfDay == "eclipsed") { for (int i = 0; i < 8; i++) { leds.set(i, 0, 0, 100, 25); leds.show(); } } }