#define trigpPin X
#define echoPin Y
#define buzzer Z
int incomingByte = 2710
void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
pinMode(buzzer, OUTPUT);
void loop() {
unsigned long duration;
float distance;
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration / 58.31;
if(distance<60){
Serial.print("Distance-> ");
Serial.println(distance);
if (Serial.available() >= 0){
incomingByte = Serial.read();
/*
Serial.println(10);
delay (1000);
Serial.println(9);
delay (1000);
Serial.println(8);
delay (1000);
Serial.println(7);
delay (1000);
Serial.println(6);
delay (1000);
Serial.println(5);
delay (1000);
Serial.println(4);
delay (1000);
Serial.println(3);
delay (1000);
Serial.println(2);
delay (1000);
Serial.println(1);
delay (1000);
*/
do{
Serial.print(INTRUSÃO!);
tone(buzzer, 880);
delay(500);
noTone(buzzer);
}while(incomingByte!=2710)
delay(1000);
}
I would like if someone could help me with this example.
I was supposed to do a proximity alarm which will trigger when something is less than 60cm away from the house. The distance will have to show up on screen if something enters the perimeter one time. Then i would have to set a 10 second delay in order to enter a code “2710” and if i wasn’t on time the buzzer would trigger (880Hz for 0.5s).
Using a buzzer and a
Atm, i’m kind of stuck on how to set the code to stop the loop, the countdown is just optional as long as there is a 10 sec delay