In this simple project, we’ll build a motion-sensing arduino alarm using a PIR (passive infrared) sensor and an Arduino microcontroller. This is a great way to learn the basics of using digital input (from the sensor) and output (in this case, to a noisy buzzer) on your Arduino.
This Arduino alarm is handy for booby traps and practical jokes, and it’s just what you’ll need to detect a zombie invasion! Plus, it’s all built on a breadboard, so no soldering required!
Download the project code here.
It’s a PDF under Files at the top of the project. Have fun!
If you have the code then send me on this address email “mf93@live.it” please!!
The code is here: https://raw.github.com/jedgarpark/Make_PIR_Sensor/master/MAKE_PIR_Sensor.pde
where is the code. Plz HURRY
For Real
i tried downloading the sketch and its no where to be found…anyone know. this is probably something simple, right? yea whatever….
The code is here: https://raw.github.com/jedgarpark/Make_PIR_Sensor/master/MAKE_PIR_Sensor.pde
Brandon, sorry for the huge delay, I didn’t see your comment until now. You can change the delay time upon startup to be longer if you need. Try adding a new line as the first one in the void setup that reads: delay(5000);
That’ll give you five seconds before it begins.
I noticed when I took the code from the PDF, the formatting was off when it is copy/pasted into Arduino editor. Best to download the PDE which is on the right side of the page above.
Hi! Nice project! wanna try it too.. but the thing is, I don’t know where to download the code.. I can’t find it….. :(
The code is here: https://raw.github.com/jedgarpark/Make_PIR_Sensor/master/MAKE_PIR_Sensor.pde
“Were Is The Code I Can’t Find It”?
Sorry about that, we’re looking into what happened. It seems when the new formatting was introduced the code was no longer included.
Hi, nice project, im looking to do an attack sensor so its very similar to this, my components are fairly simialar, just wanted to know will they work if swtiched with the ones in the project youve used, im using a vibrations motor as the output, and a sharp PIR sensor for the input, any help or advice will be great and really appreciated.
Hello, please send me the program?
e-mail: robert-1406@hotmail.com
The Sketch seems to have been removed from the page. Does anyone know where? I even did a search for “pdf” in the source code of this page without a result (sorry Goli Mohammadi).
The code is here: https://raw.github.com/jedgarpark/Make_PIR_Sensor/master/MAKE_PIR_Sensor.pde
Is there code for this yet?
The code is here: https://raw.github.com/jedgarpark/Make_PIR_Sensor/master/MAKE_PIR_Sensor.pde
I found the code here: http://make-documents.s3.amazonaws.com/fv1fYSLfy6QRgANM.pdf
Hello, send me the code? Please.
elany7@gmail.com
cant download this pir sensor sketch, whats the deal? someone let me know just how much of an idiot iam?
Sorry for the delay in fixing the post. Here is the code, I’ll see about having it properly added to the project next.
// Uses a PIR sensor to detect movement, buzzes a buzzer
// more info here: http://blog.makezine.com/projects/pir-sensor-arduino-alarm/
// email me, John Park, at jp@jpixl.net
// based upon:
// PIR sensor tester by Limor Fried of Adafruit
// tone code by michael@thegrebs.com
int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
int pinSpeaker = 10; //Set up a speaker on a PWM pin (digital 9, 10, or 11)
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
pinMode(pinSpeaker, OUTPUT);
Serial.begin(9600);
}
void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
playTone(300, 160);
delay(150);
if (pirState == LOW) {
// we have just turned on
Serial.println(“Motion detected!”);
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
playTone(0, 0);
delay(300);
if (pirState == HIGH){
// we have just turned of
Serial.println(“Motion ended!”);
// We only want to print on the output change, not state
pirState = LOW;
}
}
}
// duration in mSecs, frequency in hertz
void playTone(long duration, int freq) {
duration *= 1000;
int period = (1.0 / freq) * 1000000;
long elapsed_time = 0;
while (elapsed_time < duration) {
digitalWrite(pinSpeaker,HIGH);
delayMicroseconds(period / 2);
digitalWrite(pinSpeaker, LOW);
delayMicroseconds(period / 2);
elapsed_time += (period);
}
}
Would it be possible to just run this off a battery?
Yes, you could run this off of batteries. I’ve done so and it works fine. I usually use 4 AA NiMH batteries.
can you give me pir for 8051 controller
Thanks this is simple and neat. My nine year old son wanted to “invent” a device that scared off the birds under our deck so they didn’t make nests. So we used these plans. Going to try an add a camera to snap pics of it scaring off birds. Though knowing these birds they’ll just make a nest on top of it.
Excellent, did you and your son build the Duck Alarm?
Hi, I seem to have trouble running the code it says “Cannot find anything named LOW” I have copied the code over, any idea what might be wrong?
Scrap that, I worked out whats wrong. Essentially I am an idiot, I had opened the code up in Processing and not Arduino. Can someone tell me how to add a Camera to take photos to this please?
One straightforward way would be to use a camera that has an input for a remote switch, and have the Arduino close that for you with a transistor or relay. I made my own release switch: http://blog.makezine.com/2010/11/10/john-edgar-park-has-a-trigger-mouth/ using a 2.5mm phone earbud, you’d trigger it with the Arduino instead of the arcade button.
Great project!
I was wondering if anyone could help me tweak the arduino sketch?
What code could I insert to make it so that there is a 3 second delay between the PIR receiving a signal and the outputs?
There are other ways to make a delay, but the block of code using the Timer library allows for other actions to take place by using pulses to define your time-domain. If you use a Delay function that locks up the MCU until the delay is completed. You can find details at: http://playground.arduino.cc/Code/Timer
Hey, is there a way to attach a servo instead? And what changes should be made to the code for that?
what code if i use pir and keypad,
keypad for on/of that sensor
My LED on pin 13 wont turn on, the PIR works fine, the only difference is I’m using a Duemilanove, any ideas.
This was a fun build to learn a little about the motion sensor. However, it is just not loud enough to keep the dogs from getting up on the table. :-(
What I need is a simple circuit to boost the output signal to drive one of the Radio Shack sirens (9-12 volt). Or a modification that turns the output into a simple switch to turn on a separately powered 9 volt circuit connected to the siren.
I have tried a couple of ideas from Hack a Week and Instructables but no success yet. How about a little help?
It may not Compile, the only error is you may have to retype the this character (“motion detected”) and (“motion ended”). It has to do with the way these character shows up on the internet. Thanks I’m going to try it now.
Do you have the Electrical Schematic for this configuration?
GOOD DAY SIR i use RE200B pir sensor and the buzzer and the led is blingking and the buzzer is continuesly sounds up ….. is there a problem if i dont use the kind of pir that you use sir > ? help me please ..
are RE200B AND YOUR PIR SENSOR THE SAME ?
Sir I want Source code in ASM Language will you please help me.
Hi..do you have block diagram for this project?
Hi nice post!
I’m looking for a PIR sensor that its delay time is less than 5 seconds.
Do you know one that can answer my needs?
Thanks
Ben
hie nice project… i need arduino software… pls give me dat site
i juz got :)
Great tutoriol….!!!!!!
I have search the web for asolution to switch with a pir my bedledlight on and off. And this great.
Can you please tell me how i can change the buzzer code in to a ction to open the mosfet…
Or a signal where the powerr on is for x seconds,please..
Or can i set the mosfet to pin 13?
sorry..how if i want when the PIR sensor detect the motion,then it will send the message via old cellphone to another cellphone to tell that the motion is detected..
How can you change the duration of the buzzer?
Pingback: Idéias para automação residencial com Arduino | Fazedores
Hi, I’m writing a blog post about cool Arduino based projects and your’s is going to be there. Do you allow me to use one or two of your pictures in the post? I’m linking the references to the project back to this page.
Thanks in advance!
Manoel Lemos
Please some one make my day….
My Pir A is working only Pir B not.
Where do i go wrong…
[code]// Twee pirren onder het bed…
// Pir A en Pir B
//Pir B werkt niet…
int ledPin = 12; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int inputPinB = 3; // PIRB
int pirState = LOW; // we start, assuming no motion detected
int pirStateB = LOW; // PIR B
int val = 1; // variable for reading the pin status
int valB = 1; // PIR B
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
pinMode(inputPinB, INPUT); // PIr B
Serial.begin(9600);
}
//////////////// PIR A
void loop(){
val = digitalRead(inputPin); // read input value
if (val == LOW) { // Zorgt dat hij de goed "richting"op gaat High is de pir anders om
digitalWrite(ledPin, HIGH); // turn LED ON
delay(100); // uitlezen van ?
////////////////
if (pirState == HIGH) { //
Serial.println("Motion detected!"); //
pirState = LOW;
delay(100); // weet niet maar zal iets met uitlezen zijn.
///////////////////////////
}
} else { digitalWrite(ledPin, LOW); //
if (pirState == LOW){ // we have just turned of
Serial.println("Motion ended!"); //
pirState = HIGH;
delay(10000); // Tijd lamp aan is
}
}
}
/////////////////////
//}
////////////////PIR B
void loopB(){
valB = digitalRead(inputPinB); // read input value
if (valB == LOW) { // Zorgt dat hij de goed "richting"op gaat High is de pir anders om
digitalWrite(ledPin, HIGH); // turn LED ON
delay(100); // uitlezen van ?
////////////////
if (pirStateB == HIGH) { //
Serial.println("Motion detected!"); //
pirStateB = LOW;
delay(100); // weet niet maar zal iets met uitlezen zijn.
///////////////////////////
}
} else { digitalWrite(ledPin, LOW); //
if (pirStateB == LOW){ // we have just turned of
Serial.println("Motion ended!"); //
pirStateB = HIGH;
delay(10000); // Tijd lamp aan is
}
}
}
[/code]
So please…
Whe you have time…
Pingback: Ideias para automação residencial com Arduino | iMasters
Pingback: Arduino UNO - Stair Lighting Project - How To | Axelology
Pingback: Note to Self: Hooking Up an Arduino Uno to WiFi So It Can Text Me | timshaya
How do I reduce the length of time it buzzes?
reduce time delay after it triggers the buzzer
Pingback: PIR Sensor | Interactive Costumes
Hi, I am using a different sensor, which has 3 wires (Red,white, Black). Red is Marked as +ve and and black is marked as “AL”. Kindly let me know which OUT wire and negetive wire..
Out is probably white , as red and black is mostly used for plus and minus voltage input..
You can also make the motion sensor wireless by following our guide here:
http://www.mysensors.org/build/motion
Cheers
Henrik
Cool! I used this code to make an alarm for my sneaky 3-yo who started getting up in the middle of the night (very stealthy). I tested it last night and sure thing it worked great! I’ll include some pics.
Hello,
Is it possible to trigger the PIR only if a person is standing for more than 10 Secs, this is to avoid triggering for passersby. If so kindly share how this can be achieved.
Thanks
Sri
I’m not an expert on this but you should look into “retriggering” and “non-retriggering” mode. I think using your PIR-sensor in “retriggering” mode (with the jumper on the back set to H) is the way to go. Then you can probably monitor the time the sensor is on an in software and set you threshold there. I.e when the sensor triggers, wait 10 seconds before doing anything.
I found this instructable that explains this in more detail.
http://www.instructables.com/id/PIR-Motion-Sensor-Tutorial/step5/Retriggering/
when it receives a signal, add a delay for 10 seconds then if there’s still a signal set off the alarm.
Pic2
Pic 2 (of insides)
Is it working 100%because I have the same PIR sensor and buzzer that u got , like in my PIR sensor there is not written which pin is of GND, VCC and Vout
plz helpme bcoz my circuit is constantly ring alarm.
Hi, can I use one of the components like the one in this page:
http://uk.rs-online.com/web/p/ir-receivers/0577897/
to build this circuit. It is just that I dont know the difference between IR receivers and PIR.
thanks
ali.
The difference is PIR sensor Senses Infrared Light, IR reciever looks for Infrared pulsed signals, such as TV B GONE OR TV REMOTES I do believe
almost, pir senses body-emitted infra red or (rarely) heat but ir reciever takes any ambient light (not only signals)
Very nice project. In a few minutes I was able to test a PIR sensor I received today.
Hi guys, my alarm rings constantly as soon as I upload the sketch. Any thoughts on what the issue could be?
maybe a short circuit, or wrong polarity
Hey Stephen what happened , Is ur circuit working? now? I mean do you still have a problem of constantly buzzing of the buzzer??
where is PIR sensor in proteus?
what is the range of this PIR sensor?
Up to 20 feet(6 meters)
thanx Pradeep