Arduino with PIR motion Sensor, LED and buzzer (Code)

Arduino with PIR motion Sensor, LED and buzzer

Today we shall learn to use a PIR motion sensor with arduino. The required kits are :

  1. An arduino and its adapter
  2. Few jumper Wires
  3. PIR motion sensor
  4. A LED with 220 OHM resistor
  5. A breadboard
  6. A buzzer
There are 3 pins on the PIR sensor. They are :
  1. Output-motion input pin
  2. GND-Ground pin
  3. VCC-positive power pin
There are two legs on a LED. The longer leg is positive and the shorter leg is negative. A buzzer has similar legs. The steps to setup hardware are listed below:
  • Connect 5V pin on the arduino to +VE on the breadboard .
  • Connect GND pin on the arduino to -VE on the breadboard .
  • Connect "VCC" pin of the sensor to +ve on the breadboard.
  • Connect Output pin to any analog or digital pins on the arduino.In this tutorial I connected it with A0
  • Connect "GND" ground pin on the sensor to -VE on the breadboard.
  • Fix the LED on the breadboard.
  • Connect longer LED leg to pin 13 on the arduino .
  • Connect shorter LED leg to GND pin on the breadboard through a 220 ohm resistor.
  • Fix buzzer on the breadboard.
  • Connect longer buzzer leg to pin 12(or any other pin) on the arduino.
  • Connect shorter buzzer leg to GND pin on the arduino.
The setup is complete. Now, upload the code and enjoy.

Check out the tutorial

(Code)

const int motionpin=A0;
const int ledpin=13;
const int buzzpin=12; // ledpin,motionpin and buzpin are not changed throughout the process
int motionsensvalue=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(ledpin, OUTPUT);
pinMode(motionpin,INPUT);
pinMode(buzzpin,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
motionsensvalue=analogRead(motionpin); // reads analog data from motion sensor
if (motionsensvalue>=200){
digitalWrite(ledpin,HIGH);
tone(buzzpin,100); //turns on led and buzzer
}
else {
digitalWrite(ledpin,LOW); //turns led off led and buzzer
noTone(buzzpin);
}
}

Comments

  1. Would you please tell me how I can control the alarm with a keypad and password?

    ReplyDelete
  2. the buzzer starting to make noise without the detection of the sensor

    ReplyDelete
  3. Hey Nice Blog!!! Thank you for sharing information. Wonderful blog & good post.Its really helpful for me, waiting for a more new post. Keep Blogging! Solar Power Lights

    ReplyDelete
  4. nice project doing the same PIR project but just not with arduino but ATmega32 MCU(PIR Sensor with AVR)

    ReplyDelete
  5. Works great, thanks! There is no purpose for the power to the + column at the end though. You have each component connected directly to the arduino, and no components going from the + column to any row, so there is no purpose. You can take that last cable out and it doesn't change anything.

    ReplyDelete

Post a Comment

If you have any problems, please do notify me.