const int trigPin = 9; const int echoPin = 10; long duration; int distance; void setup() { pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); Serial.begin(9600); } void loop() { // Send a 10-microsecond pulse to trigger the ultrasonic sensor digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Read the echo pin and calculate the distance duration = pulseIn(echoPin, HIGH); distance = duration * 0.034 / 2; // Print the distance value on Serial Monitor Serial.print("Distance: "); Serial.print(distance); Serial.println(" cm"); // delay(500); }