Anti theft motion detection using hc-sr501





MATREIALS REQUIRED
1.Arduino uno
2.Mini breadboard
3.Active buzzer
4.HC-SR501 PIR sensor

CIRCUIT








 Buzzer+ terminal-Arduino pin 7
 Buzzer- terminal-Arduino gnd
HC-SR501 vcc-Arduino +5v
HC-SR501 out-Arduino pin 6
HC-SR501 GND- Arduino gnd

CODE
int pir = 6;//pin that the output of pir sensor is connected
int buzz=7;//the pin that the + terminal of the buzzer is conneted 
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(pir,INPUT);//defining pir sensor as input device
  pinMode(buzz,OUTPUT);//defining buzzer sensor as output device

}

void loop() {
  // put your main code here, to run repeatedly:
  int pirval = digitalRead(pir);//reading the value of pir sensor
  Serial.println(pirval);
   delay(1000);
  
  if(pirval == HIGH){
    digitalWrite(buzz,HIGH);
    delay(1000);
    digitalWrite(buzz,LOW);
  }

  

}

Comments