Introduction: Accelerometer Controlled Light Gauntlets

This Halloween, I decided to be Alina Starkov from the Grisha Trilogy by Leigh Bardugo. In the books, she's the one and only Sun Summoner, doing magic with light and heat.

Since those powers were beyond me, I put together a set of Arduino-controlled gauntlets instead, that would light up on gesture commands and slip under my sleeves. [This set up, with a few tweaks, would probably serve you well for Iron Man, too]

Here's how I did it, and you can check out the gauntlets in action on Vine.

Step 1: Gathering Materials

I wanted to work with sewable arduino components, so I bought within the LilyPad system. You could substitute out another arduino board, but then you'd wind up needed to solder, instead of sew. Here's what I got (for a set of two gauntlets, just halve for one):

Step 2: Writing Code, Testing Circuits, Calibrating Accelerometer

To program an Arduino board, you need to download the Arduino software. The software and a full set of instructions for installation are here.

Before I made a single stitch, I wanted to make sure I knew how to connect everything up, that all my parts were working correctly, and that my code ran correctly.

I used the alligator clips to connect the LEDs and test each one (running the Blink program that comes with the Arduino software is a good way to check that you can install and change code).

Then, I needed to get a sense of what reading my accelerometer was giving, so I could decide what rules to use to tell my LEDs to turn on and off. After the initial setup section of my program (the same as in the final code), I wrote a loop with this code:

void loop(){

Xval = analogRead(accPin);

Serial.print("\nX-val: ");

Serial.print(Xval);

delay(1000);

}

This tells the board to check the accelerometer's reading and print it to the serial monitor (Ctrl-Shift-M on my windows computer). So, once my loop was running, I could wave the accelerometer around and see what the numbers looked like. That way, I could figure out what numbers I would see when my my arms were raised, and should trigger the lights.

Step 3: Writing the Logic for the Lights

It turned out, when my forearms were parallel to the ground, the readings from my x-axis monitor (with the arrow pointing toward my fingers) were around 500.

I could have just set the trigger there, and written logic to tell the LEDs to turn on if the readings went above 500 and to turn off if they were less than 500, but I wanted a little more flexibility. The loop I wrote looked like this instead:

void loop(){

Xval = analogRead(accPin);

if (Xval < 450){

digitalWrite(13, LOW);

};

if (Xval > 550){

digitalWrite(13, HIGH);

};

delay(100);

}

Setting up these two triggers gave me the chance to choose whether I wanted the lights to be on or off when my hands were parallel to the ground. I'm going to host a party in these, so I want to be able to hand off a drink without blinding someone, but I also want to be able to strike a lot of cool poses, at full power.

Because the lights only turn on a bit above the point where I'd be holding them straight out, I need to pull them sharply up to initially turn on, but then, I can move them around without too much fear they'll turn off. To get them off I just return my arms to my sides, and then, once they're off, I can still move them all the way up until my forearms are flat without turning them on unnecessarily.

Since I was just testing my code, to make sure I was reading my sensor correctly, I was just illuminating the built-in LED on the board at pin number 13. I started with slightly different numbers, but I just kept tweaking them and reexporting the code until the triggers felt right, and synced up with my movements as I desired.

Step 4: Sewing the Final Circuit

Once I was sure my code was working, I sewed the circuit together. Using conductive thread is easier than soldering, but there are also a couple ways to screw it up (especially since, unlike wire, your threads aren't insulated). Here's how I was careful to not wind up with shorts or loose connections:

  1. PLAN OUT HOW YOU'LL STITCH AHEAD OF TIME. (The threads can't overlap, and they aren't insulated, so make sure you've plotted out where you'll stitch so that there's room for everything).
  2. Test each connection, as you go. (Each time I was sewing one of the LEDs on, I tested it in isolation, before I started working on the next one. That way I could tell if my connection held, and could isolate a problem later)
  3. Take long stitches. (Unlike a sewing project, where stitches make a seam, here I took long stitches to avoid too much contact with the bracer and associated resistance.)
  4. Glue down all connections. (Conductive thread tends to unravel, so make sure you use elmer's clue to tack down every point where you started or ended a connection. But do this after you've run the whole set up successfully)

I also stitched my battery in place, but, depending on how you plan to use your gauntlet, you could also just stick it in place with electrical tape or sew on a little pocket or strap to hold it in place.

Step 5: Final Code

This is the ultimate code I wound up using. (The LEDs come on in a staggered way to give a fade-in/fade-out effect).

int Xval;

int led1 = 11;

int led2 = 10;

int led3 = 9;

int led4 = 3;

int accPin = A3;

void setup(){

Serial.begin(9600);

pinMode(led1, OUTPUT);

pinMode(led2, OUTPUT);

pinMode(led3, OUTPUT);

pinMode(led4, OUTPUT);

delay(1000);

Xval = analogRead(accPin);

}

void loop(){

Xval = analogRead(accPin);

if (Xval < 450){

digitalWrite(led1, LOW);

digitalWrite(led4, LOW);

delay(100);

digitalWrite(led3, LOW);

digitalWrite(led2, LOW);

};

if (Xval > 550){

digitalWrite(led2, HIGH);

digitalWrite(led3, HIGH);

delay(100);

digitalWrite(led1, HIGH);

digitalWrite(led4, HIGH);

};

delay(100);

}

Step 6: Troubleshooting / Further Extensions

Here are the two problems I had, just in case you run into them:

  1. Couldn't get my computer to recognize my arduino board (I) - Turns out I was sold a bad cable by RadioShack. Try again with a working cable
  2. Couldn't get my computer to recognize my arduino board (II) - Turns out there's a physical switch on the LilyPad, and I accidentally nudged it to off

I was lucky enough to get debugging help from HacDC, who have a microcontroller meetup every Monday.

If you want to extend this project, you can program the LEDs to strobe, turn on and off individually, etc. You can also make them responsive to more kinds of motion by using the other pins on the accelerometer to track y and z-axis movement.

If you use this project as a jumping off point, I'd love to hear how you adapt and alter it!

First Time Author Challenge

Participated in the
First Time Author Challenge

Make it Glow!

Participated in the
Make it Glow!

Halloween Costume Contest

Participated in the
Halloween Costume Contest

Microcontroller Contest

Participated in the
Microcontroller Contest

Halloween Props Contest

Participated in the
Halloween Props Contest