#include <Ultrasonic.h>
const int triggerPin = 5; // Trigger pin connected to D5
const int echoPin = 18; // Echo pin connected to D18
Ultrasonic ultrasonic(triggerPin, echoPin);
void setup() {
Serial.begin(115200);
}
void loop() {
long distance = ultrasonic.read(); // Read the distance in centimeters
if (distance >= 0) {
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
} else {
Serial.println("Error reading distance.");
}
delay(1000); // Delay 1 second before taking another reading
}