Beginning LilyPad Arduino


This is a quick tutorial to get you started sewing a simple LEDs-only circuit using the LilyPad Arduino Simple Board. You won't learn how to create your own Arduino program, but you'll hook 9 LEDs to the board (one to every pin except + and -), and you'll upload provided code to change the way the lights move and blink.

The supplies you'll need are as follows:

Recommended, but not necessary:

  • Embroidery Hoop

Go ahead and visit http://arduino.cc/en/Main/Software to download the Arduino software if you don't already have it. It's free, and it is fairly straightforward, but if you get all of your sewing done and then have to stop and install software before you can see if it works, that will be frustrating!  Follow the installation guides found here : http://arduino.cc/en/Guide/HomePage and when you're ready to install your FTDI drivers, make sure you follow the 'Arduino Duemilanove' driver installation guide. Once everything is set up and you can open Arduino, we're good to start sewing!

Take a look at your simple board- it has 11 pads on it that can be sewn to any number of interesting devices. In this tutorial, we're just going to handle lights, but remember that the Arduino board is a really versatile tool. It can be used to direct the activity of sensors, motors, buzzers, vibration motors- anything you can buy on a LilyPad board, and plenty of things you can't. We're using 9 LED light boards because you've got nine pads on the board aside from the + and - pads.

Go ahead and thread your needle with conductive thread, and sew your simple board down to the fabric where you want it by the hole in the pad labeled '5'.

Sew away from this point to where you want your first LED to go, then sew down the positive pad of the LED

Tie off and cut your thread, restarting on the next pad you'd like to sew down. I find it easier to move to the other side of the board, so that it's securely attached on both sides. Sew from this one to where you'd like the corresponding LED, and once again sew down the positive side of the LED.

Repeat this process for every pad except for the ones labeled + and -. I've sewn mine in a radial pattern - you can deviate from this pattern, but remember not to cross any of the strands. Since conductive thread is uninsulated, if the lines of stitching cross, two LEDs will receive the current meant for only one.

You have two pads left now.

Sew down the - pad, called 'ground' and stitch from it to the "-" on the nearest LED. You don't have to knot and cut this line of stitching - continue it to the next LED, and the next, all the way around to the last LED, making sure never to cross a "+" trace with this "-" trace.

When you get to the last LED, go ahead and knot the thread and cut it. You should now have all 9 LEDs connected to individual pads on the Arduino board on their positive sides, and all of them connected in one contiguous line to each other and to the ground pad.

Here is what the circuit looks like from the back - you can see that none of the positive traces are in contact with each other, and all of the negative ones are.

You're done now with the sewing portion - the circuit is complete. Connect the FTDI board to the headers on the Lilypad Arduino board and the mini-usb end of your cable to the FTDI board like so:

And the USB end of the cable into your computer

Next, you'll upload the program. If you haven't installed Arduino on your computer yet, you'll need to do it now. When you open Arduino, you'll get a screen like this:

Double check that you've selected the correct board-

Now it's time to upload the code that will run your lights!

This is the code you'll use:

    #define LED1 5
#define LED2 6
#define LED3 9
#define LED4 10
#define LED5 11
#define LED6 16
#define LED7 17
#define LED8 18
#define LED9 19

#define interval 11000
#define dead_time 1000

unsigned long PWM_counter = 0;

int offset = 0;
int step_size = 200;
unsigned long on_time = 0;
unsigned long cycle_start = 0;
char dir = 1;

int offset2 = 0;
int step_size2 = 200;
unsigned long on_time2 = 0;
unsigned long cycle_start2 = 0;
char dir2 = 1;

byte LED_tracker1 = 1;
byte LED_tracker2 = 1;

void setup() {
  Serial.begin(57600);
  pinMode(LED1, OUTPUT);      
  pinMode(LED2, OUTPUT); 
  pinMode(LED3, OUTPUT); 
  pinMode(LED4, OUTPUT); 
  pinMode(LED5, OUTPUT); 
  pinMode(LED6, OUTPUT); 
  pinMode(LED7, OUTPUT); 
  pinMode(LED8, OUTPUT); 
  pinMode(LED9, OUTPUT); 
  offset = random(2500,7500);
  offset2 = random(2500,7500);
}

void loop()
{
  PWM_counter = micros();
 
  if( (PWM_counter + offset - cycle_start) >= interval) {  // completed cycle, start over
    on_time += step_size*dir;
    cycle_start = PWM_counter;
    if (on_time >= (interval - dead_time) ) {
      dir *= -1;
      on_time = interval - dead_time;
    }
    else if (on_time <= 0) {
      on_time = 0;
      dir *= -1;
      LED_tracker1 = LED_tracker2;
      while (LED_tracker1 == LED_tracker2) LED_tracker1 = random(1,10);
      offset2 = random(0,4000);
    }
  }
  else if( (PWM_counter + offset - cycle_start) >= (dead_time + on_time) ) {  // time to switch LED off
    //digitalWrite(LED1, LOW);
    LED_off(LED_tracker1);
  }
  else if( (PWM_counter + offset - cycle_start) >= dead_time) {  // time to switch LED on
    //digitalWrite(LED1, HIGH);
    LED_on(LED_tracker1);
  }  
  
  if( (PWM_counter + offset2 - cycle_start2) >= interval) {  // completed cycle, start over
    on_time2 += step_size2*dir2;
    cycle_start2 = PWM_counter;
    if (on_time2 >= (interval - dead_time) ) {
      dir2 *= -1;
      on_time2 = interval - dead_time;
    }
    else if (on_time2 <= 0) {
      on_time2 = 0;
      dir2 *= -1;
      LED_tracker2 = LED_tracker1;
      while (LED_tracker2 == LED_tracker1) LED_tracker2 = random(1,10);
      offset2 = random(0,4000);
    }
  }
  else if( (PWM_counter + offset2 - cycle_start2) >= (dead_time + on_time2) ) {  // time to switch LED off
    //digitalWrite(LED1, LOW);
    LED_off(LED_tracker2);
  }
  else if( (PWM_counter + offset2 - cycle_start2) >= dead_time) {  // time to switch LED on
    //digitalWrite(LED1, HIGH);
    LED_on(LED_tracker2);
  }
}

void LED_on(byte LED)
{
  if (LED == 1) digitalWrite(LED1, HIGH);
  if (LED == 2) digitalWrite(LED2, HIGH);
  if (LED == 3) digitalWrite(LED3, HIGH);
  if (LED == 4) digitalWrite(LED4, HIGH);
  if (LED == 5) digitalWrite(LED5, HIGH);
  if (LED == 6) digitalWrite(LED6, HIGH);
  if (LED == 7) digitalWrite(LED7, HIGH);
  if (LED == 8) digitalWrite(LED8, HIGH);
  if (LED == 9) digitalWrite(LED9, HIGH);
}

void LED_off(byte LED)
{
  if (LED == 1) digitalWrite(LED1, LOW);
  if (LED == 2) digitalWrite(LED2, LOW);
  if (LED == 3) digitalWrite(LED3, LOW);
  if (LED == 4) digitalWrite(LED4, LOW);
  if (LED == 5) digitalWrite(LED5, LOW);
  if (LED == 6) digitalWrite(LED6, LOW);
  if (LED == 7) digitalWrite(LED7, LOW);
  if (LED == 8) digitalWrite(LED8, LOW);
  if (LED == 9) digitalWrite(LED9, LOW);
}

Cut and paste that code, in its entirety, into the Arduino sketch window, then click the upload button.

And take a look at the black box at the bottom.

If you've got a red error message, check your com port. You can do this by opening up this menu and unplugging the cord that connects the computer to the FTDI board from the computer's USB port. Look at which COM port disappears, then plug the USB back into the computer and select that port.

Barring errors, you should now have all nine lights participating in a quick, fading twinkle effect.  Go ahead and unplug the FTDI board from the Arduino board, plug in your battery, and turn the switch on to check it out. I used this circuit to create this glimmering cocktail dress, but you can apply this circuit to anything you'd like - feel free to use your creativity!

Comments 3 comments

  • Nice work, Dia - I followed this tutorial yesterday morning and by noon I had a twinkling tutu! WOOHOO!

  • very well structured and comprehensive article. another good article with a long list of tutorials could be found here http://www.intorobotics.com/resources-and-tutorials-to-start-working-with-arduino-boards/

  • This is an excellent tutorial. For those who are intimidated by arduino c code or those who wish to expand their soft circuitry knowledge I would suggest that they go to the Eduwear site
    (http;//dimeb.informatik.uni-bremen.de/eduwear). This site has a drop and drag programing system and was developed for children in middle school. It has a good manual and instructions. Finally for those with younger kids, I would suggest you get them into programming by using Scratch from MIT or Alice from Carnegie Mellon. Graybeard
    Growing older is mandatory. Growing up is optional