Introduction: Gesture Controlled Star Wars Stocking
The Star Wars stockings hang by the chimney (of course!)
To activate them you must use the Force!
Create an interactive Christmas stocking that lights up and plays sound effects in response to gestures. I made two examples using R2D2 and BB-8 that have the character's sounds loaded onto the LilyPad MP3 player. When you wave your hands in front of an embedded gesture sensor (up, down, left, right) it will trigger individual sound effects associated with each gesture and light up an LED 'eye'. For extra sparkle, rows of LEDs twinkle in the background.
Most of the circuit is constructed directly onto the fabric of the stocking using conductive thread and LilyPad sewable electronics. It is programmed in Arduino and I've included example code for you to download and use or edit. The instructions here walk through building the R2D2 version, but the process is nearly identical for the BB-8 which some slight changes in layout and code.
You'll need some basic soldering and sewing skills to complete the project and familiarity with uploading code and installing libraries in Arduino.
- LilyPad MP3 player
- Micro SD card (and card reader for loading sounds onto the card)
- LilyPad FTDI Basic Breakout - 5V
- Mini USB cable
- (2) 8Ω speakers or (1) portable speaker with audio cable
- APDS-9960 Gesture Sensor, available from SparkFun or Adafruit
- (3+) sewable WS2812 LEDs (I'll refer to them as 'pixels'), either LilyPad Pixel Boards or Flora NeoPixels, in this example I used 7
- Conductive thread
- Soldering iron, solder, and wire strippers
- Hookup wire - ribbon cable works great for this project
- 5V wall adapter
- Barrel Jack to JST Adapter
- Optional: alligator clips for prototyping
I made a wishlist on SparkFun.com with most of the parts I used for this build (excluding soldering tools). It's not a cheap build, but it is a fun exploration of sewable technology combined with gesture sensing.Feel free to swap any of the parts in this list with compatible parts as needed for price and sourcing considerations.
- Christmas stocking (I found the ones in this tutorial at Target)
- Hot Glue
- Sewing Thread
- Fray check or clear nail polish
- Hot glue gun and glue to attach components
- Fabric glue or paint for insulation
- Marker or pen
- Scrap felt or heat shrink to jump over conductive thread stitches as needed
- Optional: Acrylic paint and paintbrush
- Arduino IDE - download for free at https://www.arduino.cc/en/Main/Software
- FTDI Drivers - download for free at http://www.ftdichip.com/FTDrivers.htm
- Sound effects to play in MP3 format (I found some free sounds by searching 'Star Wars' on google)
- Arduino libraries (install through Arduino's library manager or download on GitHub):
- SdFat (by William Greiman)
- VS1053 for use with SdFat (by Bill Porter) (sometimes known as SFEMP3Shield)
- Adafruit APDS-9960 library
- Adafruit NeoPixel Library
Step 1: Planning Circuit Layout
Place all the components on your stocking to plan your circuit layout. The gesture sensor and speakers will be soldered to the LilyPad MP3 and the rest of the circuit will be connected with conductive thread stitching.
Here are the connections listed by sew tab on the LilyPad MP3 player:
- GND to GND on APDS-9960 and - on all LilyPad Pixels
- T1 to DI on pixel 1
- T2/SDA to SDA on APDS-9960
- T3/SCL to SCL on APDS-9960
- Left Speaker - to - on speaker 1
- Left Speaker + to + on speaker 1
- Right Speaker - to - on speaker 2
- Right Speaker + to + on speaker 2
- 3.3V to + on pixels and to VCC on APDS-9960
The rest of the pixels should be chained up in sets of three at the top and bottom of the design. DO of one pixel is connected to DI of the next in line and + and - in parallel. See image for reference.
Feel free to move components around until they fit with your chosen design and leave space so the conductive thread stitching will not overlap. See my R2D2 layout for an example to start with. I planned my projects in graphics software, but you can use pencil and paper to brainstorm or record your layout. Your layout may change depending on the addressable LEDs you use - the LilyPad Pixel Board and Flora NeoPixels have slightly different sew tab configurations.
Step 2: Prepare Electronics
Next, we'll solder some of the pieces together before attaching to the stocking.
The LilyPad MP3 has holes for attaching through-hole components, you can use these or solder directly to the sew tabs (just make sure not to fill the hole in the tab as some of these will be used to attach conductive thread).
Solder each speaker to the places marked 'speaker left' and speaker 'right'. You can either use the holes or solder directly to the LilyPad MP3's sew tabs (I used the tabs in this project). Use the wires that come installed with the speaker, or provide your own. If you are using a portable speaker, no soldering is need - it will connect to the headphone jack. One advantage of using the soldered speakers is you will not have to provide additional power, the LilyPad MP3 board will power them.
APDS-9960 Gesture Sensor:
There are 4 connections on the gesture sensor that will connect to the LilyPad MP3 board: GND, VCC, SDA, and SCL (we will not be connecting INT and VL in this project).
- Connect GND to the GND tab on the LilyPad MP3
- Connect VCC to 3.3V on the LilyPad MP3
- Connect SDA to T2/SDA on the LilyPad MP3
- Connect SCL to T3/SCL on the LilyPad MP3
Make sure you are soldering to 3.3V and not VIN.
Step 3: Choose Your Sounds
The example code supports up to four individual sounds. Name them ''track001.mp3" through "track004.mp3" to be compatible with the sample code.
Load your sound effect MP3 tracks onto the micro SD card that you want to use in your project.
A search for 'Star Wars sound effects' will get you lots of places to download sound files.
After the sounds are loaded onto the micro SD card, install in the LilyPad MP3 player.
Step 4: Upload Code and Test
Next, we'll upload the code and test the project before sewing into the stocking.
If you'd like, clip the pixels to the LilyPad MP3 with alligator clips so you can preview the light effects as you upload code.
Before you upload the code, you will have to install some libraries to use the code, you can do this through the library manager or manually through GitHub.
Open Arduino and attach the LilyPad MP3 player to a USB port on your computer using the FTDI board and USB cable. Plug in the JST to barrel jack adapter and connect to the AC adapter. Set the slide switch on the LilyPad MP3 to ON.
Adjust code as desired. Some things you may want to change:
- The PIXEL_COUNT constant. The code is set up for 4 pixels in the project: the first is the 'eye' of the droid and the rest are decorative pixels that twinkle along the snowflake pattern (3 at the top and 3 at the bottom controlled simultaneously). If you would like to use more or less pixels, change this number to match the amount you chose. For example, the BB-8 stocking I made only uses 2 pixels at the top and bottom, so I changed PIXEL_COUNT to 3.
- The eyecolor variable in the eye() function. For R2D2 I chose a red. Feel free to adjust this variable or manually input RGB values in the line Pixel.setPixelColor(0, eyecolor,0,0); (the first parameter is the pixel address, and the next three are R, G, B).
- The twinkle() function - feel free to adjust the code in here for your desired color or twinkling behavior for the additional LEDs.
When you are ready to upload code, open the Tools menu and select:
- Board: Arduino Pro or Pro Mini
- Processor: ATmega328 (3.3 V, 8 MHz)
Next, select the Port the LilyPad MP3 player is connected to.
Then click upload. If everything works the way you want, your LilyPad MP3 player is ready to install in your project. Unplug from your computer and power adapter before installing in your project.
Step 5: Prepare Stocking and Installing Hardware
Once the code is working and you are ready to install hardware, it's time to attach all the components on the lining of the stocking to keep them from covering the design on the outside. Open up the curved seam of the stocking with scissors or a seam ripper and pull the knit layer aside.
Carefully cut any holes in the stocking where you want components to poke through. You will need to cut a hole to allow the gesture sensor to pick up readings (it will not sense through the fabric). The sensor has a pretty wide viewing angle which can be easily blocked by the knit fabric so the hole will need to be quite large. You can disguise the color of the PCB that may show by carefully painting it to match, making sure to avoid getting any paint on the sensor itself (see detail image). Before painting, unplug or power down the board.
The LEDs may be bright enough to be installed underneath the fabric or you can cut holes for them. Reinforce the holes with sewing thread to keep the knit from unraveling and seal the cut edges with fray check or clear nail polish.
Step 6: Installing Hardware and Stitching It Together
When the holes are sealed, flip the top layer back over and use a marker or pen if needed to help mark where to place the components on the lining. Place the components on the lining, adjusting any boards as needed so they show through the holes in the knit layer. Take this time to double check the orientation of the parts according to your circuit diagram. Once in place, use a glue gun to adhere the boards to the lining of the stocking according to your circuit diagram, making sure not to fill any of the sew tab holes with glue. Leave the speakers unglued for now, as you may need to stitch underneath them.
Use a pen or marker to plan out your stitch lines between the components, making sure to keep thread lines from crossing. If you need to cross conductive thread stitch lines, use a piece of fabric or heat shrink and an insulating 'bridge' where paths cross.
Connect the components with conductive thread according to your diagram, using three to four stitches around each sew tab to secure to the tab, then using a running stitch to travel to the next component to connect to.
For a primer on sewing with conductive thread, check out SparkFun's LilyPad E-Sewing Basics.
You can continue one line of thread to connect the pixels' power tabs together. Same for ground tabs. The DO to DI need to be individual lines of thread.
Step 7: Final Function Test
When all the sewing is complete, plug the JST to barrel port adapter to the 5V wall adapter and plug into the LilyPad MP3 and a wall outlet (you won't need the FTDI plugged in unless you plan on doing some more code changes). Switch the LilyPad MP3 on using the built-in slide switch and test out your project. Even if your project was working fine in the prototyping stages, I always recommend testing one more time before moving on to the final stages. Here you may find any problems with your circuit hookup or work on some additional code debugging.
For example, the resistance of conductive thread may affect how much power the LEDs in your project are getting. After stitching my stocking together, I realized running the power stitch line through all of them ended up dimming the LEDs at the very end. After testing, I unplugged and added a second line from the 3.3V tab up the side of the stocking to the top row of LEDs. This also required jumping over the ground line of stitching, so I used a bit of heat shrink to act as a bridge (instead of felt).
This is a good time to do any additional strain relief. I'd suggest reinforcing the connection points on the speakers with hot glue as they can easily detach with movement. This also happened to my stocking after stitching it up - the factory leads on these speakers can be delicate and I want to spare you the pain of having them detach in your finished project. I also covered the back of the speakers with felt in case they had to be placed over the conductive thread stitching to provide extra insulation.
Step 8: Insulation and Finishing the Lining
When your project is testing and functioning the way you want, seal the ends of the knots on your stitching with fray check or clear nail polish. At this stage, I also added a little extra paint around the gesture sensor after seeing the hole I cut out had a little white space showing behind it.
To keep the power cord from accidentally detaching inside the stocking, tape the barrel jack together. This happened to my prototype and it was tricky to reconnect while stitched up inside the project! To help eliminate any shifting inside the stocking, baste or tack the cord down with sewing thread or hot glue it to the lining following the shape up to the hanging loop. This will allow you to hang the cord with the loop on a stocking hanger.
To protect the stitching from being damaged from presents in the stocking or keep any metallic objects/presents from shorting out the threads, coat the threads on the interior of the lining with hot glue or fabric paint or another layer of fabric.
Next, stitch the stocking lining back together along the edge seams. If using a portable speaker that needs a battery, cut a hole or flap for recharging. If you'd like to keep access to the FTDI headers for any future reprogramming, cut a small hole in the lining. Glue down the speakers if you haven't already.
Step 9: Finishing Touches
When you are ready to stitch together the outer layer, use dabs of hot glue over the LEDs to hold them in place under the knit fabric. I also like to fill the holes with glue, which diffuses the light a little bit and creates a nice glow in the finished project. Glue the edges of the fabric down around the gesture sensor, being careful not to get any glue on the sensor itself.
At this point, I also added a button over the fabric for some extra dimension and to distract the eye from the sensor cut out at the bottom of the stocking.
Finally, pin the top layer of the stocking back together and stitch closed with a matching thread.
Hang and enjoy!
We have a be nice policy.
Please be positive and constructive.