Operating a relay with a PIR sensor

Thread Starter

allenpitts

Joined Feb 26, 2011
166
Hello Electronics forum,

I have got the PIR sensor circuit to work

Now need to get the sensor to work a relay to close a circuit
that turns on an MP3 player.
Made sure that the out put of the sensor
http://www.adafruit.com/product/189
at 3.3 v matches the relay which is a 3V
relay

But it wont latch the relay.
Any ideas why the signal from the PIR sensor
won't operate the relay?
Thanks.

Allen in Dallas
 

Reloadron

Joined Jan 15, 2015
7,543
Remove the LED and 220 Ohm resistor. The LED and resistor are dropping the voltage so the relay coil never sees 3 volts. Then we can go from there if the relay works. Also, make sure the PIR can source the needed relay current. Do you have a data sheet for the PIR and relay?

Ron
 

Reloadron

Joined Jan 15, 2015
7,543
The data sheet for the relay with the 3 volt coil calls out 50mA. I found that. I am not sure how much current the PIR sensor module can source? They do mention the PIR sensor should be powered by 5 volts but does work on 3 volts but for 3 volt supply operation you need to bypass the 3 volt regulator on the little circuit card. Did you do that since you seem to be powering the PIR off 3 volts?
Finally if the PIR can't source the 50 mA for the relay and the LED current what you will need to do is place the relay and LED in a parallel configuration and power them using a transistor driven by the PIR. That would be my guess anyway. It won't work as drawn, I can tell you that much.

Ron
 

Reloadron

Joined Jan 15, 2015
7,543
+1 to Reloadron's replies.

Relay Datasheet

Decoder I.C. Datasheet

Can't tell if there is any drive circuitry on the board. If not, looks like 10mA is output source current.

Attached a schematic with transistor to try. Do not omit protection diode around relay coil.

I would do it like Pencil's drawing with one change.

Pencil, since we have a 2N2222 in there I would just let the transistor also drive the LED in parallel with the relay. I am guessing maybe 15mA on that LED? I would put the LED up there with the relay on the collector. I should have mentioned the need for the flyback diode too. :)

Ron
 

Pencil

Joined Dec 8, 2009
272
I would do it like Pencil's drawing with one change.

Pencil, since we have a 2N2222 in there I would just let the transistor also drive the LED in parallel with the relay. I am guessing maybe 15mA on that LED? I would put the LED up there with the relay on the collector. I should have mentioned the need for the flyback diode too. :)

Ron
Feature creep. I was adding to the original without consideration for best design practice.:)

Re-spun drawing as Rev 2.

P.S. Relay current requirements will cause terrible battery life.
 

Attachments

Last edited:

Thread Starter

allenpitts

Joined Feb 26, 2011
166
Hello Pencil and Relaodron,

I got it to work! Thanks. I have been working on this
for weeks. I should have used the multimeter to
troubleshoot. When the multimeter was connected
between the LED and the resistor and then to ground
(in my circuit) the reading was 1.77 volts. Not enough to latch the
relay.
Used your excellent shematic and it works like a champ.

The yellow LED on the right comes on when the relay switch closes. The red LED is between the collector
and the 220 resistor as shown on Pencil's schematic.
The next step is to make the relay turn on an LED sequence display. When that works will post it to this
thread. Then after that will use this circuit to turn on an MP3 player on an Arduino.

Also plan to take this circuit and move it from the bread board to an Archer 276-159
http://www.radioshack.com/dual-general-purpose-ic-pc-board/2760159.html#.VOpTAe8tHIU

Thanks again. I am still learning electronics but I have some skills with web development,
schematics drawing and Fritzing. If I can ever reciprocate the favor by being of service in
one of those endeavors I am and will remain

Your humble servant,

Allen Pitts, Dallas Texas
 

Thread Starter

allenpitts

Joined Feb 26, 2011
166
Hello Circuits Forum,

Couldn't get to my soldering iron today but could get to the drawing tool.
First I did a pictorial of the breadboard. I am pretty sure this one is good
although I will prove it this week end.

Thinking of getting off the breadboard for a more permanent solution
using my old friend the Archer 276-159. Not as sure on this one but
will test this weekend and advise. But if you can see any flaws your
input is appreciated.

Both of these are based on Pencil's design and Relaodron's feedback.





Thanks.

Allen in Dallas
 

Reloadron

Joined Jan 15, 2015
7,543
At a glance it looks OK to me but I am not as good with the eyes and following things as I once was. With the demise of Radio Shack I will miss those little boards. :)

Ron
 

djsfantasi

Joined Apr 11, 2010
9,180
Then after that will use this circuit to turn on an MP3 player on an Arduino.
Why not connect the PIR sensor directly to the Arduino, and use it to turn on the MP3 player instead of a relay. Since the MP3 player is part of the Arduino. Is it an Arduino or ADAFruit shield (I use the ADAFruit Music Maker MP3 shield)?
 

Pencil

Joined Dec 8, 2009
272
Allen,

You stated your relay has a 3V coil. Your circuit, using a 9V battery, is going to damage the relay.

I mistakenly thought you could power it from 4.5V (3 1.5V cells), my mistake, I was looking at the voltage range for
the decoder I.C.

One solution is to get a relay with a 9V coil and re-calculate the resistor values for the LEDs and base of the transistor.

I believe using a 9V alkaline cell is going to give poor battery life compared to other cells such as AA, C or D. See chart linked below, compare mAh capacities to see what I mean.

Battery Capacity Chart

As I stated earlier, use of a relay will cause poor battery life, maybe consider the use of rechargeable batteries.

You have a nice project, before committing to a board maybe review the power source to insure the best outcome.

Post any questions.
 

Thread Starter

allenpitts

Joined Feb 26, 2011
166
Hello Forum,

ReloadRon: Yse the RadioShack bankruptcy and store closings really bums me out. Not only becuase it is headquartered in Fort worth which is sister city to my native Dallas but also because it is right
down the road from me and now I have to travel to Fry's to get components. I did find a knock off
of the Archer 276-159B
http://www.mcmelectronics.com/product/21-4595
and maybe an improvement to it at
http://www.mcmelectronics.com/produ...il&utm_medium=email&utm_campaign=ConfirmEmail

Disfantasi: Will ditch the relly when I get to the Arduino but am having trouble with a sketch which simply
plays the same MP3 track over and over when triggered by the PIR sensor. But that is the subject of another thres probably oj a different forum.

Scott Wang: Not sure how the relay can have a wrong side since it is just a switch and does not have polarity.

Will reduce the voltage of the supply and change the relay load to a LED display this weekend and advise.

Thanks

Allen in Dallas
 

Thread Starter

allenpitts

Joined Feb 26, 2011
166
Why not connect the PIR sensor directly to the Arduino, and use it to turn on the MP3 player instead of a relay. Since the MP3 player is part of the Arduino. Is it an Arduino or ADAFruit shield (I use the ADAFruit Music Maker MP3 shield)?
It is a a SparkFun MP3 Player Shield
https://www.sparkfun.com/products/10628
Having a hard time getting it to work.
The sketch is hundreds of lines long.
All I want it to do is play one track when
the PIR sensor fires.

Thanks.

Allen in Dallas
 

djsfantasi

Joined Apr 11, 2010
9,180
Are you using the library? I am not familiar with the Sparkfun product, but do use the Adafruit MP3 shield. With the library and its example sketches, I was able to play a track on an event in less than 100 lines of code.

Can you attach your sketch? I'd like a chance to look at it. Tonight, I'll upload my example, if you'd like.
 

Thread Starter

allenpitts

Joined Feb 26, 2011
166
Hello DJ,

I like Adafruit and am using their PIR Sensor becuase it has sensitivity and timer trim pots
that the Parallax, SparkFun and Radio Shack Sensors do not.

But would like to use the SparkFun MP3 Shiels because I already bought it but
more importantly it sits right on top of the Arduino Uno so I don't have to have another
breadboard or prototype PCB.

But if I can't get it to work its useless and I will have to start all over with Adafruit.

Here's the sketch

+++++++++++++++++++++begin sketch+++++++++++++++++++++

#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>

SdFat sd; //create an instance of SdFat named sd
SFEMP3Shield MP3player; //create an instance of SFEMP3Shield named MP3player
int triggerPin = ??; //this sets the pin the PIR will use
boolean triggerState = false; //this variable indicates if detection is in progress
void setup() {
//start the shield
sd.begin(SD_SEL, SPI_HALF_SPEED);
MP3player.begin();

//you also need to set the input pin to be an input
//this was missing from your code
pinMode(triggerPin, INPUT);
}

void loop() {
//if trigger pin reads HIGH then PIR is detecting
if (digitalRead(triggerPin) == HIGH) //see how this is different from your code
{
if (triggerState == false) //only play track if not already played this detection
{
triggerState = true; //set triggerState, reset only after triggerPin goes LOW
MP3player.playTrack(1); //play track 1, will only happen once per detection
}
} else {
if (MP3player.isPlaying() == false) //triggerPin must have been LOW to get here
{
triggerState = false; //track must be done playing to get here, re-enable track
}
}
// no need to stop the player after 6 secs, it'll stop on it's own
}

+++++++++++++++++++++end sketch+++++++++++++++++++++

Thanks
Allen in Dallas
 
Top