Introduction: Interactive Child's Mobile

What can you make with fluorescent acrylic as the inspiration?  We chose to make a glow-in-the-dark baby mobile, with an accompanying toy.  This project was completed as a part of the Computing and Craft class at Olin College of Engineering.

Materials:
- Craft Materials:
    - Fluorescent acrylic (1 square foot of each of the following colors: pink, orange, yellow, green*)
    - Wooden dowels (8 feet of each of 1/4" and 3/8" diameter and 4 feet of 1/2" diameter)
    - Fishing line (approximately 5 yards)
    - Light-colored thread (approximately 5 yards)
    - Hot glue gun (1) and hot glue sticks (1-2)
    - Stuffed toy (1) (one which had circuitry in it and therefore has easy access to the insides is convenient)
- Electronics
    - Arduino UNOs (2)
    - LEDs** (3)
    - FTDI Breakout board (1)***
    - USB cables, A to B plugs (2)
    - XBee radios (2)
    - XBee breakout boards with headers (2) ****
    - Mini Servo motors (2)
    - A-B USB cable (1)
    - 1-axis accelerometer (1)
    - Three-terminal switches (3)
    - Push buttons (2)
    - Flex sensors (2)
    - Resistors (2x10k and 4x2.2k)
    - Blacklight flashlights with screw-off heads (2)
    - Solid-core wire (a lot*****)
    - Electrical tape (approximately 1 yard)
    - Soldering iron (1) and solder (approximately 1 yard)
    - Battery packs and batteries (we used one of three AAAs, one of three AAs, and two of two AAs, but some of this is flexible)

* We used 12" x 24" sheets from inventables.com.  Depending on the sizes and shapes of your parts, you might be able to use 12"x8" sheets, which are the next-smallest size.  Also, the blue fluorescent acrylic from Inventables doesn't fluoresce (as of March, 2012).
** We used lilypad LEDs because we had them in a color we liked (orange-yellow).  We don't recommend using lilypad LEDs instead of regular ones, though.
*** One of these will make your life much easier if your XBee radios aren't already configured to talk to each other. Don't assume they will. http://www.sparkfun.com/products/718
**** XBee radios have non-standard pin spacing, so you will want a workaround. Reference http://www.ecrater.com/p/10690385/xbee-breakout-board-kit-10-pack. Alternatively reference digikey.com
***** We used about a dozen wires of approximately 4 yards in length to suspend switches from the ceiling for easier access.  Securing the blacklights and the servos to the dowels also required a few yards of wire.  Other than that, most of the wiring could be done with a yard or two of wire.

Step 1: Design Parts

The acrylic for this project is cut using a laser cutter.  We designed our parts in Solidworks, but feel free to use whatever CAD software you prefer.  All of our parts were between 3 and 6 inches on a side, with most of them being approximately 4" square.  For the theme our our baby mobile, we designed two flowers, two butterflies, and one rainbow.

The sides of the acrylic fluoresce more than the faces do.  To show this off (and to mix up the colors) we cut holes and inset parts for all of the acrylic shapes.  To facilitate mixing and matching of these inset parts, we cut one of each of the flowers and the butterflies out of each color of acrylic.  We also cut the corresponding arc of the rainbow out of each color of acrylic (with pink being the largest and green being the smallest).  This gave us 20 parts, enough for two mobiles with 10 parts each.  We also cut small (1/16") holes where we wanted to attach the parts to each other to facilitate the assembly process later.  

Assemble the parts onto cutsheets (according to the format for the laser cutter you use), putting the parts as close together as you can given the tolerance of your laser cutter.  Be aware that parts placed too close to the edge of the sheet may get cut off.  Then cut the parts (or get someone to cut them for you).

The images for this step show the Solidworks parts for all the components we designed.

Step 2: Assemble Parts

Decide what color combinations you like best and lay out how you would like to assemble your parts.  We found that the orange and yellow acrylics looked similar, so we preferred to accent the pink and green with the orange and yellow, and vice versa.  We initially intended to use only fishing line to secure parts to each other but found that thread was easier to work with and allowed spinning parts more movement.  However, for parts requiring structure, fishing line worked very well to hold subparts in a particular configuration.  For our mobile, we used thread to hold together the two butterflies and the flowers.  We used fishing line to hold together the tulips and the rainbows. as these looked significantly better with more structure.

All subparts were secured to each other using square knots through corresponding holes.  (See step 1 again and look at the alignment of the holes in the parts, if you're interested.)  The spacing was intended to match that in the parts, though of course getting this exact in practice was difficult.

Step 3: Test Components

If you have not already, download the arduino software from http://arduino.cc/hu/Main/Software.  You will need this for programming and testing components.  Plug one of the arduinos into your computer and run one of the demos (e.g. Blink) to confirm your arduino is working; do the same with the other arduino.  Now you're ready to test the other components.

The bend sensors serve as variable resistors.  For our purposes, we need a reading from them.  We therefore need to solder a 10k resistor in between one of the sides and ground.  In fact, using the sensor will be a lot easier if you solder leads to each of the pins.  Make sure to insulate the connections with heat shrink tubing or electrical tape.  Note also that the joint of the bend sensor can wear through and break, so reinforcing this with tape is a good idea.  The resistor, as mentioned previously, will go to ground; the same pin to which the resistor is soldered will go to the analog input; and the other pin will go to power (5V).  Plug the bend sensor into the arduino in this configuration, with the input to pin A0.  Then configure the arduino to print out the analog input values.  If you aren't familiar with arduino software, use the code below.  See what kinds of values you get when you bend your flex sensor versus when the sensor is straight.

void setup()
{
  Serial.begin(9600);               // Setup serial
  digitalWrite(13, HIGH);         // Indicates that the program has intialized
}

void loop()
{
  raw = analogRead(A0);    // Reads the Input PIN
  Serial.println(raw); // Prints the input value
  delay(10); // Make it not scroll too quickly
}

In the next step, you will hack the servos for continuous motion.  For now, though, it's a good idea to make sure they work in the first place.  The orange wire is signal, red is power (5V), and brown is ground; hook a servo up to the arduino in this manner.  Run one of the servo test modules to make sure your servo behaves as expected.  You will need long leads on the servos (at least 1 yard, depending on how long the fishing line suspending the mobile will be), so now would be a good time to attach those by sliding them into the corresponding pins on the servo.  We found that braiding the wires together helped to keep them consolidated and ensured we knew which wires went to which component.

Solder leads to the power, ground, and signal pins of the accelerometer.  Hook the accelerometer up to the arduino, with the input going to one of the analog pins (e.g. A0).  Print the raw values as you did for the bend sensors.  Try tapping the accelerometer and see what kinds of changes in the values you get.  We found that giving the accelerometer a good shake tended to make our input numbers go from three digits to four digits.

Screw the heads off the two flashlights.  The spring in the center of the head corresponds to power and the metal threads around the outside correspond to ground.  Carefully solder a long power lead to the spring and a long ground lead to the threads.  (You will need at least 1.5 yards of each wire to get from the end of the mobile to the arduino.)  Plug the ground wire into a ground pin and the power wire into one of the digital pins.  When you set the pin to high, the light should turn on, and when you set the pin to low, the light should turn off.

Solder long leads to each end of each of the LEDs, making note of which lead goes to ground and which carries the signal.  Test each LED like you did each flashlight--insert the ground wire into a ground pin and the signal wire into a digital pin, then ensure the LED turns on when you set the pin high and off when you set the pin low.

All of your electrical components should now be working, and with the exception of hacking the servos and programming the XBees, they should be ready to use!

Step 4: Hack Servos

The servos are intended to rotate continuously in one direction, which necessitates hacking the servos.  The first step in doing this is to remove the hard stop attached to one of the gears.  Remove the screws from the casing and remove the plastic top to expose the gears.  Take careful note of the order in which the gears are placed so that you can put them back in this order!  The bottom pin has a raised plastic piece which prevents the servo from rotating more than 180 degrees in either direction.  Carefully cut off this stop--small wire cutters with an angled tip work well for this.  Then put all the gears back and screw back on the top, then put on a plastic horn.  You should be able to twist the horn continuously in either direction.  If you can't, take the horn and cover back off and make sure you removed the entire stop.

The potentiometer (pot) inside the servo tells the servo what position is has.  To allow continuous motion, we want the servo to think that the pot is in the middle at all times so that any value other than 0 degrees will cause it to rotate.  The pot has a range of 5k, so you can replace the pot with two 2.2k resistors (don't ask us about the math--this was recommended to us).  The pot is the cylindrical device inside the body which has a shaft attached to it.  Snip the wires holding the pot so you can extract the pot from the casing.  Solder a 2.2k resistor in between the white wire (signal) and the black wire (ground) and another 2.2k resistor in between the white wire and the red wire (power).  Use electrical tape or heat shrink tubing to insulate the connections.  Then (very carefully!) put the pot and shaft back in place and make sure all the components fit back into the body of the motor.  Once everything is back in place, screw back on the casing.

Step 5: Program XBees

If you know your XBee radios are properly configured to talk to each other, skip this step.

Configuring XBee's is not exactly the most straightforward of processes. You will need 2 of them, they should be 2 of the same model. We used two S1's. Go ahead and download the XCTU software from http://www.digi.com/support/productdetail?pid=3352 beneath the tab named Diagnostics, Utilities, & MIBs. While that is installing, take the FTDI breakout board and solder on leads to Power (3.3 V), Ground, TX & RX (possibly labeled DOUT & DIN).
General rules for XBee's:
    1) Only power with 3.3 V, or else you'll fry the radio. Note, your FTDI board and your Ardunio UNO's should have 3.3V rails.
    2) A wire that goes to TX on one end goes to RX on the other.
    3) Your XBee's should only need 4 wires plugged in ever.
Hook up one of your XBee's to the FTDI board and plug it in to your computer. Then start the XCTU software (as a general rule, plug it in first, then start XCTU).
Hit the Test/Query button towards the right, and if any on-screen instructions pop up, follow them.* You should receive verification that you have some fashion of an XBee. Head over to the Modem Configuration tab, click read, then check 'Always Update Firmware,' then hit write. You will want to do this to both XBee's and receive confirmation that they are configured with identical firmware, and they should be the same model number, though their serial numbers will differ. Next hit Read, uncheck 'Always Update Firmware' and make sure that you set the baud rate to 9600 (under Serial Interfacing; Interface Data Rate) and if you want to avoid interference from your neighbor's XBee tinkering, go ahead and set a different PanID & Channel. Your radios should work if you give them the same Channel, but different ID's. In order to test they can communicate, plug one radio into an Arduino, hook it up to the computer and run the Arduino software. Open the Com Port Serial Monitor (Ctr Shift M) and go back to your 'Terminal' tab from XCTU. Anything you type in the Terminal should appear magically on the other Arduino's Serial Monitor.
At this point, if it doesn't work, check the first three general rules of XBee's (see above, especially #2: i.e. wire goes from TX on the arduino to DIN on the XBee). If it still doesn't work, especially if you have a different model of XBee than we did, use the power of Google to find configuration tutorials. XCTU should have all the power you need to configure them, it is just a trick of making sure you carefully read all the options and they are configured on the same channels with same baud rates, etc. One of them might need to be in 'command' mode while another is in 'peer,' although not necessarily. There are many models of XBee's...

Step 6: Assemble Toy Circuitry

The arduino which goes into the toy will send values depending on whether the flex sensors and the accelerometer are giving high or low values.  The flex sensors read high if at least one of them is high.  If both the flex sensors and the accelerometer are low, transmit 0; if the flex sensors only are high, transmit 1; if the accelerometer only is high, transmit 2; if both components are high, transmit 3.  This significantly simplifies the processing which must be done on the receiving arduino.

Now, there's a bit of a pickle here.  The arduino usually transmits a value of '0'. However, for reasons we have not yet determined, the arduino sometimes transmits everything as a ASCII character that is 48 above whatever you desired. We got around this difficulty by just having the receiving arduino test for both possible values, but we'll be sure to update this if we figure out why we get funny values sometimes. It helps to make sure you use the Serial.write() command, not the Serial.print() or Serial.println() commands when you are hoping to actually transmit data across the radios. Also, at this point, as you start plugging things in and putting code on the Arduinos, you'll want to avoid uploading code to an Arduino that has anything plugged into it's TX or RX pins (pins 0 & 1).

We used three 1.5V batteries in series to power the arduino (three AAs).  The arduino performs some internal power regulation, so you can power the arduino off of 4.5V or 6V.

Solder the ground leads of the two flex sensors and the arduino together, leaving the end of one lead free to plug into the board.  Do the same with the three power leads.  Plug the ground leads into one of the ground pins on the arduino and the power leads into the 5V power pin.  Plug the power lead of the XBee into the 3.3V pin and the ground lead of the XBee into another ground pin, then plug the RX/DIN lead into the TX pin of the arduino.  (The XBee is receiving from the arduino, hence the input of the XBee being connected to the output of the arduino.)  Finally, plug the ground lead of the batter pack into the final ground pin and the power lead of the battery pack into the Vin pin.  

The toy circuitry is now assembled!  Now all you need to do is program the arduino.  We used the below code to control our toy.

// Values to be read
int accelVal = 0;
int bendVal1 = 0;
int bendVal2 = 0;
int accelRef;
int bendRef1;
int bendRef2;
boolean accelOn = false;
boolean bendOn = false;
int sendVal = 0;

void setup() {
  // This code runs once, at the beginning
  Serial.begin(9600); // Initialize serial monitor

  // Get reference values: these allow us to calibrate the values we send for any variation in component behavior
  accelRef = analogRead(A3); 
  bendRef1 = analogRead(A4);
  bendRef2 = analogRead(A5);
}

void loop() {
  // This code runs continuously
  delay(1);
  // Get values
  accelVal = analogRead(A3);
  bendVal1 = analogRead(A4);
  bendVal2 = analogRead(A5);

  // Check if accelerometer is on
  if ((accelVal - accelRef) > (accelRef / 3)){ // This is an arbitrary reference that we found worked well
    accelOn = true;
  } else {
    accelOn = false;
  }
  // Check if bend sensors are on
  if ((bendVal1 < (3 * bendRef1 / 4)) || (bendVal2 < (3 * bendRef2 / 4))){ // This is an arbitrary reference
    bendOn = true;
  } else {
    bendOn = false;
  }

  // Determine the correct value to transmit based on the sensors
  if (accelOn == false) {
    if (bendOn == false) {
      sendVal = 0;
    } else {
      sendVal = 1;
    }
  } else {
    if (bendOn == false) {
      sendVal = 2;
    } else {
      sendVal = 3;
    }
  }
  // Transmit the value
  Serial.write(sendVal);
}

Step 7: Assemble Mobile

We assembled the parts of the mobile back in step 2, so now it's time to put all of them together.  Lay out your mobile on the floor to make sure the two sides will not hit each other.  We used the full 4' of the thick top dowel.  The next layer consisted of medium-weight dowel of approximately 1.5' in length.   From this hung a light-weight dowel of approximately 1' in length, off of which hung a butterfly and a flower, and another medium-weight dowel, again approximately 1.5' in length; this hung low enough so as not to interfere with the other branch.  Off of that dowel we hung a rainbow and another light dowel of approximately 1' in length with another butterfly and another flower.  Each side of the mobile had one of each of the five parts, and we tried to balance the colors used, as well.

We found it useful to lay out one side of the mobile and mark the lengths of the dowels we liked, then cut two of each of the lengths we wanted (to mirror the mobile on the other side).  Once you have the dowels at the lengths you like, tie the requisite parts at the ends of the corresponding dowels using fishing line.  Secure the fishing line to the dowel with hot glue.  Once you have all the components set, balance the mobile, starting from the bottom.  Tie fishing line to the center of the bottom dowel, find the balance point, and glue the fishing line in place.  Then tie this branch to the end of the medium dowel with the rainbow on the other end and secure.  Balance this branch, then tie to one end of the other medium dowel.  Balance the final light dowel and secure to the other end of the medium dowel.  Finally, balance this branch and attach a servo horn directly at the balance point with fishing line and hot glue.  Repeat this process on the other branch.  Attach a servo to each end of the heavy dowel, using hot glue.  You may find it helpful to troubleshoot the mobile assembly before attaching the servos to the horns, but eventually you will hot glue the servo horns to the servo shafts; this is necessary because of the weight of the branches, although the branches are not very heavy.  Braid the three wires for each servo together and secure them along the thick dowel rod, having them meet in the middle.

Cut the remaining medium-weight dowel in half and attach one half to each side of the main heavy-weight dowel rod.  Tape and/or glue the blacklights to the ends of the medium-weight dowel, facing towards the mobile.  You will need to play with the angle of the blacklight heads somewhat to obtain a nice angle such that all the mobile pieces are hit by the blacklight.  Twist the blacklight wires together and secure them to the rod, meeting at the balance point of the rod.  Use fishing line to tie an LED to each end of the thick dowel and one in the middle, securing the fishing line with hot glue as necessary.  Twist the wires for each LED together and make them meet in the middle.  Twist all the wires from the LEDs, blacklights, and motors together and with the fishing line suspending the center of the mobile.  These wires will all go to the arduino in the ceiling where the mobile is mounted.  (Of course, if your ceiling does not have removable tiles like the one we used does, you will need some other place to store all your circuitry.)

Step 8: Assemble Mobile Circuitry

We assembled and tested all the components for the mobile circuitry in steps 3, 4, and 5, so now it's time to put them together.  We found that a mini breadboard helped us to clean up our circuit so we could see all the components.  You can, however, build the circuit entirely on the arduino if you prefer.

Connect the 3.3V pin of the arduino to the VDD pin of the XBee, the RX pin of the arduino the the VIN pin of the XBee, and a ground pin of the arduino to the ground pin of the XBEE.  We found that we needed to power the two motors separately from the arduino because the arduino could not source enough current to power the arduinos as well as all the other components.  Connect the power wires of the servos to each other and to the power wire of the AAA battery pack.  Connect the ground wires of the servos to each other and to the ground wire of the AAA battery pack.  Solder the ground wires of the LEDs, the blacklights, and the servos all together, leaving one end free to plug into a ground pin.  Connect all components to the requisite pins--we used pins 12 and 11 for blacklights, 10 and 9 for servos, and 8, 7, and 6 for LEDs.  

Finally, power the arduino itself.  We used two battery packs of two AAs each connected in series to give us a 6V input; you can also, as discussed previously, power arduinos off of 4.5V; we used whatever we had available.  Connect the power lead to the VIN pin and the ground lead to a GND pin.  Incidentally, we found that soldering leads onto the battery packs from the flashlights worked well--we used one of these to power the servos.

Now all you need to do is program the arduino.  We used the below code on the mobile arduino to control the various components.

#include <Servo.h>
int serial_val = 0;
boolean motors_on = false;

// Counters for the LEDs flashing
int x1 = 0;
int x2 = 0;
int x3 = 0;

// Sample pins for mobile-mounted arduino
static int ledPin1 = 6;
static int ledPin2 = 7;
static int ledPin3 = 8;
static int motorPin1 = 9;
static int motorPin2 = 10;
static int flashlightPin1 = 11;
static int flashlightPin2 = 12;

// Servo information
Servo motor1;
Servo motor2;
int pos1 = 0; // position of motor1
int pos2 = 0; // position of motor2

void setup() {
  // Setup code runs once at the beginning
  Serial.begin(9600); // Starts the serial monitor

  // Tell the arduino which pins will be used for output; no pins will be used for input on the mobile
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(flashlightPin1, OUTPUT);
  pinMode(flashlightPin2, OUTPUT);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);

  // Pin 13 is the built-in LED, usually used to signify that the program wrote correctly
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
}

void loop() {
  // Main code, which runs repeatedly

  // read value from (radio), subtract 48 for quick fix from ASCII to int
  if(Serial.available())
    serial_val = Serial.read()-48;

  // Check to make sure the value read is reasonable
  Serial.println(serial_val);
  if(serial_val > 0)
  {
    digitalWrite(13, HIGH);
  }
  else
  {
    digitalWrite(13, LOW); 
  }

  // Increment counters
  x1 = x1 + 1;
  x2 = x2 + 1;
  x3 = x3 + 1;

  // Check values of counters; random primes were selected as cutoffs so the cycles wouldn't line up
  if (x1 > 20483){
    x1 = 0;
  } else {
    if (x1 < 1000){
      digitalWrite(ledPin1, HIGH); // Turn on for 1 second every 20.483 seconds
    } else {
      digitalWrite(ledPin1, LOW); // Turn off the rest of the time
    }
  }
  if (x2 > 29303){
    x2 = 0;
  } else {
    if (x2 < 1200) {
      digitalWrite(ledPin2, HIGH);  // Turn on for 1.2 seconds every 29.303 seconds
    } else {
      digitalWrite(ledPin2, LOW); // Turn off the rest of the time 
    }
  }
  if (x3 > 18397){
    x3 = 0;
  } else {
    if (x3 < 900) { 
      digitalWrite(ledPin3, HIGH); // Turn on for 0.9 seconds every 18.397 seconds
    } else {
      digitalWrite(ledPin3, LOW); // Turn off the rest of the time
    }
  }

  // Delay just a bit so the program can respond
  delay(1);

  // to turn the blacklights on / off:
  if(serial_val == 1 || serial_val ==3)
  {
    digitalWrite(flashlightPin1, HIGH);
    digitalWrite(flashlightPin2, HIGH);
  }
  else
  {
    digitalWrite(flashlightPin1, LOW);
    digitalWrite(flashlightPin2, LOW);
  }

  // Turn the motors on or off
  // This code actually turns them on and off for brief spurts by attaching and detaching the motors
  // because otherwise they ran at too high a speed and the pieces hit each other
  if(serial_val == 2 || serial_val == 3)
  {
    if(motors_on)
    {
      motors_on = false;
      motor1.detach();
      motor2.detach();
    }
    else
    {
      motors_on = true;
      motor1.attach(motorPin1); // Attach motor1 to appropriate pin
      motor2.attach(motorPin2); // Attach motor2 to appropriate pin
      motor1.write(0);
      motor2.write(0);
      delay(300);
    }
  }
  else
  {
   if(motors_on)
    {
      motors_on = false;
      motor1.detach();
      motor2.detach();
    }
  }

}

Step 9: Final Assembly

Now that the components work, it's time to confirm that they work together and put the pieces in their final mounts.  Switch on all the battery packs.  Confirm that the blacklights turn on when the bend sensors are bent and the servos turn on when the accelerometer is shaken, and that they don't turn on otherwise.  (If one or both of these is not the case, check the circuitry first--we had several cases of a wire slipping out of the arduino causing problems.)  Confirm also that the LEDs flicker on and off every 20 seconds or so (and not in phase with each other).

If you are mounting your mobile inside the ceiling, like we did, stand on a table or other tall object and move aside a tile in the ceiling. The circuitry will rest on top of a neighboring tile.  Tie the mobile to the ceiling and place the circuitry inside the ceiling.  Test the mobile and toy interaction to make sure no wires were displaced in the hanging of the mobile.  Then slide the ceiling tile back into place.

Open the toy's midsection and pull out most of the stuffing.  Our toy had a very large head, so we put the boards inside the head.  If you are afraid that your wires may slip out (ours did!), encase the arduino gently with tape to hold everything in place.  (You could get around this problem by making your own circuit board and soldering everything in place, but this method works all right.)  Carefully slide the arduino into the stuffed animal and pad with a little bit of the extracted stuffing.  Next, sew the bend sensors to the sides of the stuffed animal, hiding the stitching as much as possible in the animal's fur.  Finally, slide in the battery pack.  Pad with as much stuffing as will fit.  Turn the battery pack on and test the interaction with the mobile.

Congratulations!  You now have a working, glow-in-the-dark, interactive baby mobile.


~Molly and Josh.
Make It Real Challenge

Participated in the
Make It Real Challenge