int sensorPin = 13; // connect PIR sensor to digital pin 3
int ledPin = 9; // connect LED to digital pin 4
int buzzerPin = 5; // connect buzzer to digital pin 5
void setup() {
Serial.begin(9600);
pinMode(sensorPin, INPUT);
pinMode(ledPin, OUTPUT); // declare all pins as OUTPUT
pinMode(buzzerPin, OUTPUT);
}
void loop() {
if(digitalRead(sensorPin) == HIGH) // if the value of pulse from PIR sensor is HIGH then LED will glow and buzzer will ring
{
digitalWrite(ledPin, HIGH);
digitalWrite(buzzerPin, HIGH);
Serial.println("THERE IS SOME MOTION IN FRONT OF SENSOR");
}
else
{
digitalWrite(ledPin, LOW); // if the value of pulse from PIR sensor is LOW then LED will not glow and buzzer
digitalWrite(buzzerPin, LOW); // will not ring!
Serial.println("THERE IS NO MOTION IN FRONT OF SENSOR");
}
}