#define SPEAKER_PIN 8
#define DISTANCE_THRESHOLD 20
#define TRIG_PIN 9
#define ECHO_PIN 10
void setup() {
pinMode(SPEAKER_PIN, OUTPUT);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
Serial.begin(9600);
}
void loop() {
int distance = 20; // Set the distance to 20 directly
Serial.print("Distance: ");
Serial.println(distance);
if (distance == DISTANCE_THRESHOLD) {
// Simple beep
tone(SPEAKER_PIN, 1000); // Adjust the frequency (Hz) as needed
delay(100); // Adjust the duration of the beep
noTone(SPEAKER_PIN);
}
delay(500); // Adjust the delay between distance measurements
}