/*
PIR Sensor Test
Wiring :
Arduino 8 -> PIR D
Arduino 5V -> PIR +
Arduino GND -> PIR -
Arduino 3 -> LED +
Arduino GND -> Resistor -> LED -
Arduino 2 -> Buzzer +
Arduino GND -> Buzzer -
*** O-Tech ***
A Place You Can Trust
https://wa.me/201207738604
https://www.facebook.com/profile.php?id=61555112881938
https://www.youtube.com/@OTECHegypt
*/
#define pirPin 2
#define ledPin 3
#define buzzer 4
bool motionDetected = false;
void setup() {
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
Serial.println("PIR Motion Sensor Test by O-Tech");
}
void loop() {
int motion = digitalRead(pirPin);
if (motion == HIGH && !motionDetected) {
motionDetected = true;
digitalWrite(ledPin, HIGH);
Serial.println("Motion Detected");
int i;
while(digitalRead(pirPin)){
for(i=700;i<800;i+=2){
tone(buzzer,i);
delay(1);
}
for(i=800;i>700;i--){
tone(buzzer,i);
delay(1);
}
}
}
if (motion == LOW && motionDetected) {
if (digitalRead(pirPin) == LOW) {
motionDetected = false;
digitalWrite(ledPin, LOW);
noTone(buzzer);
}
}
}