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

Arduino UNO-Based Ultrasonic Distance Meter with LCD Display and Laser Emitter

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Ultrasonic Distance Meter with LCD Display and Laser Emitter

Circuit Documentation

Summary

This circuit is designed to measure distance using an HC-SR04 Ultrasonic Sensor and display the measured distance on a 16x2 I2C LCD. Additionally, a KY-008 Laser Emitter is used for visual indication. The entire system is powered by a 9V battery connected through a power jack and controlled by an Arduino UNO. A rocker switch is used to turn the circuit on and off.

Component List

  1. 9V Battery

    • Description: Provides power to the circuit.
    • Pins: -, +
  2. Arduino UNO

    • Description: Microcontroller used to control the circuit.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  3. HC-SR04 Ultrasonic Sensor

    • Description: Measures distance by emitting ultrasonic waves and receiving the echo.
    • Pins: VCC, TRIG, ECHO, GND
  4. 16x2 I2C LCD

    • Description: Displays the measured distance.
    • Pins: GND, VCC, SDA, SCL
  5. Rocker Switch

    • Description: Turns the circuit on and off.
    • Pins: output, input
  6. KY-008 Laser Emitter

    • Description: Emits a laser beam for visual indication.
    • Pins: SIG, 5v, GND
  7. Power Jack

    • Description: Connects the 9V battery to the circuit.
    • Pins: POSITIF, NEGATIF

Wiring Details

9V Battery

Arduino UNO

HC-SR04 Ultrasonic Sensor

16x2 I2C LCD

Rocker Switch

KY-008 Laser Emitter

Power Jack

Code Documentation

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

// Pin definitions
#define TRIG_PIN 10
#define ECHO_PIN 9
#define LASER_PIN A0  // Laser module trigger pin connected to A0

// Create LCD object for I2C
LiquidCrystal_I2C lcd(0x27, 16, 2);  // Adjust address if needed

void setup() {
  // Initialize the LCD
  lcd.begin(16, 2);
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("FEET: ");

   // Set up ultrasonic sensor pins
    pinMode(TRIG_PIN, OUTPUT);
    pinMode(ECHO_PIN, INPUT);
    // Set up the laser module 
    
    // Start serial communication
    Serial.begin(9600);
}

void loop() {
    long duration;
    float distance_cm;
    float distance_ft;

    // Trigger the ultrasonic sensor
    digitalWrite(TRIG_PIN, LOW);
    delayMicroseconds(2);
    digitalWrite(TRIG_PIN, HIGH);
    delayMicroseconds(10);
    digitalWrite(TRIG_PIN, LOW);

    // Read the echo pin
    duration = pulseIn(ECHO_PIN, HIGH);

    // Calculate distance (in cm and feet)
    distance_cm = (duration * 0.0343) / 2;
    distance_ft = distance_cm * 0.0328084;

    // Output the distance to Serial Monitor
    Serial.print("DISTANCE: ");
    Serial.print(distance_ft, 2);
    Serial.print(" ft || ");
    Serial.print(distance_cm, 2);
    Serial.println(" cm");

  // Clear the display and update the distance readings
  lcd.clear();
  
  // Display the distance on the LCD
  lcd.setCursor(0, 0);
  lcd.print("FEET: ");
  lcd.print(distance_ft, 2); // Display feet with 2 decimal places
  lcd.print(" ft."); // Feet unit symbol
  
  lcd.setCursor(0, 1);
  lcd.print("CM: ");
  lcd.print(distance_cm, 2); // Display centimeters with 2 decimal places
  lcd.print(" cm."); // Centimeter unit symbol

  // Optional: Send data over Serial for Bluetooth or debugging
  Serial.print("DISTANCE: ");
  Serial.print(distance_ft, 2);
  Serial.print(" ft. || ");
  Serial.print(distance_cm, 2);
  Serial.println(" cm.");

  // Turn off the laser after measurement
  digitalWrite(LASER_PIN, LOW);

  // Add a small delay before repeating
  delay(2000);
}

This code initializes the LCD, sets up the pins for the ultrasonic sensor and laser module, and continuously measures the distance, displaying it on the LCD and sending it to the Serial Monitor. The laser is turned off after each measurement cycle.