Project Title: Arduino Distance  Measurement Device



Abstract:

The Arduino Distance Measurement Device is designed to accurately measure distances using ultrasonic sensors and display the results on an LCD screen. This project utilizes the Arduino platform and ultrasonic sensor technology to provide a cost-effective and reliable solution for distance measurement applications.

Objective:

The primary objective of this project is to create a distance measurement device that is easy to use, accurate, and versatile. The device will be capable of measuring distances within a specified range and displaying the results on a user-friendly interface.

Components Used:

  1. Arduino Uno
  2. Ultrasonic Sensor (HC-SR04)
  3. LCD Display (16x2) With I2C Module
  4. Breadboard and jumper wires
  5. Power supply (9V)

Circuit Diagram:


Code:

#include <LiquidCrystal_I2C.h>
#include <Wire.h>

const int trigPin = 9;   // Trig pin of the ultrasonic sensor
const int echoPin = 10;  // Echo pin of the ultrasonic sensor
LiquidCrystal_I2C lcd(0x27,16,2);

void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  lcd.begin();
}

void loop() {
  long duration, distance;
  
  // Send ultrasonic pulse
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // Measure the echo time
  duration = pulseIn(echoPin, HIGH);

  // Calculate the distance
  distance = (duration * 0.0343) / 2;

  // Display the distance on the LCD
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Distance: ");
  lcd.print(distance);
  lcd.print(" cm");

  delay(500);  // Delay for readability
}