#include <Arduino.h>
#include <Ultrasonic.h>
const int TRIGGER_PIN = 5; // GPIO pin connected to the trigger pin of HC-SR04
const int ECHO_PIN = 18; // GPIO pin connected to the echo pin of HC-SR04
const unsigned long MEASURE_INTERVAL = 100; // Measurement interval in milliseconds
Ultrasonic ultrasonic(TRIGGER_PIN, ECHO_PIN);
void setup() {
Serial.begin(115200);
}
void loop() {
// Measure distance
float distance = ultrasonic.read();
// Check if the distance is within the specified range (0 to 10cm)
if (distance >= 0 && distance <= 10) {
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
}
// Delay before next measurement
delay(MEASURE_INTERVAL);
}