Instructables

PIR Alarm Arduino Motion Sensor (with Encasing)

Picture of PIR Alarm Arduino Motion Sensor (with Encasing)
This is a guide on how to make a motion detector with an arduino! Enjoy!
 
Remove these adsRemove these ads by Signing Up

Step 2: Wire the Arduino to the breadboard

Picture of Wire the Arduino to the breadboard
Connect Digital 2 (on the Arduino), 5V, and GND, each, to a different row on the breadboard.

Step 3: Plugging in PIR sensor

Picture of Plugging in PIR sensor
Plug the PIR sensor into the board so that -,+, and Out connect to GND, 5V, and Digital 2. Make sure to place a 10K pullup resistor between the signal (Out) and 5V (+).

Step 4: Plug in the LED

Picture of Plug in the LED
Connect the anode (the longer leg) into digital pin 13 on the Arduino Uno. Plug the cathode (the shorter leg) into GND. WARNING: Be sure to place a resistor (150-170 Ohm) between the LED and GND.

Step 5: Connect the Piezo Buzzer to the Arduino

Picture of Connect the Piezo Buzzer to the Arduino
Connect the Piezo buzzer to digital pin 10 and GND. The way in which the piezo buzzer does not matter since the polarity of the buzzer does not matter.

Step 6: Launch Arduino Software

int pirPin = 2;
int pinSpeaker= 10;
int ledPin = 13;
void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(pinSpeaker, OUTPUT);
}
void loop(){
  int pirVal = digitalRead(pirPin);
  Serial.println("starting to read PIR");
  analogWrite(ledPin, 0);
  delay(2000);
  if(pirVal == LOW) {
    analogWrite(ledPin, 255);
    Serial.println("Motion Detected");
    tone(10, 700, 100);
    delay(2000);
  }
}
void tone(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);
}
  }
ConductorX7 months ago

I am not clear on the pull up 10K resistor. Can you provide a circuit sketch? The photo is not clear.

ITMuncie1 year ago
I keep getting an error on "Serial.begin(9600);" "serial was not declared in this scope".

Any idea what I need to change?
EET19822 years ago
Very cool! I just received my Adruino Uno in the mail and this is one of the projects that is helping me learn more about it. :) Thanks alot for the Instructable!