Introduction: Sensors Trigger Halloween WAV Files
Nothing begs for automation like Halloween! This instructable will tell you how to get your Arduino to play personalized Halloween WAV files in an orchestrated manner as people walk to and from your house. This project will help you step up your game for next Halloween!
The Arduino program is designed for three IR sensors triggered in succession and three speakers. As each sensor is passed a WAV file is played by the speaker for that location. Relays are used to switch the sound coming from the amplifier module to the appropriate speaker. The first sensor is furthest from the door and triggers the first WAV file. The second sensor is between the other two and plays the second WAV file. The third sensor is located nearest the door and plays its own WAV file. Then, as the guests leave your door the second IR sensor plays a fourth WAV, followed by a fifth WAV file when the first sensor is again passed. The Arduino doesn't have enough memory to store the WAV files, so I've added an SD card module.
Special devices used include an Arduino UNO, a micro SD module, an amplifier module which uses an LM386 amplifier, and some relays. Other than the Arduino, these items can be purchased for only 2 – 3 dollars (US) each.
Next Halloween, I’ll build on this idea by using additional relays to trigger movement in some of our Halloween props. I also may play with an ultrasonic sensor to determine whether visitors are big or small, allowing the Arduino to select either scary or tame Wav files to play.
Step 1: Obtain Parts
You’ll need the following components to make this Halloween project:
Arduino Uno, Radio Shack p/n 2760128
8-ohm mini-speaker, Radio Shack p/n 2730092 (Qty 3)
Speaker wire, 18/2, 60 feet, Radio Shack p/n 2780008
Breadboard, Radio Shack p/n 2760003
Hookup wire, Radio Shack p/n 2781215
Jumper wires, Radio Shack p/n 2760173
Micro SD card, 8GB, Radio Shack p/n 4400183
Micro SD card module, Catalex brand, bought on ebay
LM386 amplifier module, bought on ebay or Radio Shack p/n 2761731 + additional parts
Infrared Human motion sensor, bought on ebay as HC-SR501
2 relay module (Qty 2), bought on ebay
DC Power supplies (Qty 2)
Pin wires, female-female and female-male
Coat hangers (Qty 3)
Step 2: Mount & Wire Parts
Follow these pictures to wire this project:
A separate 5-12 VDC power supply (not shown) needs to be used for the amplifier module. Be sure to connect the common of the amplifier module power supply to the common of the Arduino power supply or else your sound will be hissy, full of static, and lacking volume. Also, the Arduino was finicky about its power supply. It did much better when powered by USB (5VDC) than with a 12 VDC supply that I had.
I found it useful to have an LED indicator to show me when a sensor had been triggered.
Step 3: Upload Software
I used the TMRpcm library for playing WAV files with the Arduino. It can be downloaded from https://github.com/TMRh20/TMRpcm . I’ll say more about how to use this library in Step 7. Next, import the library into your Arduino sketch. (Procedure for importing libraries described at http://arduino.cc/en/Guide/Libraries).
A copy of the Arduino code is included with this instructable. After tweaking it to your own needs, e.g. changing WAV file names to match the ones your using, upload the code to your Arduino.
Step 4: Prepare Sensors
The IR sensors have exposed electronics, so they really need a housing. Plus, they have a field of view that exceeds 120 degrees. I wanted a much narrower beam. Hunting around the house, I happened on the idea of mounting the sensors in cups. By cutting out a well measured rectangle in the bottom of the cup, I was able to hot glue the sensor into the cup. After first attaching three pin wires (female connector on both ends) to the sensor, I then put a plastic cup (one with ribs is best as you’ll see in a minute) with small hole in the bottom over the first cup. The wires will be hanging out of the hole in the bottom of the plastic cup. If necessary the cups could be glued together, though I didn’t need to. I then used coat hanger wire, which was first shaped around a soup can, to serve as a sensor mount that keeps the whole assembly off of the ground. The circle in the hanger wire is slid over the bottom of the cup and can be popped over the cup ribs for a tight fit. The hangar wire can be pushed into the ground at the spot of your choice.
A note about sensor adjustments: Two potentiometers are on the sensor board, Sx and Tx. The Sx is for sensitivity (range) adjustment. The Tx determines how long the sensor output stays on after it no longer senses a person. I set the delay to its minimum of about 3 seconds.
Step 5: Construct Speaker Housings
You can spend any amount of time and money making speaker housings, but since the speakers will be hidden in the bushes I went the cheap route and mounted them in food boxes after cutting out a hole for the speakers (Radio Shack p/n 2730092). It helps to put a knot in the section of speaker wire inside the box to act as a strain relief, preventing the cable from tugging on the speaker. Seal up the box with tape when you’re done.
Step 6: Prepare and Connect Cables
Bell wire (22 AWG) or hookup wire (Radio Shack p/n 2781215) is great to use because it plugs into a breadboard and into the female end of pin cables. The IR sensor cables require three conductors. For my house, I made two 15 foot cables, and one 5 foot cable. Cutting three wires for each cable length, I then wrapped electrical tape around the cable every 18 inches to keep the wires together and neat.
Step 7: Select and Format WAV Files
Many WAV’s are available on the web. Or make your own. This is one of the great benefits of this project: You can make your own personalized Halloween WAV files! Download Audacity software to make WAV files or convert your files downloaded files into a usable format. Use the following tips when using Audacity to ensure that the TMRpcm library can play your WAV file:
- · Tracks > Stereo Track to Mono (If your WAV is not in stereo, duplicate the mono track. Set one as left, the other as right. Then ‘Make Stereo Track’. Now you can do ‘Stero Track to Mono’. It’s the only way it will work.)
- · Project Rate (HZ) > set to 32000, 22050, 16000 or 11025
- · File > Export > Save as type: Other uncompressed files > Options...
- · Select WAV, Unsigned 8 bit PCM
- · Make sure the file names (not counting the WAV extension) are only eight characters or less
- · Audacity can be used to increase the volume of the WAV files.
Copy your WAV files into the root directory of the micro SD card.