A simple code to measure the distance using an arduino and ultrasonic sensor.
- Arduino Uno R3
- Ultrasonic module HC-SR04
- Vcc - 5v
- Trig - Pin 13
- Echo - Pin 12
- Gnd - Gnd
- Upload the code to the Arduino.
- Open the Serial Monitor (ensure the baud rate is set to 9600).
- The serial monitor will print the distance of an object from the sensor in centimeters.