#include <HCSR04.h> // Ultrasonic sensor Library
UltraSonicDistanceSensor distanceSensor(13, 12); // Initialize the sensor using digital pins 13 (Trig) and 12(Echo).
void setup()
{
Serial.begin(9600); // Initialize the serial connection for debugging.
}
void loop()
{
int distance;
// Trigger the HC-SR04 to get a distance measurement
distance = distanceSensor.measureDistanceCm();
if(distance != -1)
{
// Display the distance on the LCD
Serial.print("Distance:"); // Clear the line
Serial.print(distance);
Serial.println("cm ");
}
else
{
// Display the distance on the LCD
Serial.println("Out of range.");
}
delay(500); // Adjust the delay to control how often the distance is updated
}