Introduction: LilyPad Arduino Night and Day Toy

I'm teaching a course this semester on technology in libraries, and this year there will be a making / coding assignment using the LilyPad Arduino. This will be an inquiry-based, open-ended, learn-as-you-go assignment. I had never used an Arduino before, nor had I coded in anything other than HTML, before getting my LilyPad kit in the mail a week ago. Since I have a 2-year-old at home, I decided to make a toy with my LilyPad. This is basically a round, two-page, vertical "book" that plays "Twinkle, Twinkle" and blinks white LEDs when the night side is exposed, and plays "You Are My Sunshine" and blinks colored LEDs when the "page" is turned to reveal the day side. To see the toy in action, visit or download the video file below.

Step 1: Materials

Sewing Materials:
  • Scraps of non-stretchy fabric, such as felt or quilting cotton (you will need at least 3 pieces that are at least 12"x12")
  • Approximately 2 sq. feet fusible fleece (Pellon) or fusible web
  • Approximately 1 sq. ft. fusible adhesive (such as Heat 'n' Bond)
  • Embroidery floss (I used black, white, yellow, and orange)
  • Sewing needle
  • Glue-on eyes (2 large for owl, 2 small for birds)
  • Fray-Check
  • Fabric glue
  • (Optional) 2 green gems for leaves on "day" side
  • (Optional) Embroidery hoop (makes stitching easier)
  • Iron
Electronics Materials:

Step 2: Plan

This project will have a flap in the middle (the bottom half of the night panel / top half of the day panel) that is not connected to the back of the project (picture an open book, with just one page in between the covers). So, you want all of your electronic components on the top half of the night panel and the bottom half of the day panel.

  1. Sketch your day and night panels. Include locations for all electronic components. The light sensor should be placed on the front of the night panel, above the midline. See the pictures for my sketches.
  2. Plan your stitching. Your stitches with the conductive thread will be made through the back layer of fabric only (with the exception of stitches that hold electronic components in place on the front of your project). Remember not to cross stitches. My stitching guide is shown in the picture above.

Step 3: Piece Together and Embroider Day and Night Panels

  1. Cut out two 12-inch circles: one blue (for the day panel), and one black (for the night panel).
  2. Using scrap fabric, cut out shapes. On the night panel, you will need to cut out six stars, a crescent moon, a branch, and the owl's body, wings, feet, and nose. On the day panel, you will need to cut out a yellow circle for the sun, a butterfly, a branch, three flowers, and bodies, tail feathers, chest pieces, wings, and beaks for the birds.
  3. For any fabric that might fray along the edges, apply a thin bead of Fray-Check along all edges and allow to dry. You won't need this for fabrics like felt or fleece.
  4. Lay out all of your shapes on your circles. Make sure that after you fuse / sew everything down, your electronic components will be in roughly the same places as in your planning diagrams.
  5. Once everything is in place, use the fusible adhesive with your iron to stick your pieces to the panels. Note, you do NOT want to stick or sew down the stars on the night panel or the centers of the three flowers on the day panel, since you will be sewing LEDs here later. You should also wait to glue down the eyes.
  6. Using your embroidery floss and a needle, embroider along all edges and add sun rays and butterfly antennae. For most edges, 2-3 strands of embroidery floss is sufficient. I mostly used the blanket stitch, but you can use any stitch you think looks nice. Here's a great tutorial on five basic embroidery stitches, including the blanket stitch:

Step 4: Sew

Note: I don't usually follow patterns when I sew, so I apologize if these directions are confusing!

  1. Cut out one 12-inch circle and one half-circle from your fusible fleece / fusible web. This layer is technically optional, but will make your toy soft, like a quilt, and will help to give the toy more structure, which in turn will help keep your conductive stitches from rubbing against each other.
  2. Cut out one 12-inch circle of backing fabric. This can be any color you choose (mine was black).
  3. Place the night circle right-side-up on a flat surface. Then place the day circle right-side down on top of the night circle (right sides together), with the bottom of the day circle meeting the top of the night circle. In other words, the two panels should be right-sides together, but upside down from each other. Finally, lay your half-circle of fusible fleece over the top half of the day panel (the half with the sun). Pin around the edges to hold everything in place, then sew the outside edge of the half with the fleece, leaving a 1/4" seam allowance. Do not sew the other half. Turn right-side out and iron to fuse the three layers together.
  4. At this point, you should have one finished half-circle with two raw half-circles sticking out. Now, lay down your backing fabric circle on a flat surface, right-side up. Then, lay down the two raw panels of your project right-side down on top of the backing fabric. Your finished half-circle will be inside; you can squash it a bit to keep it away from the edges. Finally, lay your 12-inch circle of fusible fleece on top. Make sure everything is lined up, then pin around the edges to hold everything in place and carefully sew around the edge, leaving a 1/4" seam allowance and stopping about 3 inches before you complete the circle. Be sure you don't accidentally sew into your finished half-circle.
  5. Using the 3-inch unsewed section, turn the project right-side out. The fusible fleece should be the middle layer. Iron to fuse all your layers together, then turn in the remaining unsewed edges and use your needle and thread to close up the 3-inch section.
  6. Glue on the owl and bird eyes.
The hard part of the crafting is done! Now on to the electronics components...

Step 5: Sew Your Conductive Stitches

For me, this was actually the easiest part of the whole project. Basically, you just follow the stitching diagram made in Step 1 to sew all of your electronics components to the project and to the LilyPad board. Make sure that for each connection, you wrap your conductive thread around the pins multiple times (I basically wrapped until there was no more pin showing!). Also make sure that your stitch lines go only through the backing fabric, so they won't show up on the front of your project.

  1. First, place your LilyPad board in the bottom right corner of the backing fabric. If you're viewing your project from the front, this would correspond roughly to behind the large bird's feet. You can use some double-sided tape to hold the board in place while you make your first few stitches.
  2. Place your buzzer to the upper left of the LilyPad board (+ on the left). Using conductive thread, make several passes through the positive pin of the buzzer, being sure to only pass through the backing fabric (you don't want your stitches to show up on the front of your project). Then make a neat stitching line to Pin 6 of the LilyPad board, and make several passes through that pin, again going only through the backing fabric. Do the same thing from the negative pin of the buzzer to Pin 5 of the LilyPad.
  3. Next, place your light sensor on the front of the night panel, above the midline and just to the left of the moon. The "S" pin should be at the bottom. Using your stitch diagram and the same method described in the previous step, sew the negative pin of the sensor to the negative pin of the LilyPad board, the "S" pin to A5, and the positive pin to A4.
  4. Place the colored LEDs on the front of the "day" panel at the center of each flower (you can use double-sided tape to hold them down temporarily; just remove it when you're ready to sew). Sew the positive pins of these LEDs to pins 9, 10, and 11 as shown in the stitching diagram.
  5. Place all of the white LEDs on the front of the night panel. Using a very long piece of thread, stitch through all of the positive connections on these LEDs and around the bottom edge of your project to pin A2, using the stitch diagram as a guide.
  6. Using another very long piece of thread, stitch through all of the negative pins of all LEDs, ending at Pin 5 as shown in the stitch diagram.
And that's all the stitching! Now onto...

Step 6: Program

Disclaimer: I have never coded in anything other than HTML before, so I'm sure that people who know better will look at this code and think it's terribly inelegant. However, it does work!

Here's the behavior I wanted: When I turn the toy on, I wanted it to read the light sensor. If it's light, that means the sensor is exposed, which means the "night" panel is showing. In that case, I wanted it to play "Twinkle, Twinkle" and blink the white LEDs. If it's dark, the flap is up and the sensor is covered, so the day side is showing. In that case I wanted it to play "You Are My Sunshine" and independently blink the three colored LEDs. That much was pretty easy to code, but what I really wanted was for the song and light display to change immediately as soon as I flipped the toy, and figuring out how to code that was difficult (for me... I'm sure it would be easy for others). But I did eventually figure it out, basically by having it test the light value after each note of the song and restart the loop if the light value had risen above or fallen below the threshhold (depending on which song it was switching from).

I realized in doing this project that it may have been easier to do this with an accelerometer, and that wouldn't have the issue of not being usable in a dark room. However, since this is meant to be a toy for a child, an accelerometer probably wouldn't work (kids like to shake toys). So all things considered, I think I would stick with the light sensor if I did this again.

My code is attached in the text file below. I tried to provide comments to describe what I was doing with each line of code.

Step 7: Upload Your Program and Test

  1. Plug the Li-Po battery into the LilyPad board. The battery will charge when you have the board connected to your computer (you should see an orange light if it's charging; if you don't see an orange light, turn the switch on the board to "on").
  2. Attach the FTDI breakout board to your LilyPad and use the mini USB to connect the board to your computer.
  3. Using the Arduino IDE, input your code and upload to your board. Your toy should be fully functional at this point!

Step 8: Finishing Touches

At this point, you can glue or stitch on your white stars and the flower centers to mostly cover up your LEDs. I cut a tiny hole in the center of each of these pieces so as not to cover up the LED itself, and just used glue to stick them down.

I also cut a quarter-sized circle of black fabric out to cover up the light sensor because I didn't like how obvious it was on the night panel (I cut out a hole in the middle so the sensor could still read). I glued this around the sensor.

I put a drop of fabric glue on each knot on the back of my project, to make sure that none of my stitches unravel.

Finally, I decided that I wanted something to cover up the LilyPad and my stitches, and to protect them from rubbing against each other. So I cut another 12-inch circle out of stiff felt, and used small (1/2" square) pieces of Velcro (glued down) to attach this to the back of my project.