Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Based Ultrasonic Distance Measurement System

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based Ultrasonic Distance Measurement System

Circuit Documentation

Summary of the Circuit

This circuit integrates an Arduino UNO microcontroller board with an HC-SR04 Ultrasonic Sensor to measure distance. The Arduino UNO is responsible for controlling the sensor, processing the distance measurements, and outputting the results to the Serial Monitor. The HC-SR04 Ultrasonic Sensor operates by emitting an ultrasonic pulse and then listening for its echo to determine the distance to an object.

Component List

Arduino UNO

HC-SR04 Ultrasonic Sensor

Wiring Details

Arduino UNO

HC-SR04 Ultrasonic Sensor

Documented Code

/*
 * This Arduino Sketch interfaces with an HC-SR04 Ultrasonic Sensor to measure
 * distance. The sensor's VCC and GND are connected to the Arduino's 5V and GND
 * pins, respectively. The TRIG pin is connected to D3, and the ECHO pin is
 * connected to D2. The measured distance is printed to the Serial Monitor.
 */

const int trigPin = 3; // TRIG pin connected to D3
const int echoPin = 2; // ECHO pin connected to D2

void setup() {
  Serial.begin(9600); // Initialize serial communication at 9600 baud
  pinMode(trigPin, OUTPUT); // Set TRIG pin as output
  pinMode(echoPin, INPUT);  // Set ECHO pin as input
}

void loop() {
  long duration, distance;
  digitalWrite(trigPin, LOW); // Ensure TRIG pin is low
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH); // Send a 10us high pulse to TRIG pin
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH); // Read the ECHO pin
  distance = duration * 0.034 / 2; // Calculate distance in cm
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");
  delay(1000); // Wait for 1 second before next measurement
}

This code is designed to be uploaded to the Arduino UNO microcontroller. It initializes the necessary pins for communication with the HC-SR04 Ultrasonic Sensor, sends trigger pulses, reads the echo signal, calculates the distance based on the time interval between sending and receiving the pulse, and outputs the distance measurement to the Serial Monitor.