Need a cool gadget that shows when the ISS is above you? Then check out these cubes!
Whenever the sun has set or not yet risen, you have the opportunity to observe the ISS - assuming it passes overhead.
This device lights up when you have the chance to observe the ISS as it travels around the Earth. Whether it is just dark enough for that, you have to find out yourself. ;-)
To determine the next overflight times for your location, we use the API http://open-notify.org. For this you need your coordinates and optionally the altitude of your location above sea level. If you don't know your coordinates yet, you can use Google Maps or a similar service in order to find them.
The constructionThe NeoPixel LED rings usually don't have cables soldered to them when you buy them. If so, solder 3 cables to these pins first: DI, GND and VCC.
Assembling the ring and the other parts couldn't be easier then. Place your ESP8266 on the mini breadboard. Then connect the LED ring as follows: DI to D4, VCC to 3.3V, GND to... GND.
Print out the attached STL files if you would like to use our design. The upper cube (print it with white filament) has a hidden ISS on the inside that is not visible until the cube lights up – as you can see in the video above. Of course you can also use whatever enclosure you like – or none at all. :)
Notice: If you have never programmed an ESP8266 with your Arduino IDE, please read this tutorial first.
The most important parts of the code are two API queries (one for the current time and one for the next overflight times) and the control of the NeoPixel LED ring. We won't discuss all parts of the sketch but only the most important.
First of all you have to install the required libraries if they are not already installed in your Arduino IDE. So, if necessary, open the library manager of your Arduino IDE and check for the following libraries.
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include <ESP8266HTTPClient.h>
#include <Adafruit_NeoPixel.h>
Next, your code needs your Wifi credentials and your coordinates. Enter them at the top of the sketch. You don't have to enter the altitude of your location, the API call works also without by assuming you're living 100m above sea level.
/*** Your WiFi Credentials ***/
const char* ssid = "your ssid";
const char* password = "your password";
/*** Your coordinates ***/
const float latitude = 00.00;
const float longitude = 00.00;
const float altitude = 100.00;
Controlling the NeoPixelThe library for the NeoPixel LED ring is very easy to use. First declare an object:
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(12, 2, NEO_GRB + NEO_KHZ800);
The first argument (12) is the amount of LEDs installed on the ring. The second is the pin on your ESP8266 the NeoPixel is connected with. D4 is GPIO2.
In your void setup() you provide the following settings:
pixels.begin();
pixels.setBrightness(100);
pinMode (2, OUTPUT); //LED Pin (at ESP8266: D4)
Inside the function pixels.setBrightness you can specify the brightness of the LEDs with a value between 0 (off) and 255.
To make all the ring's LEDs light up in the same color, turn them on one after the other using a for loop. The three values inside pixels.Color() correspond to a specific RGB color value – in this case a bright green.
for (int i = 0; i < 12; i++) {
pixels.setPixelColor(i, pixels.Color(0, 255, 0));
pixels.show();
}
To turn them off use this loop:
for (int i = 11; i >= 0; i--) {
pixels.setPixelColor(i, LOW);
pixels.show();
}
Later we will return to the LED ring, but for now we will take care of the two API calls.
Getting the current timeTo find out how long it will take until the ISS appears above your location, we first need the current time. All times in this project are in the time zone UTC.
We get the time from the following URL:
http.begin("http://worldtimeapi.org/api/timezone/europe/london");
The response is a JSON string that we parse with the library ArduinoJson in order to save the current time in the variable currentTime. For more information about parsing JSON check the website, there is a lot to learn.
Getting the ISS flight dataWe use the API of open-notify.org for the time of the next flyover. In the URL we are heading for are the coordinates and the altitude of your location and the amount of flyovers we want to get (5).
http.begin("http://api.open-notify.org/iss-pass.json?lat=" + String(latitude) + "&lon=" + String(longitude) + "&alt=" + String(altitude) + "&n=5");
Two values interest us in the server's response: the time of the next pass and its duration. We store the first one in the variable riseTime and the duration in the variable duration.
duration = response[0]["duration"];
riseTime = response[0]["risetime"];
However, if the first pass in the answer is already over (riseTime < currentTime), then we take the second.
if (riseTime < currentTime) {
duration = response[1]["duration"];
riseTime = response[1]["risetime"];
}
Finally, we calculate the time in seconds it will take for the ISS to rise above the horizon:
timeUntilFlyover = riseTime - currentTime;
The loopIn the loop you count down the seconds until the ISS appears.
while (timeUntilFlyover > 0) {
delay(1000);
Serial.println(timeUntilFlyover);
timeUntilFlyover--;
}
When the big moment has come, you map the color of the NeoPixel to the duration of the flyover. This means that the LED ring starts to glow blue and slowly changes its color. When the ISS is going to disappear behind the horizon again, it glows red. To do this, use the map() function, which you can read more about in the Arduino documentation.
int maxDuration = duration; //save max value of the flyover duration
for (duration; duration >= 0; duration--) {
int colorRed = map(duration, 0, maxDuration, 200, 0);
int colorBlue = map(duration, 0, maxDuration, 0, 200);
//show the current color on all LEDs
for (int i = 0; i < 12; i++) {
pixels.setPixelColor(i, pixels.Color(colorRed, 0, colorBlue));
pixels.show();
}
delay(1000);
}
Once the ISS has disappeared, everything starts all over again until the ISS comes back and lights up your cubes again.
And that's it!
Comments