# ISS Pin

## Overview

https://www.youtube.com/watch?v=Ld5MOGk63Xs

A Particle Photon microcontroller and an Adafruit Neopixel ring combine to make a pin that's fit for NASA fans. It displays an orbiting white blip when idle and then turns blue, white, red and multicolor when the ISS flies by. The code takes advantage of the Photon's Wi-Fi capability and&nbsp;uses IFTTT (If This Then That), a free site that makes connecting IoT devices as easy as a few clicks. This project was inspired by my first NASA Space Apps Challenge project created with friend Brooks Zurn Rampersad--the _ISS Orbit Skirt_.&nbsp;That's enough history...on to the parts!

# ISS Pin

## Tools & Supplies

![](https://cdn-learn.adafruit.com/assets/assets/000/040/874/medium800/projects_PARTS.jpg?1492225986)

Particle Photon and Adafruit's Particle/Spark NeoPixel&nbsp;Ring make a great combo for this pin, creating&nbsp;the perfect platform for&nbsp;a planet. Notice the plastic button which allows for any photo insert. Although I've included a battery, that's really just for showing off to a class or friends for an hour. You'll really need to have a&nbsp;USB battery pack and cable if you want to wear it in your fave wifi zone for an extended period of time.

**Supplies:**

- [Particle Photon With Headers](https://www.adafruit.com/product/2721)
- [Adafruit Particle/Spark NeoPixel Ring Kit](https://www.adafruit.com/product/2268)
- [USB Cable A/MicroB](https://www.adafruit.com/product/592)&nbsp;
- [LiPoly Battery&nbsp;](https://www.adafruit.com/product/1570)(optional)
- [Adafruit LiPo Micro USB Charger](https://www.adafruit.com/product/1304)&nbsp;(optional)
- [USB Battery Pack](https://www.adafruit.com/product/1959)&nbsp;(you probably have one at home)
- [Magnetic Pin Back](https://www.adafruit.com/product/1170)
- Adhesive Velcro (found in craft stores)
- Black Construction Paper
- White Paper (decent stock for printing Earth image)
- Solder

**Tools:**

- Soldering Iron (with small tip)
- Diagonal Snips

Make sure you've taken the time to thoroughly go over the guides for:

- [Particle Photon](https://docs.particle.io/guide/getting-started/intro/core/) (on Particle's site)
- [Adafruit NeoPixel UberGuide](../../../../adafruit-neopixel-uberguide)&nbsp;

Primary: 

# ISS Pin

## Solder Circuit

![](https://cdn-learn.adafruit.com/assets/assets/000/040/876/medium800/projects_Ring.jpg?1492226032)

Insert the pins of the Photon through the NeoPixel ring board so there is a row of holes on the outside surrounding the microcontroller (basically aligning the microcontroller with the outline on the board).&nbsp;

Solder all pins on the reverse side being careful not to create bridges since the holes are close together. After soldering, snip the remaining length of the pins so you have a smooth back for your pin.

![projects_Solider.jpg](https://cdn-learn.adafruit.com/assets/assets/000/040/877/medium640/projects_Solider.jpg?1492226061)

![projects_Trim.jpg](https://cdn-learn.adafruit.com/assets/assets/000/040/878/medium640/projects_Trim.jpg?1492226082)

# ISS Pin

## Create Cover

Take the plastic button and remove the magnet from the back. We'll need it to be smooth to lay on top of the microcontroller. Remember we have a magnet pin back we'll be placing on the back of the NeoPixel ring.

![projects_RemoveMagnet.jpg](https://cdn-learn.adafruit.com/assets/assets/000/040/879/medium640/projects_RemoveMagnet.jpg?1492226137)

Go to&nbsp;[NASA's photo library](https://images.nasa.gov/#/search-results?q=earth&page=1&media=image&yearStart=1920&yearEnd=2017)&nbsp;and select your favorite Earth image. Size it to fit your button (mine was about 2 1/8 in.) and print it on paper/card stock. Cut out the image, as well as a matching circle of black paper. Then, pry open the plastic back of the button and place&nbsp;both the image and black paper inside with Earth facing out.

![projects_GlobeCut.jpg](https://cdn-learn.adafruit.com/assets/assets/000/040/881/medium640/projects_GlobeCut.jpg?1492226239)

Now in order to create a removable hatch, we'll need to build up the inside area between the plastic button and microcontroller with velcro. You can create 2-3 layers like I did on either side of the Photon, or you can choose to glue some foam core or cardboard on the bottom layer with some velcro on top. The trick is to get the button to lay level on the top of the Photon&nbsp;as the micro jack&nbsp;makes it slightly uneven. Test out your layers of velcro before adhering them.&nbsp;

![projects_Velcro.jpg](https://cdn-learn.adafruit.com/assets/assets/000/040/883/medium640/projects_Velcro.jpg?1492226881)

The finishing touch is to add the magnetic pin on the back of the NeoPixel ring board. Just center it length-wise between the holes on the board. This is a strong pin so you won't have to worry about it falling off.

![projects_Magnet.jpg](https://cdn-learn.adafruit.com/assets/assets/000/040/889/medium640/projects_Magnet.jpg?1492238598)

# ISS Pin

## Code

Make sure your Photon is plugged into your computer and sign into [Particle.io](https://www.particle.io/). Then,&nbsp;go into "Console" and make sure you've selected your Photon device. Next,&nbsp;go into the "IDE" and enter the code below. It's important to load the code before you get to the next step&nbsp;of "Finishing Touches" as a function is called that needs to be read by the program IFTTT (IfThisThenThat).&nbsp;

Primary: 

```auto
/* ISS Pin by Leslie Birch for Adafruit Industries
Based on NeoPixel Library by Adafruit and code from Particle.io
This version connects with IFTTT and shows a ring of blue, white, red and multi when triggered. 
When not triggered, it does a comet chase of white. */

// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>

#include "application.h"

SYSTEM_MODE(AUTOMATIC);

void colorWipe(uint32_t c, uint8_t wait);

#define PIXEL_PIN D6
#define PIXEL_TYPE WS2812B

const int FADE_LENGTH = 3;
const int FADE_SCALE  = 128;
const int PIXEL_COUNT = 24;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

bool toggle = false;

int pos = 0, dir = 1; 
int j;

int pixelToggle(String command);

void setup(){
  strip.begin();
  strip.setBrightness(70); //set the brightness of NeoPixels to your preference
  strip.show(); // Initialize all pixels to 'off'
  
    Particle.function("pixelPIN", pixelToggle);
}
  void loop (){

   if(toggle==true){
   
  colorWipe(strip.Color(0, 0, 255), 25); // Blue
  colorWipe(strip.Color(0, 0, 255), 25); // Blue
  colorWipe(strip.Color(150, 150, 150), 25); // White
  colorWipe(strip.Color(150, 150, 150), 25); // White
  colorWipe(strip.Color(255, 0, 0), 25); // Red
  colorWipe(strip.Color(255, 0, 0), 25); // Red
  strip.setPixelColor(0,0,0,255);
  strip.setPixelColor(3,0,0,255);
  strip.setPixelColor(6,0,0,255);
  strip.setPixelColor(9,0,0,255);
  strip.setPixelColor(12,0,0,255);
  strip.setPixelColor(15,0,0,255);
  strip.setPixelColor(18,0,0,255);
  strip.setPixelColor(21,0,0,255);
  strip.setPixelColor(1,150,150,150);
  strip.setPixelColor(4,150,150,150);
  strip.setPixelColor(7,150,150,150);
  strip.setPixelColor(10,150,150,150);
  strip.setPixelColor(13,150,150,150);
  strip.setPixelColor(16,150,150,150);
  strip.setPixelColor(19,150,150,150);
  strip.setPixelColor(22,150,150,150);
  strip.setPixelColor(2,255, 0, 0),
  strip.setPixelColor(5,255, 0, 0),
  strip.setPixelColor(8,255, 0, 0),
  strip.setPixelColor(11,255, 0, 0),
  strip.setPixelColor(14,255, 0, 0),
  strip.setPixelColor(17,255, 0, 0),
  strip.setPixelColor(20,255, 0, 0),
  strip.setPixelColor(23,255, 0, 0),
  strip.show();
  delay(5000);
  colorWipe(strip.Color(0, 0, 0), 0); // off
  (toggle = false);
   }

    else {
     
    comet();
    }
  }
   
   void comet (){
        for ( int i=0 ; i < PIXEL_COUNT * 5 ; i++ ) {
        for ( int p=0 ; p < PIXEL_COUNT ; p++ ) {
            strip.setPixelColor( p, 0 );  //  clear the strip
        }
        drawFade( i, 255, 255, 149);        //  then draw the fade
        strip.show();
        delay( 400 );
    }
}

void drawFade ( uint8_t start, uint8_t r, uint8_t g, uint8_t b ) {
    int brightness = 50;
    for ( int p=0 ; p < FADE_LENGTH ; p++ ) {
        strip.setPixelColor( 
            ( start - p ) % PIXEL_COUNT, 
            strip.Color( 
                ( r * brightness ) / 255,
                ( g * brightness ) / 255,
                ( b * brightness ) / 255                
            )
        );
        brightness = ( brightness * FADE_SCALE ) / 255;
    }
} void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(50);
  }
}

int pixelToggle(String command){
    toggle = true;
}
```

# ISS Pin

## Set Up IFTTT

Primary: 

Head over to [IFTTT (IfThisThenThat)](https://ifttt.com/discover) and set up a sign-in. IFTTT is an Internet-of-Things site that allows you to connect different devices using easy-to-use applets. Not only can you connect Hue lights to trigger certain colors based on weather conditions, you can also connect microcontrollers that have Wi-Fi capability. With your account now set, hover over your account name in the right-hand corner and choose **New Applet** from the pull-down menu.

![](https://cdn-learn.adafruit.com/assets/assets/000/040/894/medium800/projects_IFTTT.jpg?1492459738)

IFTTT&nbsp;wants you to think literally about two things: "this" happens triggering "that". So, we will choose these two things in different steps. Here goes:

1. Click on the **+this** _&nbsp;_and type **space** in the search bar
2. Click on the **Space** square that appears
3. Now select the square **ISS passes over a specific location**
4. Move the map to select your exact location and click **Create Trigger**

![](https://cdn-learn.adafruit.com/assets/assets/000/040/886/medium800/projects_IFTTT2.jpg?1492231786)

OK, now we are shifting gears to handle the second part.

1. Click on the **+that** and type **Particle** in the search bar
2. Click on the **Particle** square that appears
3. Now select the square **Call a function**
4. Under **Then Call (Function Name) (required)**, check the dropdown for **pixelPIN on "yourdevicename"**
5. Now go to the bottom and click **Complete Action**
6. You can keep the green light that enables **Receive notifications when applet runs**
7. Hit **Finish**
8. You can **Check Now** &nbsp;to see that the applet is working, but it will only do the special light sequence if you force the trigger or the ISS actually passes
9. If you ever need to check this applet, you'll find it under **My Applets** on the top menu
10. Be aware that if you continue to run the applet without your pin having power, it will eventually automatically shut down
11. It's nice to have the IFTTT app installed on your phone to turn applets on/off

### Want a Test?

If you need to test what a flyby would be like without waiting long hours, it is good to set up another applet. This one will allow you to send an email to trigger your pin.&nbsp;

1. Follow the above directions for creating&nbsp;a new applet
2. This time for **+this** &nbsp;type&nbsp; **Email&nbsp;** in the search bar
3. Choose the **Send IFTTT any email** &nbsp;box
4. Now follow the directions above for doing the **+that** choosing **Particle**
5. Keep following those directions for all the choices including the function
6. Under the function section you'll see **+ingredient** - select **subject**
7. Hit **Create Action** and then&nbsp; **Finish**

This applet will enable you to send an email to **trigger@applet.ifttt.com&nbsp;** with anything written in the subject line. In a few seconds the pin will do its special light show as if the ISS had flown by. This is very handy for demos.&nbsp;

&nbsp;

# ISS Pin

## Wear It!

![](https://cdn-learn.adafruit.com/assets/assets/000/040/890/medium800/projects_Pin_HERO.jpg?1492239243)

The best way to wear the pin is to plug in the USB battery pack and tuck it in your pocket. It can last 24 hrs. even with all the pinging of data. If you want to go rogue you can plug in the little LiPoly battery (the plug placement is a bit awkward and will take some finger gymnastics). You can trim a small piece of velcro and attach it to the battery with&nbsp;its matching velcro side on the back of the pin. That way you can just wear the battery for meet-and-greets for a short amount of time. Remember to use the micro Lipo charger for the battery. Also, if you want to change the Wi-Fi&nbsp;zone of your pin, you will need to review [the basics](https://docs.particle.io/guide/getting-started/start/photon/). You may also want to install [Particle's Command Line](https://docs.particle.io/guide/tools-and-features/cli/photon/) to simplify things.

If you are a serious ISS fan, you will probably want to [sign up for alerts from NASA](https://spotthestation.nasa.gov/) for best viewing days/times. This pin's data can be up to an hour off according to Particle, but it does let you know all the passes for your neighborhood, which is cool. The idea for the pin stems from a lack of awareness of how frequently the ISS is flying overhead. So, think of this project less as a scientific device, but more of a mindful way of experiencing spaceflight. Sending high fives to my NASA Datanaut friends!


## Related Guides

- [Fix-It Felix Jr. Hammer with Sound FX](https://learn.adafruit.com/fix-it-felix-jr-hammer.md)
- [Textable Sensor with FONA and CircuitPython](https://learn.adafruit.com/textable-sensor-with-fona-and-circuitpython.md)
- [Wireless Image Transfer with Circuit Playground Bluefruit and TFT Gizmo](https://learn.adafruit.com/wireless-image-transfer-with-circuit-playground-bluetooth-and-tft-gizmo.md)
- [Pinball Controller for iPad](https://learn.adafruit.com/pinball-controll-ipad.md)
- [Making a Name Tag in MakeCode Arcade](https://learn.adafruit.com/making-a-name-tag-in-makecode-arcade.md)
- [Matrix Portal Scoreboard](https://learn.adafruit.com/matrix-portal-scoreboard.md)
- [Mini Golf Course with Circuit Playground and Crickit](https://learn.adafruit.com/mini-golf-course-with-makecode-circuit-playground-crickit.md)
- [Adafruit IO Basics: Schedule Actions](https://learn.adafruit.com/adafruit-io-basics-scheduled-triggers.md)
- [Trellis M4 Beat Sequencers](https://learn.adafruit.com/trellis-m4-beat-sequencer.md)
- [PyPortal MQTT Sensor Node/Control Pad for Home Assistant](https://learn.adafruit.com/pyportal-mqtt-sensor-node-control-pad-home-assistant.md)
- [Chinese Dragon Puppet with Motion-Reactive Flame Effect](https://learn.adafruit.com/chinese-dragon-puppet-with-motion-reactive-flame-effect.md)
- [PyPortal Roku Remote](https://learn.adafruit.com/pyportal-roku-remote.md)
- [Circuit Playground-O-Phonor](https://learn.adafruit.com/circuit-playground-o-phonor.md)
- [No-Code Pool Party Notifier](https://learn.adafruit.com/pool-party-notification-device.md)
- [NeoPixel Badge Lanyard with Bluetooth LE](https://learn.adafruit.com/bluetooth-neopixel-badge-lanyard.md)
