// Define the pins for the ultrasonic sensor const int pinTrig = 26; const int pinEcho = 27; void setup() { // Start serial communication Serial.begin(9600); // Configure the pins for the ultrasonic sensor pinMode(pinTrig, OUTPUT); pinMode(pinEcho, INPUT); } void loop() { // Send a short pulse to the TRIG pin digitalWrite(pinTrig, LOW); delayMicroseconds(2); digitalWrite(pinTrig, HIGH); delayMicroseconds(10); digitalWrite(pinTrig, LOW); // Read the response time from the ECHO pin long duration = pulseIn(pinEcho, HIGH); // Calculate the distance in centimeters int distance_cm = duration * 0.034 / 2; // Print the distance on the serial port Serial.print("Distance: "); Serial.print(distance_cm); Serial.println(" cm"); // Wait for a brief period of time before the next reading delay(1000); }