ISS tracker with the plug and make kit!
Ever wondered where the ISS is right now? Or how close it is to you? Then this project will solve that mystery!
Components and supplies
1
Arduino Plug and Make Kit
Apps and platforms
1
arduino IDE
1
Arduino Cloud
Project description
Code
drawings.h
csharp
LED Matrix drawings
1const uint32_t farAway[] = { 2 0xe00c0000, 3 0x600, 4 0x60ffffff 5}; 6 7const uint32_t gettingCloser[] = { 8 0x3c018000, 9 0x600, 10 0x60ffffff 11}; 12 13const uint32_t contact[] = { 14 0xf006000, 15 0x600, 16 0x60ffffff 17}; 18 19const uint32_t leaving[] = { 20 0x3c01800, 21 0x600, 22 0x60ffffff 23}; 24 25const uint32_t leavingFar[] = { 26 0x700300, 27 0x600, 28 0x60ffffff 29}; 30 31const uint32_t animation[][4] = { 32 { 33 0x80000, 34 0xc8124212, 35 0x40180000, 36 1 37 }, 38 { 39 0x20, 40 0xc8124212, 41 0x40180000, 42 2 43 }, 44 { 45 0x0, 46 0xc9124212, 47 0x40180000, 48 3 49 }, 50 { 51 0x0, 52 0xc8125212, 53 0x40180000, 54 4 55 }, 56 { 57 0x0, 58 0xc8124a12, 59 0x40180000, 60 5 61 }, 62 { 63 0x0, 64 0xc8124212, 65 0x401a0000, 66 6 67 }, 68 { 69 0x0, 70 0xc8124212, 71 0x50180000, 72 7 73 }, 74 { 75 0x0, 76 0xc8124292, 77 0x40180000, 78 8 79 }, 80 { 81 0x0, 82 0xc8124252, 83 0x40180000, 84 9 85 }, 86 { 87 0x0, 88 0xc8124212, 89 0x42180000, 90 10 91 }, 92 { 93 0x0, 94 0xc8124212, 95 0x40181000, 96 11 97 } 98};
ISS Tracker
c
ISS tracker sketch for UNO R4 WiFi
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 12// Define Modulino Pixels and Buzzer 13ModulinoPixels leds; 14ModulinoBuzzer buzzer; 15 16ModulinoColor DAYTIME_COLOR(100, 100, 0); // Yellow 17ModulinoColor NIGHT_COLOR(0, 0, 100); // Blue 18 19// Define melody for Buzzer 20int melody[] = { 262, 196, 196, 220, 196, 0, 247, 262 }; 21 22int brightness = 25; 23 24// Keeps track of which direction the ISS should be going on the LED matrix 25bool dirSwitch = false; 26 27// Enter your coordinates: 28float myLatitude = 55.611826087732084; // Malmo, Sweden. You can edit this with your location 29float myLongitude = 12.97776190663195; 30 31// Variables for ISS location 32float spaceLong, spaceLat, distance; 33 34// Variable for time of day of ISS 35String timeOfDay; 36 37void setup() { 38 // Initialize serial and wait for port to open: 39 Serial.begin(9600); 40 41 // This delay gives the chance to wait for a Serial Monitor without blocking if none is found 42 delay(1500); 43 44 // Initialize matrix and Modulino 45 matrix.begin(); 46 Modulino.begin(); 47 leds.begin(); 48 buzzer.begin(); 49 50 // Give more time for WiFi connection to stabilize before NTP sync 51 delay(2000); 52 53 // Defined in thingProperties.h 54 initProperties(); 55 56 // Connect to Arduino IoT Cloud 57 ArduinoCloud.begin(ArduinoIoTPreferredConnection); 58 59 // Allow time for NTP sync to complete 60 delay(1000); 61 62 setDebugMessageLevel(2); 63 ArduinoCloud.printDebugInfo(); 64 65 // Print a message to confirm coordinates are set for Guatemala City 66 Serial.println("ISS Tracker initialized for Guatemala City"); 67 Serial.print("Latitude: "); 68 Serial.print(myLatitude, 6); 69 Serial.print(", Longitude: "); 70 Serial.println(myLongitude, 6); 71} 72 73void loop() { 74 // Handle IoT Cloud updates 75 ArduinoCloud.update(); 76 77 // Print a message showing we're attempting to get ISS position 78 Serial.println("Fetching ISS position..."); 79 80 // Calls a function that will get the ISS position 81 getISSposition(); 82 83 // If we successfully got ISS data 84 if (spaceLat != 0 && spaceLong != 0) { 85 Serial.print("ISS Position - Lat: "); 86 Serial.print(spaceLat, 6); 87 Serial.print(", Long: "); 88 Serial.println(spaceLong, 6); 89 90 // Calculate distance in km 91 calculateDistanceInKm(); 92 93 // Update cloud variable with ISS location 94 isslocation = Location(spaceLat, spaceLong); 95 displayDistance = distance; 96 97 // Update visibility and message based on distance 98 if (distance < 400) { 99 visibility = 100; 100 message = "Eyes to the sky ISS is here!"; 101 } else if (distance < 600) { 102 visibility = 90; 103 message = "Get ready ISS almost in-view!"; 104 } else if (distance < 1000) { 105 visibility = 70; 106 message = "ISS approaching - prepare for sighting"; 107 } else if (distance < 1500) { 108 visibility = 50; 109 message = "ISS detected in your region"; 110 } else if (distance < 2000) { 111 visibility = 30; 112 message = "ISS approaching your area"; 113 } else if (distance < 2500) { 114 visibility = 10; 115 message = "ISS in tracking range"; 116 } else { 117 visibility = 0; 118 message = "ISS too far for viewing"; 119 } 120 121 Serial.print("ISS Distance: "); 122 Serial.print(distance); 123 Serial.print(" km, Visibility: "); 124 Serial.println(timeOfDay); 125 126 // Display time of day with the Modulino pixels 127 displayLEDs(); 128 } else { 129 Serial.println("Failed to get ISS position data"); 130 } 131 132 // Checking the distance and drawing on the LED Matrix according to how close the ISS is 133 if (distance > 3500) { 134 matrix.loadSequence(animation); 135 for(int x = 0; x < 11; x++){ 136 uint32_t nr = x; 137 matrix.renderFrame(nr); 138 delay(3000); 139 matrix.next();} 140 dirSwitch = false; 141 Serial.println("ISS is very far away"); 142 } else if (distance < 1000) { 143 for (int i = 0; i < 8; i++) { 144 int note = melody[i]; 145 buzzer.tone(note, 250); 146 delay(250);} 147 matrix.loadFrame(contact); 148 dirSwitch = true; 149 Serial.println("ISS is extremely close!"); 150 delay(5000); 151 } else if (distance < 2500) { 152 if (dirSwitch) { 153 matrix.loadFrame(leaving); 154 Serial.println("ISS is leaving"); 155 } else { 156 matrix.loadFrame(gettingCloser); 157 Serial.println("ISS is getting closer"); 158 } 159 delay(5000); 160 } else { // This covers 2500-3500 km 161 if (dirSwitch) { 162 matrix.loadFrame(leavingFar); 163 Serial.println("ISS is moving farther away"); 164 } else { 165 for (int i = 0; i < 8; i++) { 166 int note = melody[i]; 167 buzzer.tone(note, 250); 168 delay(250);} 169 matrix.loadFrame(farAway); 170 Serial.println("ISS is far away"); 171 } 172 delay(10000); 173 } 174} 175 176void getISSposition() { 177 int httpPort = 443; 178 char serverAddress[] = "api.wheretheiss.at"; // server address 179 WiFiSSLClient wifi; 180 HttpClient client = HttpClient(wifi, serverAddress, httpPort); 181 182 // Add more helpful debug information 183 Serial.print("Connecting to "); 184 Serial.println(serverAddress); 185 186 // Set timeout for HTTP client to prevent hanging 187 client.setTimeout(10000); 188 189 // Make the API request 190 client.get("/v1/satellites/25544"); 191 192 // Get the status code 193 int statusCode = client.responseStatusCode(); 194 Serial.print("HTTP Status code: "); 195 Serial.println(statusCode); 196 197 if (statusCode != 200) { 198 Serial.println("Failed to get ISS data"); 199 return; 200 } 201 202 String result = client.responseBody(); // Collects the API response 203 204 if (result.length() > 0) { 205 Serial.print("Response length: "); 206 Serial.println(result.length()); 207 208 DynamicJsonDocument doc(32000); 209 DeserializationError error = deserializeJson(doc, result); 210 211 if (error) { 212 Serial.print("JSON parsing failed: "); 213 Serial.println(error.c_str()); 214 return; 215 } 216 217 // Extracts the information from the API call 218 spaceLong = doc["longitude"]; 219 spaceLat = doc["latitude"]; 220 timeOfDay = String(doc["visibility"]); 221 velocity = doc["velocity"]; 222 223 } else { 224 Serial.println("Empty response received"); 225 } 226} 227 228void calculateDistanceInKm() { 229 int R = 6371; // Radius of the earth in km 230 float converter = M_PI / 180; 231 float calculateLat = (spaceLat - myLatitude) * converter; 232 float calculateLon = (spaceLong - myLongitude) * converter; 233 234 float a = sin(calculateLat / 2) * sin(calculateLat / 2) + 235 cos(myLatitude * converter) * cos(spaceLat * converter) * 236 sin(calculateLon / 2) * sin(calculateLon / 2); 237 float c = 2 * atan2(sqrt(a), sqrt(1 - a)); 238 distance = R * c; // Distance in km 239} 240 241// Helper function to set a pixel with a color 242void setPixel(int pixel, ModulinoColor color) { 243 leds.set(pixel, color, brightness); 244 leds.show(); 245} 246 247void displayLEDs() { 248 // Set the LEDs to yellow for daylight 249 if (timeOfDay == "daylight") { 250 for (int i = 0; i < 8; i++) { 251 setPixel(i, DAYTIME_COLOR); 252 delay(25); // Small delay between LEDs for effect 253 } 254 } 255 // Set the LEDs to blue for eclipsed 256 else if (timeOfDay == "eclipsed") { 257 for (int i = 0; i < 8; i++) { 258 setPixel(i, NIGHT_COLOR); 259 delay(25); // Small delay between LEDs for effect 260 } 261 } 262} 263 264void onDisplayDistanceChange() { 265} 266 267void onVisibilityChange() { 268} 269 270void onMessageChange() { 271}
Downloadable files
Connection Guide
overview-001.png

Comments
Only logged in users can leave comments