Step 3: Test 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.
Serial.begin(9600); // Setup serial
digitalWrite(13, HIGH); // Indicates that the program has intialized
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!