MP3 Triggered by Motion Detector

Thread Starter

allenpitts

Joined Feb 26, 2011
163
Hello All About Circuits forum,

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 outlet
based on a trigger from a motion detector.

SensorPlug.gif

But when the boom box gets power someone must push 'play'.

Solving this dilema led to the discovery of the SparkFun
MP3 Shield and a started a project that would automatically play an MP3
based on a signal from a motion detector.
When the system senses motion within about six feet it plays a track from the MP3 player.
Project_front_b.gif
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)
PIR_to_MP3_shield_STA054_amp_150420_b.gif
The Motion Detector Circuit
The motion detector circuit is built on a prototype board found at MCM Electronics part No 21-4610
Prototype_board_b.gif
but any small printed circuit board (PCB) could be used. Radio Shack has one
RadioShack_276-159.gif


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.)

The Motion Detector
The motion detector from SparkFun is called PIR Motion Sensor (JST) SEN-13285 RoHS. This a good
product 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. By studying the AdaFruit
AdaFruit_PIR.gif


unit it was discovered that the AdaFruit unit is an HC-SR501.

HC_SR501_front.gif

HC_SR501_back.gif

The HC-SR501 is superior because it has two trim pots (potientiometers or variable resistors) that allow for adjustment.
One pot changes the time that the PIR sends a signal.
The other pot changes the distance that the sensor detects a change in the infrared response.
The data sheet on the HC-SR501 can be found at
HC-SR501 datasheet
Some of the HC-SR501s, dependent on the supplier, have a jumper pin switch that allows one to
change the triggering function from repeatable to non-repeatable. In non-repeatable mode the sensor
waits until the signal stops sending before it can be triggered again.
In repeatable mode the sensor will begin a second signal during the first signal being sent if
the sensor detects motion before the first signal is complete.

Another reason for using the HC-SR501 is it sends a HIGH, 3.3 volt, signal. Some of the other
PIR sensors, like the SparkFun, send a LOW signal. So the Arduino pin receiving the signal from the PIR sensor
must have a pull up resistor to pull the Aruino pin high. Then the trigger in the Arduino code
looks for a LOW signal from the sensor. If a sensor which sends out a LOW signal is used the sketch for the Arduino
would have to be change to accomaodate the difference in signals.

Connecting the Motion Detector to the PCB
The PIR Sensor is connected to the PCB using a male to female jumper wire cable.

Male_Female_jumper_wire.gif

The female end recieves 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.

Unable to post more GIFs because of forum restriction.
More GIFs at
https://www.instructables.com/id/Auto-MP3-Player/

This makes the PIR sensor removeable 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 removeable module. But in the constuction of the project it has
been found that making the PIR removeable 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 constructng the unit being able to disconnect the PIR
to get at other components is to fit them into the project box cna be helpful.

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 enought to fit easily into the project box and big enough to be easily soldered,
widely available and fairly inexpensive.

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 exposed the amount
of exposed wire to a mimimum to avoid shorting the power lead to the grounding arm.
If there is any doubt that the power and the ground might tough wrapping a piece
of paper tape, like masking tape, is a way of insulating the two exposed leads.

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.


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 mopre 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 resisitor, 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 resisitor
This wire is colored purple on the pictorial
called "PIR to MP3 player 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.


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 is that
one must be careful not use symbols in the libray folders such as hyphens.
When the libaray 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.


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
arduino sketch

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
card.
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.


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.


Thirty Watt Stereo Amplifier
Most of the work done on this subsystem is done in follwing 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.

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 between the power supply and the
wall house main outlet. But if you are like me you have several 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.

The plug built into the TOL-11296 has a female 4 pin Molex plug.
To recieve the female 4 pin Molex plug a cable of the type used
in desk top computers to connect to a hard drive is used. The
description found is a "5 x 4Pin IDE Molex to 15 Pin Serial ATA SATA
Hard Drive Power Adapter Cable Cord".
The Hard Drive Power cable pictured has a black end and a white end.
The black end is cut off. There are five wires coming out of the
Hard Drive Power cable. Only two are needed. Cut the three unneeded
wires and tape them or secure them somer means of wire management.

Then the Hard Drive Power cable is connected
to the Molex 4 pin female from the TOL-11296. First use a multimeter
used to find the 12 volt supply. (There are two grounds from the
Molex 4 pin female from the TOL-11296. I connected to one of
the grounds and was not getting 12 volts. I believe the first
ground connected to was the ground for the five volt supply.
When I tried the other ground I got a steady 12.3 volts)


The other end is connected a male phono plug.
Use the multimeter to test the male phono plug for 12 volts.
If a female phono jack has not been connected to the sensor PCB, do that
now and test for 12 volts at the sensor PCB

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.


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.

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 are big enough for this project are in the $15 to $20
range. The box used comes from Sterilite and costs $3.
The plastic 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.


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.
 

Attachments

Top