Introduction: Singing Pumpkins/ Arduino
Lets start off by saying that I am a noob to micro controllers like Arduino. After looking through instructables for a while I saw the things that arduino could do. That is when I realized that I had to get one and learn the whole process of programming. So having said that I will now move onto my first instructable build.
UPDATE!! IF YOU HAVE UPGRADED TO ARDUINO 1.0 THE WAVE LIBRARY WILL NOT WORK!!! I AM CURRENTLY LOOKING FOR A FIX TO THIS. IN THE MEAN TIME PLEASE USE THE OLDER VERSION OF ARDUINO SOFTWARE OR IF YOU CAN HELP WITH THE FIX PLEASE POST!!
I decided to create a singing pumpkin display for Halloween. I got the idea from https://www.instructables.com/id/Singing-PumpkinsParallel-Port-Relay-Box/ I did't have a parallel port but I had an arduino, sound shield and lots of patience. I used the song "This is Halloween" from Nightmare Before Christmas, wrote the code and built a relay board. I will go over how I did this later. Even though it took a lot of work the final result is well worth it! Video is posted in last step.
CAUTION!! CAUTION!! CAUTION!! CAUTION!! CAUTION!! CAUTION!! CAUTION!! CAUTION!! CAUTION!! CAUTION!! CAUTION!!
THIS PROJECT DEALS WITH HIGH VOLTAGE. IF YOU ARE NOT CAREFUL YOU COULD GET SERIOUSLY INJURED.
IF YOU ARE NOT COMFORTABLE WITH THAT PORTION OF THE PROJECT, PLEASE GET SOMEONE TO HELP.
UPDATE!! IF YOU HAVE UPGRADED TO ARDUINO 1.0 THE WAVE LIBRARY WILL NOT WORK!!! I AM CURRENTLY LOOKING FOR A FIX TO THIS. IN THE MEAN TIME PLEASE USE THE OLDER VERSION OF ARDUINO SOFTWARE OR IF YOU CAN HELP WITH THE FIX PLEASE POST!!
I decided to create a singing pumpkin display for Halloween. I got the idea from https://www.instructables.com/id/Singing-PumpkinsParallel-Port-Relay-Box/ I did't have a parallel port but I had an arduino, sound shield and lots of patience. I used the song "This is Halloween" from Nightmare Before Christmas, wrote the code and built a relay board. I will go over how I did this later. Even though it took a lot of work the final result is well worth it! Video is posted in last step.
CAUTION!! CAUTION!! CAUTION!! CAUTION!! CAUTION!! CAUTION!! CAUTION!! CAUTION!! CAUTION!! CAUTION!! CAUTION!!
THIS PROJECT DEALS WITH HIGH VOLTAGE. IF YOU ARE NOT CAREFUL YOU COULD GET SERIOUSLY INJURED.
IF YOU ARE NOT COMFORTABLE WITH THAT PORTION OF THE PROJECT, PLEASE GET SOMEONE TO HELP.
Step 1: Things You Will Need
Things you will need:
Tools:
Drill
Dremel
Solder Iron
Solder
Screwdriver
Utility Knife
Supplies:
Arduino ( I used the uno with smd chip)
Wave shield
8 pumpkins with light socket and cord( the more styles the better )
flicker bulb set ( available at HD Christmas isle)
5 outlets
relays
wire ( low voltage, electrical cord )
Preff board
9 diodes- Vr/50v Io/1A T/R. Mfg P/N: 1N4001
9 10k OHM 5% 1/4W carbon film resistors
9 330 OHM 1/6W carbon film resistors
9 transistors- 600mA 75V NPN ON Semi Bipolar Small Signal Mfg P/N; P2N2222AG
9 leds 3v
Plastic box ( for relay board and outlets )
Small plastic box ( protection for arduino and sound shield )
Masking Tape
Electrical tape
9v wall wart (adapter)
For the relay board set up I needed 9 relays that control 110v. That 's 8 for the pumpkins and 1 for the flicker bulbs that will run In standby mode. The relays I used are 5v input and 110v 12a output. The relays are wired to be controlled by the arduino but they are powered by a wall wart ( transistors are perfect for using a low voltage to control a higher voltage ). The circuit is simple( as you will see in upcoming steps). The arduino sends a signal to the 10k resistor which is connected to the center pin of the transistor. This will use the transistor as a switch to connect the negative from the wall wart to the relay pin by switching the ground.
Tools:
Drill
Dremel
Solder Iron
Solder
Screwdriver
Utility Knife
Supplies:
Arduino ( I used the uno with smd chip)
Wave shield
8 pumpkins with light socket and cord( the more styles the better )
flicker bulb set ( available at HD Christmas isle)
5 outlets
relays
wire ( low voltage, electrical cord )
Preff board
9 diodes- Vr/50v Io/1A T/R. Mfg P/N: 1N4001
9 10k OHM 5% 1/4W carbon film resistors
9 330 OHM 1/6W carbon film resistors
9 transistors- 600mA 75V NPN ON Semi Bipolar Small Signal Mfg P/N; P2N2222AG
9 leds 3v
Plastic box ( for relay board and outlets )
Small plastic box ( protection for arduino and sound shield )
Masking Tape
Electrical tape
9v wall wart (adapter)
For the relay board set up I needed 9 relays that control 110v. That 's 8 for the pumpkins and 1 for the flicker bulbs that will run In standby mode. The relays I used are 5v input and 110v 12a output. The relays are wired to be controlled by the arduino but they are powered by a wall wart ( transistors are perfect for using a low voltage to control a higher voltage ). The circuit is simple( as you will see in upcoming steps). The arduino sends a signal to the 10k resistor which is connected to the center pin of the transistor. This will use the transistor as a switch to connect the negative from the wall wart to the relay pin by switching the ground.
Step 2: Relay Board 1
For this step I laid out my relays so I could get an Idea of how I wanted it to be. The relay I used had the load pin in the middle and it did not fit into the preff board so some drilling was needed ( see pic ). Now it's time to place relays and solder them. Once the relays are all soldered we can now move on to placing the other parts. I started with the diode. Even though relays have no polarity the diode will change that ( diodes let the juice flow one direction ) and that will keep the voltage from bouncing back where it shouldn't be.
Step 3: Relay Board 2
At this point I added the transistor and first resistor (10k). Since the transistor switched a ground or negative I placed it so the output pin is connected to the diode negative or ground side. ( side without stripe ). The resistor is connected to the signal pin of the transistor this pin is used to control the internal switch.
In the next picture I added the second resistor (330k). This is used to limit or resist the voltage to the led. In the picture it looks like it connects to the transistor but it is not. The side of the resistor that is facing away from the transistor will be soldered together.
By now the solder connections are as follows. Solder relay to the board. solder diode so that each pin is soldered to the relay signal pins. Place transistor and solder one pin to the negative side of the diode and relay. Solder the 10k resistor to the middle pin of the transistor. Solder the 330ohm resistor so that both resistors are connected opposite of that transistor.
In the next picture I added the second resistor (330k). This is used to limit or resist the voltage to the led. In the picture it looks like it connects to the transistor but it is not. The side of the resistor that is facing away from the transistor will be soldered together.
By now the solder connections are as follows. Solder relay to the board. solder diode so that each pin is soldered to the relay signal pins. Place transistor and solder one pin to the negative side of the diode and relay. Solder the 10k resistor to the middle pin of the transistor. Solder the 330ohm resistor so that both resistors are connected opposite of that transistor.
Step 4: Relay Board 3
In this step add the led. Leds have a flat edge on one side this is the negative( - ) or cathode. This will be soldered to the last pin of the transistor. The other pin of the led the anode will be soldered to the 330k resistor. You may notice in the second picture the layout is slightly different then the first and that is because things got a bit tight for soldering. However the circuit remains the same. (See pic).
The next pic show the jumper wires used to connect the positive( + ). This will feed power to all relays with a wall wart. The jumper wires are soldered to the stripe end of each diode. It's now a good time to add the signal wires. The wall wart negative (-) ground connects to the ground buss bar and arduino ground.
Now to the bottom of the relay board for some major work ( see pic ). I know the solder isn't pretty but, hey, it's my first major solder project. Solder a buss bar to all load pins on the relays. Solder either a buss bar or jumper wires to all negative ( - ) connections. The negative connections need to connect to the ground on the arduino and to the negative on the wall wart. The only thing left to solder is the line wire from a male plug and the output load wires to each relay that will connect to your outlets.
The next pic show the jumper wires used to connect the positive( + ). This will feed power to all relays with a wall wart. The jumper wires are soldered to the stripe end of each diode. It's now a good time to add the signal wires. The wall wart negative (-) ground connects to the ground buss bar and arduino ground.
Now to the bottom of the relay board for some major work ( see pic ). I know the solder isn't pretty but, hey, it's my first major solder project. Solder a buss bar to all load pins on the relays. Solder either a buss bar or jumper wires to all negative ( - ) connections. The negative connections need to connect to the ground on the arduino and to the negative on the wall wart. The only thing left to solder is the line wire from a male plug and the output load wires to each relay that will connect to your outlets.
Step 5: Set Up the Housing
Housing:
Select a plastic box that will suit your needs. I used a shoe box sized box with lid. It gave me room for the 5 outlets, relay board and small plastic box for the arduino and sound shield. Lay masking tape across the side you choose for the outlets. Use an outlet face plate and trace holes. Now use the dremel to cut holes.
Outlets:
I used 5 outlets for 8 pumpkins. This is accomplished by removing the metal tab on one side of the outlet ( copper screw side, See pics ) This will now change the 5 outlets to 10. The project uses 8 plugs for the pumpkins, 1 plug for the flicker bulb string. So the left over one I connected so it stays live for the use of an adapter.
On the other side of the outlet will be silver screws this is the neutral side( White Wire ). Connect all neutral sides together. Now on the other side where the tab was removed attach one (black ) wire to the top screw and one (black ) wire to the bottom screw. The black wires will connected to the relays. ( See pic for details ) Now take a plug end from an extension cord. The white wire from the cord will connect to the white wires on the outlets. The black wire will connect to the relay board via buss bar.
Select a plastic box that will suit your needs. I used a shoe box sized box with lid. It gave me room for the 5 outlets, relay board and small plastic box for the arduino and sound shield. Lay masking tape across the side you choose for the outlets. Use an outlet face plate and trace holes. Now use the dremel to cut holes.
Outlets:
I used 5 outlets for 8 pumpkins. This is accomplished by removing the metal tab on one side of the outlet ( copper screw side, See pics ) This will now change the 5 outlets to 10. The project uses 8 plugs for the pumpkins, 1 plug for the flicker bulb string. So the left over one I connected so it stays live for the use of an adapter.
On the other side of the outlet will be silver screws this is the neutral side( White Wire ). Connect all neutral sides together. Now on the other side where the tab was removed attach one (black ) wire to the top screw and one (black ) wire to the bottom screw. The black wires will connected to the relays. ( See pic for details ) Now take a plug end from an extension cord. The white wire from the cord will connect to the white wires on the outlets. The black wire will connect to the relay board via buss bar.
Step 6: Arduino/Wave Shield Set Up and the Files
I used this wave shield http://www.ladyada.net/make/waveshield/ It comes as a kit simply follow the assembly instructions on the link.
The wave shield will use pins 1, 2 ,3 ,4 ,5 ,10
Our project uses pins 6, 7, 8, 9, A0, A1, A2, A3, A4, A5
Pins 6 ,7 ,8, 9, A0, A1, A2, A3 will be used for the pumpkins flashing lights, pin A4 will be used to control the flicker bulb set and pin A5 will be used to control a relay that will disconnect the background audio and connect the wave shield to one set of speakers. This is so that everyone will focus on the main event of the Halloween display.
Upload the audio file to an sd card, and upload the sketch to the arduino.
SKETCH
// Created by Greg Spiridakos 2011//
#include <AF_Wave.h>
#include <avr/pgmspace.h>
#include "util.h"
#include "wave.h"
AF_Wave card;
File f;
Wavefile wave; // only one!
#define redled 9
uint16_t samplerate;
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Wave test!");
pinMode(2, OUTPUT); // used by sound shield
pinMode(3, OUTPUT); // used by sound shield
pinMode(4, OUTPUT); // used by sound shield
pinMode(5, OUTPUT); // used by sound shield
pinMode(6, OUTPUT); // led light
pinMode(7, OUTPUT); // led light
pinMode(8, OUTPUT); // led light
pinMode(9, OUTPUT); // led light
pinMode(A0, OUTPUT); // led light
pinMode(A1, OUTPUT); // led light
pinMode(A2, OUTPUT); // led light
pinMode(A3, OUTPUT); // led light
pinMode(A4, OUTPUT); // flicker bulb set
pinMode(A5, OUTPUT); // auido switch over relay
pinMode(redled, OUTPUT);
if (!card.init_card()) {
putstring_nl("Card init. failed!"); return;
}
if (!card.open_partition()) {
putstring_nl("No partition!"); return;
}
if (!card.open_filesys()) {
putstring_nl("Couldn't open filesys"); return;
}
if (!card.open_rootdir()) {
putstring_nl("Couldn't open dir"); return;
}
putstring_nl("Files found:");
ls();
}
void ls() {
char name[13];
int ret;
card.reset_dir();
putstring_nl("Files found:");
while (1) {
ret = card.get_next_name_in_dir(name);
if (!ret) {
card.reset_dir();
return;
}
Serial.println(name);
}
}
uint8_t tracknum = 0;
void loop() {
uint8_t i, r;
char c, name[15];
card.reset_dir();
// scroll through the files in the directory
for (i=0; i<tracknum+1; i++) {
r = card.get_next_name_in_dir(name);
if (!r) {
// ran out of tracks! start over
tracknum = 0;
return;
}
}
putstring("\n\rPlaying "); Serial.print(name);
// reset the directory so we can find the file
card.reset_dir();
playcomplete(name);
tracknum++;
}
void playcomplete(char *name) {
uint16_t potval;
uint32_t newsamplerate;
playfile(name);
samplerate = wave.dwSamplesPerSec;
while (wave.isplaying) {
// you can do stuff here!
delay(500);
}
card.close_file(f);
}
void playfile(char *name) {
f = card.open_file(name);
if (!f) {
putstring_nl(" Couldn't open file"); return;
}
if (!wave.create(f)) {
putstring_nl(" Not a valid WAV"); return;
}
// ok time to play!
wave.play();
{ // this group animates the leds
digitalWrite(A5,HIGH); // this will turn audio relay on to switch background music to audio sheild sharing speakers
delay(14500); // this will delay the leds after the audio has started in miliseconds
// 1000 miliseconds = 1second
// 14.5sec delay from start
// cycle 1
digitalWrite(6,HIGH); //
digitalWrite(7,HIGH); //
digitalWrite(8,HIGH); //
digitalWrite(9,HIGH); // all on
digitalWrite(A0,HIGH); //
digitalWrite(A1,HIGH); //
digitalWrite(A2,HIGH); //
digitalWrite(A3,HIGH); //
delay(23000); //delay 23.0 sec
// cycle 2
digitalWrite(6,LOW); //
digitalWrite(7,LOW); //
digitalWrite(A0,LOW); // all off
digitalWrite(A1,LOW); //
digitalWrite(A2,LOW); //
digitalWrite(A3,LOW); //
delay(5100); // delay 5.1 sec
// cycle 3
digitalWrite(8,LOW); // 8 off
delay(5700); // delay 5.7 sec
// cycle 4
digitalWrite(9, LOW); // 9 off
digitalWrite(7, HIGH); // 7 on
delay(5000); // delay 5 sec total delay from start
// cycle 5
digitalWrite(6,HIGH); //
digitalWrite(7,HIGH); //
digitalWrite(8,HIGH); // all on
digitalWrite(9,HIGH); //
digitalWrite(A0,HIGH); //
digitalWrite(A1,HIGH); //
digitalWrite(A2,HIGH); //
digitalWrite(A3,HIGH); //
delay(6300); //delay 6.3 sec
// cycle 6
digitalWrite(6,LOW); //
digitalWrite(7,LOW); //
digitalWrite(8,LOW); //
digitalWrite(9,LOW); // all off
digitalWrite(A0,LOW); //
digitalWrite(A1,LOW); //
digitalWrite(A2,LOW); //
digitalWrite(A3,LOW); //
delay(1100); // delay 1.1 sec
// cycle 7
digitalWrite(8,HIGH); // 8 on
digitalWrite(9,HIGH); // 9 on
delay(6000); // delay 6 sec
// cycle 8
digitalWrite(8,LOW); //8 off
digitalWrite(9,LOW); //9 off
digitalWrite(A0,HIGH); // A0 on
delay(5000); // delay 5 sec
// cycle 9
digitalWrite(A0,LOW); // A0 off
digitalWrite(7,HIGH); // 7 on
delay(6000); // delay 6 sec
// cycle 10
digitalWrite(6,HIGH); //
digitalWrite(7,HIGH); //
digitalWrite(8,HIGH); //
digitalWrite(9,HIGH); // all on
digitalWrite(A0,HIGH); //
digitalWrite(A1,HIGH); //
digitalWrite(A2,HIGH); //
digitalWrite(A3,HIGH); //
delay(1000); // 1 sec delay
// cycle 11
digitalWrite(6,LOW); //
digitalWrite(7,LOW); //
digitalWrite(8,LOW); // all but A0 off
digitalWrite(9,LOW); //
digitalWrite(A0,HIGH); //
digitalWrite(A1,LOW); //
digitalWrite(A2,LOW); //
digitalWrite(A3,LOW); //
delay(100); // .1 sec delay
// cycle 12
digitalWrite(A0,LOW); // A0 off
digitalWrite(A1,HIGH); // A1 on
delay(1000); // delay 1 sec
// cycle 13
digitalWrite(A1,LOW); // A1 off
digitalWrite(7,HIGH); // 7 on
delay(1000); // delay 1 sec
// cycle 14
digitalWrite(A1,HIGH); // A1 on
delay(1000); // delay 1 sec
// cycle 15
digitalWrite(A1,LOW); // A1 off
digitalWrite(8,HIGH); // 8 on
digitalWrite(9,HIGH); // 9 on
delay(8000); // delay 8 sec
// cycle 16
digitalWrite(7,HIGH); // 7 on
delay(3000); // delay 3 sec
// cycle 17
digitalWrite(6,HIGH); //
digitalWrite(7,LOW); //
digitalWrite(8,HIGH); // all but 7 on
digitalWrite(9,HIGH); //
digitalWrite(A0,HIGH); //
digitalWrite(A1,HIGH); //
digitalWrite(A2,HIGH); //
digitalWrite(A3,HIGH); //
delay(2000); // delay 2 sec
// cycle 18
digitalWrite(6,LOW); //
digitalWrite(7,LOW); //
digitalWrite(8,LOW); // all but 9 off
digitalWrite(9,HIGH); //
digitalWrite(A0,LOW); //
digitalWrite(A1,LOW); //
digitalWrite(A2,LOW); //
digitalWrite(A3,LOW); //
delay(2000); // delay 2 sec
// cycle 19
digitalWrite(6,LOW); //
digitalWrite(7,LOW); //
digitalWrite(8,LOW); // all but A2 off
digitalWrite(9,LOW); //
digitalWrite(A0,LOW); //
digitalWrite(A1,LOW); //
digitalWrite(A2,HIGH); //
digitalWrite(A3,LOW); //
delay(1000); // dealy 1 sec
// cycle 20
digitalWrite(A2,LOW); // A2 off
digitalWrite(A3,HIGH); // A3 on
delay(3000); // delay 3 sec
// cycle 21
digitalWrite(A3,LOW); // A3 off
digitalWrite(A0,HIGH); // A0 on
delay(2500); // delay 2.5 sec
// cycle 22
digitalWrite(A0,LOW); // A0 off
digitalWrite(A3,HIGH); // A3 on
delay(3000); // delay 3 sec
// cycle 23
digitalWrite(A3,LOW); // A3 off
digitalWrite(7,HIGH); // 7 on
delay(5500); // delay 5.5 sec
// cycle 24
digitalWrite(6,HIGH); //
digitalWrite(7,HIGH); //
digitalWrite(8,HIGH); // all on
digitalWrite(9,HIGH); //
digitalWrite(A0,HIGH); //
digitalWrite(A1,HIGH); //
digitalWrite(A2,HIGH); //
digitalWrite(A3,HIGH); //
delay(6000); // delay 6 sec
// cycle 25
digitalWrite(8,HIGH); // 8 on
delay(1000); // delay 1 sec
// cycle 26
digitalWrite(8,LOW); // 8 off
digitalWrite(9,HIGH); // 9 on
delay(7500); // delay 7.5 sec
// cycle 27
digitalWrite(6,HIGH); // 6 on
delay(1000); // delay 1 sec
// cycle 28
digitalWrite(7,LOW); // 7 on
digitalWrite(A1,HIGH); // A1 on
delay(2000); // delay 2 sec
// cycle 29
digitalWrite(7,HIGH); // 7 on
delay(3500); // delay 3.5 sec
// cycle 30
digitalWrite(A1,LOW); // A1 off
digitalWrite(7,LOW); // 7 off
digitalWrite(A0,HIGH); // A0 on
delay(3000); // delay 3 sec
// cycle 31
digitalWrite(A1,HIGH); // A1 on
delay(3000); // delay 3 sec
// cycle 32
digitalWrite(A0,LOW); // A0 off
delay(2500); // delay 2.5 sec
// cycle 33
digitalWrite(8,HIGH); // 8 on
digitalWrite(9,HIGH); // 9 on
delay(3500); // delay 3.5 sec
// cycle 34
digitalWrite(7,HIGH); // 7 on
delay(1000); // delay 1 sec
// cycle 35
digitalWrite(A0,HIGH); // A0 on
digitalWrite(A1,HIGH); // A1 on
digitalWrite(A2,HIGH); // A2 on
digitalWrite(A3,HIGH); // A3 on
delay(17500); // delay 17.5 sec
// cycle 36
digitalWrite(8,HIGH); // 8 on
digitalWrite(9,HIGH); // 9 on
delay(6500); // delay 6.5 sec
// cycle 37
digitalWrite(6,HIGH); //
digitalWrite(7,HIGH); //
digitalWrite(8,HIGH); //
digitalWrite(9,HIGH); //
digitalWrite(A0,HIGH); // all on
digitalWrite(A1,HIGH); //
digitalWrite(A2,HIGH); //
digitalWrite(A3,HIGH); //
delay(10000); // delay 10 sec
// cycle 38
digitalWrite(6,LOW); // 6 off
digitalWrite(7,LOW); // 7 off
digitalWrite(8,LOW); // 8 off
digitalWrite(9,LOW); // 9 off
digitalWrite(A0,LOW); // A0 off
digitalWrite(A1,LOW); // A1 off
digitalWrite(A2,LOW); // A2 off
digitalWrite(A3,LOW); // A3 off
delay(100); // .1 sec delay
// cycle 39
// starts random flashing
digitalWrite(6,HIGH);
digitalWrite(A0,HIGH);
delay(150);
digitalWrite(6,LOW);
digitalWrite(9,HIGH);
delay(150);
digitalWrite(9,LOW);
digitalWrite(A0,LOW);
digitalWrite(7,HIGH);
delay(150);
digitalWrite(A1,HIGH);
digitalWrite(7,LOW);
delay(150);
digitalWrite(A1,LOW);
digitalWrite(8,HIGH);
delay(150);
digitalWrite(8,LOW);
digitalWrite(A2,HIGH);
delay(150);
digitalWrite(A3,HIGH);
delay(150);
digitalWrite(A3,LOW);
digitalWrite(A2,LOW);
delay(150);
digitalWrite(6,HIGH);
digitalWrite(A0,HIGH);
delay(150);
digitalWrite(6,LOW);
digitalWrite(9,HIGH);
delay(150);
digitalWrite(9,LOW);
digitalWrite(A0,LOW);
digitalWrite(7,HIGH);
delay(150);
digitalWrite(A1,HIGH);
digitalWrite(7,LOW);
delay(150);
digitalWrite(A1,LOW);
digitalWrite(8,HIGH);
delay(150);
digitalWrite(8,LOW);
digitalWrite(A2,HIGH);
delay(150);
digitalWrite(A3,HIGH);
delay(150);
digitalWrite(A3,LOW);
digitalWrite(A2,LOW);
delay(150);
digitalWrite(6,HIGH);
digitalWrite(A0,HIGH);
delay(150);
digitalWrite(6,LOW);
digitalWrite(9,HIGH);
delay(150);
digitalWrite(9,LOW);
digitalWrite(A0,LOW);
digitalWrite(7,HIGH);
delay(150);
digitalWrite(A1,HIGH);
digitalWrite(7,LOW);
delay(150);
digitalWrite(A1,LOW);
digitalWrite(8,HIGH);
delay(150);
digitalWrite(8,LOW);
digitalWrite(A2,HIGH);
delay(150);
digitalWrite(A3,HIGH);
delay(150);
digitalWrite(A3,LOW);
digitalWrite(A2,LOW);
delay(150);
digitalWrite(6,HIGH);
digitalWrite(A0,HIGH);
delay(150);
digitalWrite(6,LOW);
digitalWrite(8,HIGH);
delay(150);
digitalWrite(A0,LOW);
digitalWrite(A2,HIGH);
delay(150);
digitalWrite(8,LOW);
digitalWrite(A2,LOW);
delay(150);
digitalWrite(7,HIGH);
digitalWrite(A3,HIGH);
delay(150);
digitalWrite(7,LOW);
digitalWrite(9,HIGH);
delay(150);
digitalWrite(A3,LOW);
digitalWrite(9,LOW);
delay(150);
digitalWrite(6,HIGH);
digitalWrite(A1,HIGH);
delay(150);
digitalWrite(6,LOW);
digitalWrite(8,HIGH);
delay(150);
digitalWrite(A1,LOW);
digitalWrite(8,LOW);
delay(8000); // delay between song and flicker bulbs delay in ms
// stand by mode which will turn on flicker bulbs
digitalWrite(A4, HIGH); // flicker bulbs on
delay(200); // delay till audio is switched from audio shield to background music
digitalWrite(A5, LOW); // disconnects relay from audio shield to background music
delay(600000); // delay till flicker bulbs turn off and starts song and light show (600000ms = 10min delay)
// 1000ms = 1sec, 600000ms = 10min
digitalWrite(A4, LOW); // Turns of flicker bulbs
}}
The wave shield will use pins 1, 2 ,3 ,4 ,5 ,10
Our project uses pins 6, 7, 8, 9, A0, A1, A2, A3, A4, A5
Pins 6 ,7 ,8, 9, A0, A1, A2, A3 will be used for the pumpkins flashing lights, pin A4 will be used to control the flicker bulb set and pin A5 will be used to control a relay that will disconnect the background audio and connect the wave shield to one set of speakers. This is so that everyone will focus on the main event of the Halloween display.
Upload the audio file to an sd card, and upload the sketch to the arduino.
SKETCH
// Created by Greg Spiridakos 2011//
#include <AF_Wave.h>
#include <avr/pgmspace.h>
#include "util.h"
#include "wave.h"
AF_Wave card;
File f;
Wavefile wave; // only one!
#define redled 9
uint16_t samplerate;
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Wave test!");
pinMode(2, OUTPUT); // used by sound shield
pinMode(3, OUTPUT); // used by sound shield
pinMode(4, OUTPUT); // used by sound shield
pinMode(5, OUTPUT); // used by sound shield
pinMode(6, OUTPUT); // led light
pinMode(7, OUTPUT); // led light
pinMode(8, OUTPUT); // led light
pinMode(9, OUTPUT); // led light
pinMode(A0, OUTPUT); // led light
pinMode(A1, OUTPUT); // led light
pinMode(A2, OUTPUT); // led light
pinMode(A3, OUTPUT); // led light
pinMode(A4, OUTPUT); // flicker bulb set
pinMode(A5, OUTPUT); // auido switch over relay
pinMode(redled, OUTPUT);
if (!card.init_card()) {
putstring_nl("Card init. failed!"); return;
}
if (!card.open_partition()) {
putstring_nl("No partition!"); return;
}
if (!card.open_filesys()) {
putstring_nl("Couldn't open filesys"); return;
}
if (!card.open_rootdir()) {
putstring_nl("Couldn't open dir"); return;
}
putstring_nl("Files found:");
ls();
}
void ls() {
char name[13];
int ret;
card.reset_dir();
putstring_nl("Files found:");
while (1) {
ret = card.get_next_name_in_dir(name);
if (!ret) {
card.reset_dir();
return;
}
Serial.println(name);
}
}
uint8_t tracknum = 0;
void loop() {
uint8_t i, r;
char c, name[15];
card.reset_dir();
// scroll through the files in the directory
for (i=0; i<tracknum+1; i++) {
r = card.get_next_name_in_dir(name);
if (!r) {
// ran out of tracks! start over
tracknum = 0;
return;
}
}
putstring("\n\rPlaying "); Serial.print(name);
// reset the directory so we can find the file
card.reset_dir();
playcomplete(name);
tracknum++;
}
void playcomplete(char *name) {
uint16_t potval;
uint32_t newsamplerate;
playfile(name);
samplerate = wave.dwSamplesPerSec;
while (wave.isplaying) {
// you can do stuff here!
delay(500);
}
card.close_file(f);
}
void playfile(char *name) {
f = card.open_file(name);
if (!f) {
putstring_nl(" Couldn't open file"); return;
}
if (!wave.create(f)) {
putstring_nl(" Not a valid WAV"); return;
}
// ok time to play!
wave.play();
{ // this group animates the leds
digitalWrite(A5,HIGH); // this will turn audio relay on to switch background music to audio sheild sharing speakers
delay(14500); // this will delay the leds after the audio has started in miliseconds
// 1000 miliseconds = 1second
// 14.5sec delay from start
// cycle 1
digitalWrite(6,HIGH); //
digitalWrite(7,HIGH); //
digitalWrite(8,HIGH); //
digitalWrite(9,HIGH); // all on
digitalWrite(A0,HIGH); //
digitalWrite(A1,HIGH); //
digitalWrite(A2,HIGH); //
digitalWrite(A3,HIGH); //
delay(23000); //delay 23.0 sec
// cycle 2
digitalWrite(6,LOW); //
digitalWrite(7,LOW); //
digitalWrite(A0,LOW); // all off
digitalWrite(A1,LOW); //
digitalWrite(A2,LOW); //
digitalWrite(A3,LOW); //
delay(5100); // delay 5.1 sec
// cycle 3
digitalWrite(8,LOW); // 8 off
delay(5700); // delay 5.7 sec
// cycle 4
digitalWrite(9, LOW); // 9 off
digitalWrite(7, HIGH); // 7 on
delay(5000); // delay 5 sec total delay from start
// cycle 5
digitalWrite(6,HIGH); //
digitalWrite(7,HIGH); //
digitalWrite(8,HIGH); // all on
digitalWrite(9,HIGH); //
digitalWrite(A0,HIGH); //
digitalWrite(A1,HIGH); //
digitalWrite(A2,HIGH); //
digitalWrite(A3,HIGH); //
delay(6300); //delay 6.3 sec
// cycle 6
digitalWrite(6,LOW); //
digitalWrite(7,LOW); //
digitalWrite(8,LOW); //
digitalWrite(9,LOW); // all off
digitalWrite(A0,LOW); //
digitalWrite(A1,LOW); //
digitalWrite(A2,LOW); //
digitalWrite(A3,LOW); //
delay(1100); // delay 1.1 sec
// cycle 7
digitalWrite(8,HIGH); // 8 on
digitalWrite(9,HIGH); // 9 on
delay(6000); // delay 6 sec
// cycle 8
digitalWrite(8,LOW); //8 off
digitalWrite(9,LOW); //9 off
digitalWrite(A0,HIGH); // A0 on
delay(5000); // delay 5 sec
// cycle 9
digitalWrite(A0,LOW); // A0 off
digitalWrite(7,HIGH); // 7 on
delay(6000); // delay 6 sec
// cycle 10
digitalWrite(6,HIGH); //
digitalWrite(7,HIGH); //
digitalWrite(8,HIGH); //
digitalWrite(9,HIGH); // all on
digitalWrite(A0,HIGH); //
digitalWrite(A1,HIGH); //
digitalWrite(A2,HIGH); //
digitalWrite(A3,HIGH); //
delay(1000); // 1 sec delay
// cycle 11
digitalWrite(6,LOW); //
digitalWrite(7,LOW); //
digitalWrite(8,LOW); // all but A0 off
digitalWrite(9,LOW); //
digitalWrite(A0,HIGH); //
digitalWrite(A1,LOW); //
digitalWrite(A2,LOW); //
digitalWrite(A3,LOW); //
delay(100); // .1 sec delay
// cycle 12
digitalWrite(A0,LOW); // A0 off
digitalWrite(A1,HIGH); // A1 on
delay(1000); // delay 1 sec
// cycle 13
digitalWrite(A1,LOW); // A1 off
digitalWrite(7,HIGH); // 7 on
delay(1000); // delay 1 sec
// cycle 14
digitalWrite(A1,HIGH); // A1 on
delay(1000); // delay 1 sec
// cycle 15
digitalWrite(A1,LOW); // A1 off
digitalWrite(8,HIGH); // 8 on
digitalWrite(9,HIGH); // 9 on
delay(8000); // delay 8 sec
// cycle 16
digitalWrite(7,HIGH); // 7 on
delay(3000); // delay 3 sec
// cycle 17
digitalWrite(6,HIGH); //
digitalWrite(7,LOW); //
digitalWrite(8,HIGH); // all but 7 on
digitalWrite(9,HIGH); //
digitalWrite(A0,HIGH); //
digitalWrite(A1,HIGH); //
digitalWrite(A2,HIGH); //
digitalWrite(A3,HIGH); //
delay(2000); // delay 2 sec
// cycle 18
digitalWrite(6,LOW); //
digitalWrite(7,LOW); //
digitalWrite(8,LOW); // all but 9 off
digitalWrite(9,HIGH); //
digitalWrite(A0,LOW); //
digitalWrite(A1,LOW); //
digitalWrite(A2,LOW); //
digitalWrite(A3,LOW); //
delay(2000); // delay 2 sec
// cycle 19
digitalWrite(6,LOW); //
digitalWrite(7,LOW); //
digitalWrite(8,LOW); // all but A2 off
digitalWrite(9,LOW); //
digitalWrite(A0,LOW); //
digitalWrite(A1,LOW); //
digitalWrite(A2,HIGH); //
digitalWrite(A3,LOW); //
delay(1000); // dealy 1 sec
// cycle 20
digitalWrite(A2,LOW); // A2 off
digitalWrite(A3,HIGH); // A3 on
delay(3000); // delay 3 sec
// cycle 21
digitalWrite(A3,LOW); // A3 off
digitalWrite(A0,HIGH); // A0 on
delay(2500); // delay 2.5 sec
// cycle 22
digitalWrite(A0,LOW); // A0 off
digitalWrite(A3,HIGH); // A3 on
delay(3000); // delay 3 sec
// cycle 23
digitalWrite(A3,LOW); // A3 off
digitalWrite(7,HIGH); // 7 on
delay(5500); // delay 5.5 sec
// cycle 24
digitalWrite(6,HIGH); //
digitalWrite(7,HIGH); //
digitalWrite(8,HIGH); // all on
digitalWrite(9,HIGH); //
digitalWrite(A0,HIGH); //
digitalWrite(A1,HIGH); //
digitalWrite(A2,HIGH); //
digitalWrite(A3,HIGH); //
delay(6000); // delay 6 sec
// cycle 25
digitalWrite(8,HIGH); // 8 on
delay(1000); // delay 1 sec
// cycle 26
digitalWrite(8,LOW); // 8 off
digitalWrite(9,HIGH); // 9 on
delay(7500); // delay 7.5 sec
// cycle 27
digitalWrite(6,HIGH); // 6 on
delay(1000); // delay 1 sec
// cycle 28
digitalWrite(7,LOW); // 7 on
digitalWrite(A1,HIGH); // A1 on
delay(2000); // delay 2 sec
// cycle 29
digitalWrite(7,HIGH); // 7 on
delay(3500); // delay 3.5 sec
// cycle 30
digitalWrite(A1,LOW); // A1 off
digitalWrite(7,LOW); // 7 off
digitalWrite(A0,HIGH); // A0 on
delay(3000); // delay 3 sec
// cycle 31
digitalWrite(A1,HIGH); // A1 on
delay(3000); // delay 3 sec
// cycle 32
digitalWrite(A0,LOW); // A0 off
delay(2500); // delay 2.5 sec
// cycle 33
digitalWrite(8,HIGH); // 8 on
digitalWrite(9,HIGH); // 9 on
delay(3500); // delay 3.5 sec
// cycle 34
digitalWrite(7,HIGH); // 7 on
delay(1000); // delay 1 sec
// cycle 35
digitalWrite(A0,HIGH); // A0 on
digitalWrite(A1,HIGH); // A1 on
digitalWrite(A2,HIGH); // A2 on
digitalWrite(A3,HIGH); // A3 on
delay(17500); // delay 17.5 sec
// cycle 36
digitalWrite(8,HIGH); // 8 on
digitalWrite(9,HIGH); // 9 on
delay(6500); // delay 6.5 sec
// cycle 37
digitalWrite(6,HIGH); //
digitalWrite(7,HIGH); //
digitalWrite(8,HIGH); //
digitalWrite(9,HIGH); //
digitalWrite(A0,HIGH); // all on
digitalWrite(A1,HIGH); //
digitalWrite(A2,HIGH); //
digitalWrite(A3,HIGH); //
delay(10000); // delay 10 sec
// cycle 38
digitalWrite(6,LOW); // 6 off
digitalWrite(7,LOW); // 7 off
digitalWrite(8,LOW); // 8 off
digitalWrite(9,LOW); // 9 off
digitalWrite(A0,LOW); // A0 off
digitalWrite(A1,LOW); // A1 off
digitalWrite(A2,LOW); // A2 off
digitalWrite(A3,LOW); // A3 off
delay(100); // .1 sec delay
// cycle 39
// starts random flashing
digitalWrite(6,HIGH);
digitalWrite(A0,HIGH);
delay(150);
digitalWrite(6,LOW);
digitalWrite(9,HIGH);
delay(150);
digitalWrite(9,LOW);
digitalWrite(A0,LOW);
digitalWrite(7,HIGH);
delay(150);
digitalWrite(A1,HIGH);
digitalWrite(7,LOW);
delay(150);
digitalWrite(A1,LOW);
digitalWrite(8,HIGH);
delay(150);
digitalWrite(8,LOW);
digitalWrite(A2,HIGH);
delay(150);
digitalWrite(A3,HIGH);
delay(150);
digitalWrite(A3,LOW);
digitalWrite(A2,LOW);
delay(150);
digitalWrite(6,HIGH);
digitalWrite(A0,HIGH);
delay(150);
digitalWrite(6,LOW);
digitalWrite(9,HIGH);
delay(150);
digitalWrite(9,LOW);
digitalWrite(A0,LOW);
digitalWrite(7,HIGH);
delay(150);
digitalWrite(A1,HIGH);
digitalWrite(7,LOW);
delay(150);
digitalWrite(A1,LOW);
digitalWrite(8,HIGH);
delay(150);
digitalWrite(8,LOW);
digitalWrite(A2,HIGH);
delay(150);
digitalWrite(A3,HIGH);
delay(150);
digitalWrite(A3,LOW);
digitalWrite(A2,LOW);
delay(150);
digitalWrite(6,HIGH);
digitalWrite(A0,HIGH);
delay(150);
digitalWrite(6,LOW);
digitalWrite(9,HIGH);
delay(150);
digitalWrite(9,LOW);
digitalWrite(A0,LOW);
digitalWrite(7,HIGH);
delay(150);
digitalWrite(A1,HIGH);
digitalWrite(7,LOW);
delay(150);
digitalWrite(A1,LOW);
digitalWrite(8,HIGH);
delay(150);
digitalWrite(8,LOW);
digitalWrite(A2,HIGH);
delay(150);
digitalWrite(A3,HIGH);
delay(150);
digitalWrite(A3,LOW);
digitalWrite(A2,LOW);
delay(150);
digitalWrite(6,HIGH);
digitalWrite(A0,HIGH);
delay(150);
digitalWrite(6,LOW);
digitalWrite(8,HIGH);
delay(150);
digitalWrite(A0,LOW);
digitalWrite(A2,HIGH);
delay(150);
digitalWrite(8,LOW);
digitalWrite(A2,LOW);
delay(150);
digitalWrite(7,HIGH);
digitalWrite(A3,HIGH);
delay(150);
digitalWrite(7,LOW);
digitalWrite(9,HIGH);
delay(150);
digitalWrite(A3,LOW);
digitalWrite(9,LOW);
delay(150);
digitalWrite(6,HIGH);
digitalWrite(A1,HIGH);
delay(150);
digitalWrite(6,LOW);
digitalWrite(8,HIGH);
delay(150);
digitalWrite(A1,LOW);
digitalWrite(8,LOW);
delay(8000); // delay between song and flicker bulbs delay in ms
// stand by mode which will turn on flicker bulbs
digitalWrite(A4, HIGH); // flicker bulbs on
delay(200); // delay till audio is switched from audio shield to background music
digitalWrite(A5, LOW); // disconnects relay from audio shield to background music
delay(600000); // delay till flicker bulbs turn off and starts song and light show (600000ms = 10min delay)
// 1000ms = 1sec, 600000ms = 10min
digitalWrite(A4, LOW); // Turns of flicker bulbs
}}
Step 7: Pumpkins
Each pumpkin has a bulb and wire attached to it. Each pumpkin will connected to an outlet and will be on it's own channel. On the bottom of the pumpkins, drill a hole large enough to hold the flicker bulbs. The flicker bulb string will plug into it's own line that connects to the A4 pin of the arduino.
Step 8: Final Assembly
Build your stand. In the back of the stand will be the guts of the operation as seen in the pictures. As you can see, I used a black box for the arduino and wave shield. I placed a cover that has a seal on it as I didn't want any moisture to harm either board. Drill a hole and feed your signal wires, a plug for arduino, and audio plug through the hole. I used a 9v wall wart to power the relay board and the arduino. You will want to connect the arduino and relay board to the adapter. (Caution: do not use the power pins to to power the relay board. If you use the arduino to power the relay board it will suffer in power and the relays will not have a strong latch.)
AUDIO RELAY: Optional. if you will not use background music for your display simply leave this step out.
For the audio relay connect the common wire ( the one with no skin ) from two male plugs and speakers . On the male plug connect the red and white (left ch and right ch) together do this for both male plugs. On the relay find the n/o pin connect to one of the male plugs red and white wires. This plug will connect to the wave shield. Now on the n/c pin connect the other male plugs red and white wires to this the same way as the last one. This plug will connect to your background music either to a computer, Ipod, Stereo, or whatever you are using. Locate the line pin, now connect the speakers red and white wire to this. The relay needs to be built like the other ones in this project with diode, resistors, led and transistors. Connect the signal wire to the arduino's A5 pin. Connect relays coil wires (-) and (+) to the wall wart connection.
This setup will allow background music to play while the pumpkins are in standby mode with flicker bulbs running. Once the arduino program starts the relay will disconnect the background music and connect the speakers to the wave shield during singing. Once singing is done and flicker bulbs turn on, the audio relay will switch back on the background music.
AUDIO RELAY: Optional. if you will not use background music for your display simply leave this step out.
For the audio relay connect the common wire ( the one with no skin ) from two male plugs and speakers . On the male plug connect the red and white (left ch and right ch) together do this for both male plugs. On the relay find the n/o pin connect to one of the male plugs red and white wires. This plug will connect to the wave shield. Now on the n/c pin connect the other male plugs red and white wires to this the same way as the last one. This plug will connect to your background music either to a computer, Ipod, Stereo, or whatever you are using. Locate the line pin, now connect the speakers red and white wire to this. The relay needs to be built like the other ones in this project with diode, resistors, led and transistors. Connect the signal wire to the arduino's A5 pin. Connect relays coil wires (-) and (+) to the wall wart connection.
This setup will allow background music to play while the pumpkins are in standby mode with flicker bulbs running. Once the arduino program starts the relay will disconnect the background music and connect the speakers to the wave shield during singing. Once singing is done and flicker bulbs turn on, the audio relay will switch back on the background music.