Step 6: Wire and Program the Arduino
I used a radio shack adjustable voltage DC power adapter set to 6V to power everything. On the Adafruit breadboard power supply, I set the voltage of the adjustable rail to +5V. Instead of using a separate power supply or battery to power my Arduino, I powered it off of the breadboard power supply. I sacrificed a battery holder by cutting the barrel connector off of it. I soldered short pieces of solid core wire onto the end of the connector so that it could plug directly into the breadboard. I connected it to the unregulated voltage rail of the breadboard.
Because the LEDs draw so much power, transistors need to be used so that you can power them with the breadboard power supply. I used 2N2222 NPN Transistors from Radio shack. Connect the Pinout wires from the Arduino to the base of the transistors (center pin). A resistor needs to be added between the Pinout wires and the center pin of the transistors (see picture). Wire the collector pin (rightmost pin) to ground. Wire the positive lead of the LED wire to the +5V of the power supply. Wire the negative lead of the same LED to the transistor emitter (leftmost pin). Make sure that the flat side of the transistor is facing you. To determine what resistors to use I did a lot of experimentation to get the correct brightness and voltage/current to the LEDs. I used a combination of 480 ohm, 220 ohm, and 510 ohm resistors for this.
I wired the LEDs to the following Arduino pins:
#define fire 6
#define small_blue 16
#define big_blue 17
#define lights_left 18
#define lights_right 19
You need wav files to play on the waveshield. I got some of my sound clips from here:
I also grabbed some directly from the blu-ray discs using audacity. There is a great tutorial on Adaruit’s website on making and converting files for use with the wav shield. I would recommend checking it out if you are going to be making clips for the wave shield. I have attached all of the wav files that are used in program except for the BTTF I theme song. The theme song was too big to upload, but you can grab it from that website. If you dump them on the SD card that goes into your wav shield, my program will be able to call and play them. Right now I have 13 different clips set up. I use a case switch structure to cycle through the different clips.
I am using a cheap pair of logitech computer speakers. I bought ones that plug into a wall outlet for power since they do not get that loud when powered by the wave shield. There is a headphone jack on the wave shield for the speakers to plug into.
I took the wave shield sample code and picked out the parts that I needed to play a wav file. Be sure to use to use the playfile() command and not the playcomplete() command. You will not be able to execute other commands if you call playcomplete(). Playfile() on the other hand will let you drive the LEDs while wav files are playing. For example, if I wanted to play Remotecontrol.wav, I would use the command:
I am not the best programmer in the world, so I am sure my code can be improved. I did not use anything fancy to control the lights, just good ole’ delay() commands. It is really tedious work to synchronize the lights to music, but I have not found a better way. There is an example on the Adafruit website where lights can be illuminated automatically by the code depending on the volume of the audio, but it was not yielding good results for me. I also programmed a timer into the program that changes that state of the lights after a couple minutes of no activity (no one presses the button). I could not get the .ino file to upload so I put my code into a .txt file. Sorry, but some of my code did not save. The last 1/3 of the choreographed lights to the theme song is not in the code that I uploaded. I will try to redo this code when I get a chance.