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

Arduino UNO-Based Ultrasonic Parking Sensor with LCD Display and LED Indicators

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Ultrasonic Parking Sensor with LCD Display and LED Indicators

Circuit Documentation

Summary

This circuit is a parking sensor system that uses an Arduino UNO microcontroller to measure the distance of an object using an HC-SR04 ultrasonic sensor. The distance is displayed on an LCD display, and LEDs and a piezo buzzer provide visual and auditory warnings based on the measured distance. A potentiometer is used to adjust the contrast of the LCD display.

Component List

  1. Arduino UNO

    • Description: Microcontroller board based on the ATmega328P.
    • 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
  2. Resistor

    • Description: 220 Ohms resistor.
    • Pins: pin1, pin2
    • Properties: Resistance: 220 Ohms
  3. LCD Display (16 pin)

    • Description: 16x2 character LCD display.
    • Pins: VSS, VDD, VO, RS, R_W, E, DB0, DB1, DB2, DB3, DB4, DB5, DB6, DB7, A, K
  4. Potentiometer

    • Description: Variable resistor used to adjust LCD contrast.
    • Pins: GND, Output, VCC
  5. LED: Two Pin (red)

    • Description: Red LED.
    • Pins: cathode, anode
  6. LED: Two Pin (green)

    • Description: Green LED.
    • Pins: cathode, anode
  7. LED: Two Pin (yellow)

    • Description: Yellow LED.
    • Pins: cathode, anode
  8. HC-SR04 Ultrasonic Sensor

    • Description: Ultrasonic distance sensor.
    • Pins: VCC, TRIG, ECHO, GND
  9. Piezo Buzzer

    • Description: Buzzer for auditory warnings.
    • Pins: pin 1, pin 2

Wiring Details

Arduino UNO

Potentiometer

LCD Display (16 pin)

HC-SR04 Ultrasonic Sensor

Piezo Buzzer

LED: Two Pin (red)

LED: Two Pin (green)

LED: Two Pin (yellow)

Resistor

Code Documentation

#include <LiquidCrystal.h>

// Initialize LCD pins (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Pin definitions
const int trigPin = 9;    // Ultrasonic sensor trigger
const int echoPin = 10;   // Ultrasonic sensor echo
const int buzzerPin = 8;  // Buzzer
const int greenLed = 7;   // Safe distance
const int yellowLed = 6;  // Warning distance
const int redLed = 13;    // Danger distance

// Distance thresholds (in cm)
const int SAFE_DISTANCE = 100;
const int WARNING_DISTANCE = 50;
const int DANGER_DISTANCE = 20;

void setup() {
  // Initialize LCD
  lcd.begin(16, 2);  // 16 columns, 2 rows
  
  // Initialize pins
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(buzzerPin, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(yellowLed, OUTPUT);
  pinMode(redLed, OUTPUT);
  
  // Display startup message
  lcd.print("Parking Sensor");
  lcd.setCursor(0,1);
  lcd.print("Starting...");
  delay(2000);
}

void loop() {
  // Get distance measurement
  long duration, distance;
  
  // Clear trigger pin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  
  // Send ultrasonic pulse
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  
  // Read echo
  duration = pulseIn(echoPin, HIGH);
  
  // Calculate distance in cm
  distance = duration * 0.034 / 2;
  
  // Update display and warnings
  updateDisplay(distance);
  updateWarnings(distance);
  
  delay(100);
}

void updateDisplay(long distance) {
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Dist:");
  lcd.print(distance);
  lcd.print("cm");
  
  lcd.setCursor(0,1);
  if (distance > SAFE_DISTANCE) {
    lcd.print("Safe to Park");
  } else if (distance > WARNING_DISTANCE) {
    lcd.print("Getting Close!");
  } else if (distance > DANGER_DISTANCE) {
    lcd.print("Warning!");
  } else {
    lcd.print("STOP!");
  }
}

void updateWarnings(long distance) {
  // Update LEDs
  digitalWrite(greenLed, distance > SAFE_DISTANCE);
  digitalWrite(yellowLed, distance <= SAFE_DISTANCE && distance > DANGER_DISTANCE);
  digitalWrite(redLed, distance <= DANGER_DISTANCE);
  
  // Update buzzer
  if (distance <= DANGER_DISTANCE) {
    // Continuous tone
    tone(buzzerPin, 2000);
  } else if (distance <= WARNING_DISTANCE) {
    // Intermittent beeping
    tone(buzzerPin, 1500);
    delay(distance * 2);
    noTone(buzzerPin);
    delay(distance * 2);
  } else