Hi guys. I am currently trying to write a code for a project that improves the accuracy of the six feet dist. rule. I am using a piezoelectric buzzer, PIR sensor, and ultrasonic dist. sensor. I am trying to combine a PIR sensor and an ultrasonic dist sensor. I am trying to set two check points before the piezoelectric buzzer buzzes. I am definitely going to have some errors. As from the fact that I am a newbie, please explain it a little simpler. Thank you.
int buzzer = 13; // LED
int pirPin = 3; // PIR Out pin
int pirStat = 0; // PIR status
int distsens = 12;
int limit = 6;
int total_range = 6;
void setup() {
pinMode(buzzer, OUTPUT);
pinMode(pirPin, INPUT);
pinMode(distsens, INPUT);
}
void loop(){
pirStat = digitalRead(pirPin);
if (pirStat == HIGH) &&
(distsens <= limit && distance >= total_range){ // if motion detected
digitalWrite(buzzer, HIGH);
tone(beeper, 5000, 700);
delay(1000);
noTone(buzzer);
delay(1000);
}
else {
digitalWrite(buzzer, LOW); // turn LED OFF if we have no motion
delay(1000);
}
}
Thanks