Arduino Light Up Sweater

by elizabethna in Circuits > Wearables

1534 Views, 9 Favorites, 0 Comments

Arduino Light Up Sweater

Arduino Light Up Sweater | GIT TECH'D

Ugly sweater parties are a staple of the holidays. Each year you have to up your game and wear the best sweater you can find. But this year you can do one better and make the best sweater. We use Adafruit Wearables to create a beautiful lit up sweater that is sure to impress your friends and family.

Adafruit created some great projects around Wearables already so we are using their modified code to implement this project from their Sparkle Skirt project.

In this tutorial you will:

  • Learn to use Wearables
  • Code your Flora main board, accelerometer, and NeoPixels to light up using Arduino

Getting Started

Accel & Main Board.jpg
Multiple Neopixel.jpg

We are going to use Adafruit Flora Wearables, a battery pack, conductive thread, and a holiday sweater. You’ll also need some regular thread, needles, and nail polish. It will all make sense in time. Our version is going to give Santa light up eyes but we support all religions and holidays and beliefs, so be creative!

Layout

Full Layout with lines.jpg

We need to layout the pixels, main board, and accelerometer before beginning the stitching process. The pixels will have a data connection, + for power, and - for ground. The accelerometer needs connections for 3V, SCL, SDA, and ground.

Layout the pixels, main board, and accelerometer on the sweater as you plan to stitch it. Make sure you will not cross any stitching since that will cause shorts. Since we are having our board face in and NeoPixels face out we are using the 3V, Pin 9, and Ground to connect the NeoPixels.

The NeoPixels have an arrow that shows how the data connection should go from the Flora main board to the next NeoPixel. Make sure all NeoPixels are lined up facing the same way.

Stitching Tips

The important part of stitching is three things; no shorts/crossing of stitches, tight knots when ending a stitch, and good connections to Wearables.

No Shorts/Stitch Crossing

Make sure to layout your Wearables so that your stitching won’t cross over. The lines should not cross, obviously. Once you have a layout that ensures all stitches remain separate, you need to make sure when you stitch that it is tight. If you leave too much slack it can allow the thread to touch. Once you finish a stitch cut the excess ends so there is no stray threads.

Tight Knots

When ending a stitch line, a tight knot will ensure the stitch doesn’t come loose. The trick is to put a small dollop of clear nail polish on the knot and let it dry. This helps hold the knot in place, similar to glue. The conductive thread doesn’t hold as well in a knot as regular thread so I highly recommend using nail polish or you may wind up with stitching coming loose.

Good Connections

Make sure the loops on the pins are tight. This will help ensure that if your circuit isn’t working, we know it’s not the connections that are the problem. You can loop through the pins 2-3 times to make sure there will always be a good connection.

Tips/Tricks

Make sure your item of clothing isn’t powered on when you take it on and off. This is the easiest way to have threads touch and cause a short. Don’t turn on your battery pack until the item of clothing is comfortably on.

Stitching the Components

fullstitch.jpg
neopixstitch.jpg

The first piece we need to attach is the Flora Main Board. Stitch the board to your sweater using regular thread through two pins you are not planning to use. This will hold the board in place and make it easier to stitch using the conductive thread. A few simple loops is enough to keep it from moving.

Next, you need to stitch the four connections from the Flora Main Board and the Accelerometer. This will be the Power, Ground, SCL, and SDA. If you place the Accelerometer to the top left of the main board the connections will directly line up. So you will have four separate stitches to connect the two boards. Use a little clear nail polish on both end knots to keep them from unravelling. A little nail polish on the boards won’t hurt them.

Finally, you need to connect the 3V, ground, and data connections from the Flora Main board to the NeoPixels. You can do two long, continuous stitches for the ground and power since those are at the bottom and top of the NeoPixels. For the data connections from Pin 9 you need to do separate stitches from each NeoPixel to the next.

Arduino IDE

The Flora Main Board is Arduino-compatible so we will be using Arduino IDE for our code. You can download the latest version through this link. https://www.arduino.cc/en/Main/Software

There is also a web version through this link. https://create.arduino.cc/

There are four libraries that need to be added to use our NeoPixels and Accelerometer. Go to Sketch, Include Library, Manage Libraries. For each you will need to search for it by name, select the latest version, and click install.

  • Adafruit NeoPixel
  • Adafruit Unified Sensor
  • Adafruit TSL2561
  • Adafruit LSM303DLHC

Once these are installed and the stitching is complete we are ready to test our sweater to make sure everything is working.

Test Scripts

acceltes1.jpg

To test our project we need to connect our Adafruit main board to your computer using a USB cable. Then go to Tools, Port, and select your Flora Main board in the list.

First thing we will test is if the accelerometer is working properly. Go to File, Examples, Adafruit LSM303DLHC, accelsensor. This will open a script that tests if the sensor is connected and reads coordinate values. Upload to your board and open the Serial Monitor in the top right of the Arduino IDE. If you see values changing in the Serial Monitor, like in the photo, while moving the accelerometer then it is working!

The second thing we will test is if the NeoPixels are working. Go to File, Examples, Adafruit NeoPixels, strandtest. Before we run this script, change the Pin to 9 and number of pixels to 6 (or whatever you are using for your project). Upload to your board and if the pixels all light up you’re ready for the final script!

Final Script

Screen Shot 2018-12-10 at 3.39.18 PM.png

Now it’s time to load our final code. Copy the code below into a new project file. The Pin is set to 9 and number of NeoPixels are set to 6. If you are using something different, change those before running this script. You can adjust the favorite colors by adjusting the values of R, G, & B from 0-255. You can also add more favorite colors by adding a new line. The move threshold can be adjusted as well. The lower the number, the easier it is to detect movement and turn on the NeoPixels. Once you make any changes you want, save and upload to your Flora Main Board. You should be able to see the pixels lighting up if you move the accelerometer around. Once you see that you can unplug from your computer and we can connect to our battery pack.

#include <Wire.h><br>#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_Neopixel.h>

#define PIN 9 #define PIXELCOUNT 6

// Parameter 1 = number of pixels in strip // Parameter 2 = pin number (most are good but we are using 9) // Parameter 3 = pixel type flags, add together as needed: // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products. product we are using) // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs. product we are using) Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXELCOUNT, PIN, NEO_GRB + NEO_KHZ800); Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(54321);

// Adjust the R, G, B from 0-255 and // add new {nnn, nnn, nnn}, for more colors // R G B uint8_t myFavoriteColors[][3] = {{255, 255, 255}, // white {255, 0, 0}, // red { 0, 255, 0}, // green };

// don't edit the line below #define FAVCOLORS sizeof(myFavoriteColors) / 3

// this number adjusts the motion sensitivity // lower number = more sensitive #define MOVE_THRESHOLD 5 //super sensitive currently

void setup() { Serial.begin(9600); // Try to initialise and warn if we couldn't detect the chip // Use Serial Monitor to view the print out if (!accel.begin()) { Serial.println("We got a problem. It's you, not me... unable to initialize the LSM303. I'd start with a quick check on the wiring"); while (1); } strip.begin(); strip.show(); // Set pixels to 'off' }

void loop() { /* Get a new sensor event */ sensors_event_t event; accel.getEvent(&event); // Serial.print("Accel X: "); Serial.print(event.acceleration.x); Serial.print(" "); // Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print(" "); // Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print(" ");

// Get the magnitude (length) of the 3 axis vector double storedVector = event.acceleration.x*event.acceleration.x; storedVector += event.acceleration.y*event.acceleration.y; storedVector += event.acceleration.z*event.acceleration.z; storedVector = sqrt(storedVector); // Serial.print("Len: "); Serial.println(storedVector); // wait a bit delay(250); // get new data! accel.getEvent(&event); double newVector = event.acceleration.x*event.acceleration.x; newVector += event.acceleration.y*event.acceleration.y; newVector += event.acceleration.z*event.acceleration.z; newVector = sqrt(newVector); // Serial.print("New Len: "); Serial.println(newVector); // are we moving yet? if (abs(newVector - storedVector) > MOVE_THRESHOLD) { Serial.println("Flashy! Flash! Flash! McFlash!"); flashRandom(10, 2); // first number is 'wait' delay, shorter num == shorter twinkle flashRandom(10, 4); // second number is how many neopixels to simultaneously light up flashRandom(10, 6); } }

void flashRandom(int wait, uint8_t howmany) {

for(uint16_t i=0; i<howmany; i++){
//randomly chosen from favorite colors
int c = random(FAVCOLORS);
int white = myFavoriteColors[c][0];
int red = myFavoriteColors[c][1];
int green = myFavoriteColors[c][2];

//the pixels to turn on in an order for (int i=0; i < 6; i++) int j = strip.numPixels(); Serial.print("Pixel on"); Serial.println(i); // now we will 'fade' it in 3 steps for (int x=0; x < 3; x++) { int w = white * (x+1); w /= 3; int r = red * (x+1); r /= 3; int g = green * (x+1); g /= 3; strip.setPixelColor(i, strip.Color(w, r, g)); strip.show(); delay(wait); } // & fade out in 3 steps for (int x=3; x >= 0; x--) { int w = white * x; w /= 3; int r = red * x; r /= 3; int g = green * x; g /= 3;strip.setPixelColor(i, strip.Color(w, r, g)); strip.show(); delay(wait); } } // LEDs will be off when done (they are faded to 0) }

Battery Pack

battery.jpg

To keep your sweater continuously powered we will use a battery pack. We need to make a harness for the pack so it doesn’t just hang from the board. I used the corner of an old pillowcase as my battery pocket. I stitched up the open side and stitched one side of the top to the sweater close enough to the main board that it can easily plug in and not pull on it.

Plug the battery pack into the main board, turn the small switch on the main board from off to on, and turn on your battery pack. Your sweater should now be working and ready to wear.

Conclusion

Screen Shot 2018-12-17 at 11.23.47 AM.png

You have now made a light up sweater that will impress all your friends and family! But this isn’t just a holiday project. Make your valentine a heart light sweater or light up a shamrock shirt for St. Patrick’s Day. Use your imagination and let us know what you’ve created!