Intro: Auto MP3 Player
This started out as a way of greeting trick-or-treaters with a scary scream or goulish moan. There are devices that will turn on a device like a boom box connected to a 110 outletbased on a trigger from a motion detector. But when the boom box gets power someone must push 'play'.
Solving this dilema led to the discovery of the SparkFunMP3 Shield and a started a project that would automatically play an MP3based on a signal from a motion detector. When the system senses motion within about six feet it plays a track from the MP3 player.
Step 1: Four Parts to the System
There are four parts to the system.
1. The motion detector circuit
2. The Arduino Uno with the SparkFun MP3 shield
3. The Sparkfun 30 Watt Audio Amplifier Kit - STA540
4. The power supply SparkFun TOL-11296 Power Supply - 12V/5V (2A)
Step 2: The Motion Detector Circuit
The motion detector circuit is built on a prototype board found at MCM Electronics part No 21-4610 but any small printed circuit board (PCB) could be used. Radio Shack has one called Dual General-Purpose IC PC Board Model: 276-159 Catalog #: 2760159 that could be adapted. (I will miss RadioShack. I believe one can still get their products online.)
Step 3: The Motion Detector
The motion detector from SparkFun is called PIR Motion Sensor (JST) SEN-13285 RoHS. This a goodproduct and includes a pigtail for connecting to the PCB. PIR sensor modules (motion detectors) by SparkFun, Parallax, Radio Shack and AdaFruit have been used in several projects. The documentation of the pin outs of the SparkFun PIR is a bit inconsistent and confusing. The Radio Shack and the Parallax units work well and are responsive and well documented. The PIR sensor used in the project is the AdaFruit #189. By studying the AdaFruit PIR sensor it was discovered that the AdaFriuit PIR is an HC-SR501. The datasheet for this sensor can be found at http://www.mpja.com/download/31227sc.pdf
This sensor is superior because it provides two trim posts that allow one to change the distance the sensor is sensitive to motion and the time the sensor sends out a signal before reaming for the next cycle. The HC_SR501 also has a a jumper switch that allows one to set the sensor to either repeatable trigger or non-repeatable trigger. Repeatable trigger allows a new signal to begin a second On cycle before the first On cycle has eneded. In Non-repeatable trigger the first cycle must be ended before a new signal can be sent.
And speaking of first cycles: Be patient with the HC-SR501 in the first cycle becasue it takes a minute or to for the HC-SR501 to calibrate itself when it is first turned on.
Step 4: Connecting the Motion Detector to the PCB
The PIR Sensor is connected to the PCB using a male to female jumper wire cable.The female end receives the PIR sensor. The male end of the jumper wire cable goes into female headers soldered onto the PCB. The female headers are SparkFun part number PRT-00115. Break off three positions of the female header and solder onto the PCB.
This makes the PIR sensor removable from the PCB. Using the jumper cable instead of just soldering wires on to the leads and the PCB may seem like lot of trouble to make the PIR sensor a removable module. But in the construction of the project it has been found that making the PIR removable is worth the trouble for several reasons.If the system is not working and one is trouble shooting being able to swap out units can be important. Also while constructing the unit being able to disconnect the PIR to get at other components is to fit them into the project box can be helpful.
Step 5: Soldering the Power Plugs
The power input and the power output from the PCB are accomplished using phono plugs or RCA plugs. This may seem old fashioned or even strange but they are connectors that are small enough to fit easily into the project box and big enough to be easily soldered, widely available and fairly inexpensive.
But any two conductor connector could be used: banana plugs. molex connectors, crimp and lug connectors
To be consistent the sleeve connection to the arm is always ground and the tip
connection to the cup is always voltage supply, in this case 12 volts dc. When connecting the voltage wire to the cup it is best to keep the amount of exposed wire to a minimum to avoid shorting the power lead to the grounding arm. If there is any doubt that the power and the ground might touch a way of insulating the two exposed leads is to wrap a pieces of paper tape , like masking tape, around the grounding arm..
Another tip is to be sure the barrel for the plug or jack are on the wires before soldering the connections. If the other end of the wires are already connected to another terminal one would have to desolder the wire connections to get the barrel on the plug or jack. One of the reasons to make the power to the PCB through a connector is the PIR sensor circuit can be tested as a unit. Also if one is troubleshooting a sub circuit within the system one of the first things tested is "Is there power?" Using modular power connections one can much more easily test for power.
Step 6: Testing the PIR Sensor Circuit
This project guide assumes that the builder has a digital multimeter.
If one is not owned it would be a good idea to acquire one. As usual the vendor of choice is the 'Shack. There are more expensive meters by Fluke and others but if you don't already have one this one will get you started for twenty bucks. It will provide AC and DC voltage, resistance, and amperage and is pretty much a 'must have' for a project of anything but minimal complexity. When the female power-in connector, PIR sensor, the indicator LED and the 220 ohm resistor have been installed on the PCB the sensor circuit can be tested. (The LED is called an indicator LED because it indicates that the PIR is sending a signal.) To test the circuit first test the LED to resistor connection by taking a nine volt battery in a holder and touching the negative terminal of the battery to the negative side of the LED and the positive side of the battery to the lead on the 220 ohm resistor that is farthest away from the LED. If the LED glows he indicator subcircuit works. If it does not check to see that the LED polarity is correct, the solders are good, and the components, the LED and the resistor, are good.
When the indicator LED is working test the PIR motion detector. Find the wire coming out of the PCB from the PIR sensor signal (Shown on the pictorial called "PIR to MP3 playey to 30 Watt Amp" as the green middle wire.) Twist the exposed end of green PIR signal wire to the exposed end of the wire going out of the PCB near the LED indicator resistor This wire is colored purple on the pictorial called "PIR to MP3 playey to 30 Watt Amp") When those two are connected rig a male phone plug to a nine volt battery.
When the battery is connected to the PCB the PIR should operate as described on the datasheet. That is, when one waves a hand in front of the PIR, the indicator LED should come on and, depending how the trim pots on the PIR are set, the indicator LED should stay on for some seconds and then go off. Then after a few seconds the PIR will reset and a hand movement in front of the PRI sensor should trigger another on and off cycle.
Be patient with the PIR sensor on the first cycle. It takes a while for sensor to cycle the first time.
Step 7: Setting Up the MP3 Shield
With the PIR sensor working set up the Arduino to MP3 shield system.
SparkFun has an excellent section called a Hook Up Guide on setting up the MP3
shield. Basically there are two parts to setting up the MP3 shield: hardware and software. The hardware mainly is soldering the headers onto the shield. When the headers have been solder onto the MP3 shield then the shield header pins can be slid into Arduino Uno Rev3. There are two set of six pins on one side and two sets of eight pins on the other side so getting all twenty-eight pins lined up takes some concentration but it is not too bad.
The software is a little more work. Again the Hook Up Guide has a good section on downloading and installing SFEMP3Shield Arduino library. The thing that stumped this builder is that a folder must be created for the SFEMP3Shield Arduino library. I got that part but I didn't get the fact that one must be careful to not use symbols in the library folders such as hyphens. When the library was first installed errors were thrown because of hyphens in the library folder name.
With the SFEMP3Shield Arduino library installed the next step is to install the sketch on Arduino which operate the shield. I struggled with this for some time because all the examples first found were hundreds of lines long with sections for playing multiple tracks, shuffling tracks and lots of advanced features not needed for this project. A plain and simple sketch was finally hammered out is copied herewith below. One problem I had was caused by not reading the SparkFun Hookup guide carefully. I was trying to use digital pins 12 and 13 for input and output. These pins are used for other functions by the shield and the only two digital pins available are 5 and 10. So 5 is used as the input from PIR sensor and 10 is used as output to the indicator LED.
Step 8: MP3 Shield Sketch
NOTE: This is an image of the sketch that is posted here so it can be easily
read. The sketch could not be displayed using HTML because the tags in the sketch interfere with HTML. To get a soft copy of the sketch click here
Step 9: Testing the MP3 Shield
First test the MP3 shield as a unit. A micro SD card
has to be supplied with a track called "track001.MP3" because that is the way the shield library is written. An inexpensive M3 player was purchased at, where else, RadioShack.
The SanDisk was used to put track001.MP3 on a micro SD
This is the card that fits in the MP3 shield. Connected to my
computer via USB the micro SD card shows up in Windows Explorer as "Removeable Disk". A short MP3 (six seconds) was put on the micro SD card since would be used for testing and short MP3 would keep the test cycle more brief.
Provide power to the Arduino via USB or wall wart. Without the PIR to send
it instructions the Arduino will play track001.MP3 indefinitely in a loop. A set of headphones or ear buds can be plugged into the shield to hear the
MP3 playing. Alright, alright, alright two out four systems working. Two more to go.
Step 10: Connect the MP3 Shield to the PIR Sensor
Once again on the PIR sensor PCB find the green wire which is the output
from the sensor. Take the end of the green wire and slide it into MP3 shield pin 5. Then take the purple wire, which is the out put from the Arduino and put it into the header slot for pin 10.
Then power is supplied to the PIR sensor PCB by either the nine volt battery or the 5 volt output from the Arduino. This should make track001.MP3 play once triggered by motion in front of the motion detector. If it doesn't work test the PIR sensor again by itself. Then make sure the shield is working. If both systems work independently both don't work together, either they are hooked up incorrectly or there is something wrong with the sketch. Is the indicator LED lighting up? If it is that part of the sketch is working so one could imitate the part that is working to get the MP3 shield to work.
Step 11: Thirty Watt Stereo Amplifier
Most of the work done on this subsystem is done in following the
directions for building the amplifier called STA504. Parenthetically, Sparkfun had done a great job on the STA504.
If you have ever built any other stereo amplifier you will realize that the STA540 is a sweet piece. I tried an amp from Velleman but the pot hookup was a mess. I finally ditched it and went with the STA 540 which has the pots built in. Also the instructions, especially the testing after construction set SparkFun apart. I have done dozens of kits and usually you put it together, plug it in and if it doesn't work your cooked. A little testing goes a long way. Well done.
The speakers used in the project are 3.5 inch which were bought at the 'Shack about twenty years ago. But there are some 3.5 inch speakers
that can be purchased on line for less than $20 for the pair: PYLE PLG3.2 3.5-Inch 120 Watt Two-Way Speakers When the STA504 is built it can be tested by providing a signal and power. A signal can be provided with a rig
from my favorite store. The light green plug on the right side is a standard
3.5" stereo cable available from the Shack as Model: 4201016 Catalog #: 4201016 AUVIO 3-Ft. 1/8" (3.5mm) Stereo Cable
In the picture four wires can be seen coming out of the stereo jack
two black wires going up and down near the light green plug and a green wire on the top left and a yellow wire on the bottom left. The black wires are ground wires that run to the signal input ground for the amplifier. The yellow and green wires run to the right and left inputs to the amplifier. The other end of the standard 3.5" stereo cable with the light green plug goes to the out put of the SanDisk or any other device that will put out a stereo signal like an iPhone, Walkman, or smart phone. Power for the amp can come from a battery but nine volts won't get us there by itself. A couple of C, D, or double A batteries in series with the nine volt will provide enough punch to test the amplifier. That is, take a C, D or double A bateries in a battery holder. Connect the the red wire from the nine volt battery holder to the black wire on the C, D, or double A battery holder. Then connect the the red wire of the nine volt battery holder to the power input with plus sign. Connect the black wire from the C, D, or double A battery holder to the power input on the amplifier marked with the minus sign.
If it doesn't work go back and retest the amplifier using the excellent test instructions in the SparkFun assembly guide. The first time I tested it I thought I had a dud but then I realized I had the 'Standby' button on.
Step 12: Power to the Sensor PCB
To this point testing of the three subsystems, the PIR sensor PCB,
the Arduino with MP3 Shield, and the 30 watt amplifier have been done using batteries. At this point the three systems are connected to the the SparkFun 12 volt power supply.
This a great power supply because it is regulated
and will provide up to two amps of current. The SparkFun power supply TOL-11296 does not come with a cord that goes bertween the power supply and the wall house main outlet. But if you are like me you have sevearl of these lying around in the house. If not a cord can be obtained on line for about five bucks.
To get the right shape to fit the TOL-11296 get cord marked "EIC C 13". So the power supply has a cord to go the wall now a cable is needed to go the sensor PCB.
Step 13: Power to the Amplifier From the Sensor PCB
Power to the amplifier from the Sesnor PCB is effected by simply
soldering two wires, a 12 volt and a ground, to the sensor PCB. On STA 540 amplifier Sparkfun has graciouly provided PCB mounted screw type terminal blocks which makes for quick and easy connection.
Step 14: Power to the Arduino
Power to the Arduino is provided by creating a male phono plug
with a pig tail. Solder the loose end of the pig tail to the voltage side and the ground side of the sensor PC board.
To get to the Arduino a 5.5x2.1mm, center-positive barrel jack is needed. This can be obtained from SparkFun as 9V to Barrel Jack Adapter PRT-09518.
Or if you are like a lot people you have old wall warts kept from devices
that you no longer have. If that is the case and one of them is 5.5x2.1mm, that is, it will fit the Arduino power jack, then your in business.
The cable on most wall warts is shielded cable so unbrading the shielding
and separating it from the center conductor will be required. Also the power jack on the Arduino is center positive and sleeve ground. It is important to make sure that the polarity is correct on the power plug to the Arduino to avoid damaging the microprocessor. Arrival at the fun part has finally been realized. Plug all the subsytems together and play the MP3 track. It is advisable to turn the the amplifier to "Standby" when power is applied to the system because sometimes the amplifier pops when it first comes on. If it doesn't work test the components separately to see where the weak link is and then start string subsystems back together to get them to work as a unit.
Step 15: Deploy in Project Box
The three circuit boards were placed on a 3" x 9" x 1/8" clear
plastic board using 6 x 32 x 1/2" machine screws and standoffs made of the body of a Bic pen cut into 3/16" lengths with an Exacto microsaw. But the boards could be mounted on the bottom of the project box.
Something has been run into that cannot be obtained from RadioShack.
Well it can but the best deal comes from Home Depot. That is the project box. The aluminum boxes may be more durable but they harder to work with and cost a lot more than plastic. And the plastic boxes big enought for this project are in the $15 to $20 range. The box used comes from Sterilite and costs $3. The platic board holding the PCBs was mounted to the bottom of the box. Then a rectangular hole about 3/4" x 1" was cut in the side of the box big enough for the EIC C 13 power cord to go through Directly adjacent 3/4" x 1" rectangular hole a round hole about
with a diameter of 3/16" was drilled to accept the cord. With
the poer cord plug fed thruough the hole a piece of clear plastic was mounted with screws over the hole cut for the power cord plug. This provides some strain relief on the cord and makes the project a little more watertight. It is not intended for the project to waterproof but it would be good if, while it is greeting the trick-or-treaters, if it begins to rain, it will shed water long enough for me to go outside and bring it inside the house before it is ruined.
The power supply box is mounted on the back of the project box. Coat hanger wire was wrapped around a pair needle nose pliers to create a small loop that would accept a 6 x 32 x 1/2" machine screw. Then the wire was bent to fit the shape of the power supply box. The component which was most problematic in mounting in the box was the PIR sensor. There are two holes in the PIR sensor PCB but they are so small that none of the screws in my stash would fit through them. Smaller screws could be acquired at the Home Depot but there are electronic components directly adjacent the holes so that the nuts for the even the tiniest screws would bear on the electronic components them which could have unintended consequences.
To solve this issue two small pices of clear acrylic were superglued to the sides of the motion detector and these pices were drilled
for 6 x 32 x 1/2" screws with nuts.
Step 16: Prologue
So the project is complete and has been tested successfully in the front yard.
About half way through building this my wife thought I was crazy and was rolling her eyes at me. Now that auto MP3 player has been demonstrated she thinks it is cool and says we should use it at Christmas time to play carols for arriving guests.