Introduction: Christmas Greeting Wreath Arduino and MP3
This wreath uses an Arduino microcontroller with the Adafruit MP3 shield and a Parallax PIR motion sensor to detect if someone is approaching the doorway. It then plays a custom greeting pre-recorded and pitched to sound like an Elf, after which it plays a random Christmas Song. The song(s) will keep playing as long as the PIR sensor picks up motion within 15 seconds.
Step 1: Christmas Wreath Components
You'll need the following items for the arduino:
1-Arduino Uno (or similar)
1-Adafruit "Music Maker" MP3 Shield for Arduino w/3W Stereo Amp - v1.0 (http://www.adafruit.com/products/1788)
1-Micro SD card for MP3 files
1-PIR Sensor - I used a Parallax sensor from Radio Shack
1-Speaker, <=4 ohm. I picked up a budget bluetooth speaker at Fry's Electronics and pulled just the speaker out
1-Christmas Wreath
Some fuzzy pipe cleaner / case for arduino
Power, either:
1-9 VDC 1000mA regulated switching power adapter (or similar, arduino compatible)
OR
1-DC battery pack - however, my code is not optimized for lower power and the pack ran out after about 2 days of continual use
Step 2: Assemble Your Arduino, PIR Sensor, Speaker, and Shield
MP3 Shield
I purchased the un-assembled Adafruit MP3 shield so I replaced the header pins with stack-able headers so I could stack and easily prototype other items as I don't intend to leave this MP3 shield on here permanently.
PIR Sensor
The PIR sensor is connected with the following pins / colors:
Yellow (VCC) > 5v
Red(GND) > Ground
Green (OUT) > Digital Pin 2
If you change the digital pin make sure you update the following code in the Arduino INO file:
int inputPin = 2; // choose the input pin (for PIR sensor)
Speaker
Connect the speaker to the MP3 shield to the 2pin terminal blocks OR using a stereo connector if that's how you have your speaker(s) set up.
I used masking type to keep my PIR connected and hope that after the holidays it is easily removable still.
Battery / Power
I first used an 8 AA cell battery pack but it only lasted a couple of days so I switched to a 9v DC power supply which I tucked behind my garland around the door.
Step 3: Christmas Wreath Arduino Code
MP3 Files
Place your MP3 files on your SD card on the MP3 shield, make sure you have one named: merry02.mp3 for the greeting when movement is detected. You can name it what you want but update your code to match.
Also make sure you have at least 20 MP3's and that you update the array is set up to match the names and naming conventions(more info on that below).
Code
Download the ZIP or Text file attached and copy into your Arduino IDE.
Here are some notable items you'll want to change:
Change your digital input pin match which one you connected your OUT line to from the PIR sensor, note the following "intputPin" is set to 2.
/*
* PIR sensor tester
*/
int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor) <br>
Change your track names to match the MP3 files you have on your SD card on the MP3 shield. Note that there is a limit to the file name length, defined in the MP3 shield instructions. Mine are all named track00#.mp3
//this array is initialized once, randomly selected in the loop
//Instead of using a random load of MP3s from the file system, I ran into problems after looping through the filesystem about 10 times the board would lock up
//I believe there was a problem opening the file system over and over again to query for random files
//secondly, I have files on the system that I dont want to play
char* myFiles[]={"track001.mp3", "track002.mp3", "track003.mp3",
"track004.mp3", "track005.mp3","track006.mp3","track007.mp3","track008.mp3","track009.mp3",
"track010.mp3","track011.mp3","track012.mp3","track013.mp3","track014.mp3",
"track015.mp3","track016.mp3","track017.mp3","track018.mp3","track019.mp3",
"track020.mp3"};
Compile and validate it works. The sensor waits for 15 seconds to "calibrate"(I got that from the Parallax code examples. Then when movement is detected I output the random file to the serial buffer and play the file, it keeps looping about every second and then if there is NO movement for at least fifteen loops(seconds) the music stops playing and I reset the Mp3 card (musicPlayer.softReset();) - The reason I do that is it seemed when I would start a new track later with new movement I'd get a blip from the old track. With the reset I always get a clean start on the next MP3's played. I guess I should say something to Adafruit and determine if it is a bug or if I'm doing it correctly as I am with the rest.
if ( (millis() - detectTime) >= 15000){
Serial.println("No motion for 15 seconds");
musicPlayer.stopPlaying();
musicPlayer.softReset();
delay(200);
digitalWrite(ledPin,LOW);
val = 0; // we start, assuming no motion detected
detectTime = 0;
}
Step 4: Assemble and Mount the Wreath
There wasn't much to this step. I simply put the arduino in a felt bag with the PIR sensor hanging out and the DC input going into the power supply of the arduino. I stashed the bag with arduino near the wreath's battery pack and used some pipe cleaners (green or brown) to keep the cord from whipping around. The PIR just stuck out behind some needles and you can experiment with placement of the PIR. At one point I had the PIR hidden behind some decorating ribbon which was somewhat loose mesh and it still picked up movement about five feet out.
Other Ideas
I had a few other ideas to improve this which I didn't have time to incorporate yet:
Improved power management - there's an Arduino tutorial that describes how to turn off most power usage on the arduino to conserve battery power and only wake it when the PIR senses movement. I want to put that into place at some point so this can be totally battery driven. https://hwstartup.wordpress.com/2013/04/15/how-to-...
Greeting Tweaks - several family members came by for a party shortly after I put this up and suggested that I have some jingling sounds for the MP3 greeting file than the voice greeting in order to capture the persons attention, otherwise they only catch half the greeting due to their surprise. I can't wait for the applications of this at Halloween.
Music and light synchronization- I left the stock lights on the wreath which have their own timer but it would be possible to sync them to when the music turns on and to use a light sensor to automatically turn them on when the sunsets.