bruno_opaiva
Published © GPL3+

Car Parking Simulator

A simulation of a real life car parking using Arduino, Ultrasonic sensors, LCD Display and RGB LEDs.

IntermediateFull instructions provided688
Car Parking Simulator

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
USB-A to B Cable
USB-A to B Cable
Cable to send the sketch to Arduino
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
Common cathode used here
×2
Resistor 221 ohm
Resistor 221 ohm
Resistor for LED
×4
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
Simulation of the parking spot
×2
I2C 16x2 Arduino LCD Display Module
DFRobot I2C 16x2 Arduino LCD Display Module
It will show the images if is free or occupied.
×1
Solderless Breadboard Full Size
Solderless Breadboard Full Size
Breadboard to fit the LEDs and sensors
×1
Jumper wires (generic)
Jumper wires (generic)
Jumper for connections of the LEDs and sensors
×20
Male/Female Jumper Wires
Male/Female Jumper Wires
Connections of the display
×4

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematics

Schematics of the project, made using Tinkercad

Code

Code

C/C++
Code of the project, made using Arduino IDE
#include <Ultrasonic.h> //Library for the ultrasonic sensor
#include<LiquidCrystal_I2C.h> //Library for the display
#include<Wire.h>
LiquidCrystal_I2C lcd (0x27, 16, 2); //Creates an object lcd
Ultrasonic ultrasonic1 (13, 12); //Creates an object ultrasonic1
Ultrasonic ultrasonic2 (11, 10); //Creates an object ultrasonic1
int ledOccupied1 = 9; //LED to indicate if the spot is occupied
int ledFree1 = 8; //LED to indicate if the spot is free
int ledOccupied2 = 7; //LED to indicate if the spot is occupied
int ledFree2 = 6; //LED to indicate if the spot is free
int val1; //val1 as a value variable for ultrasonic sensor
int val2; //val1 as a value variable for ultrasonic sensor
byte SpaceA[] = //Custom character to indicate a free spot
{
  0b11111,
  0b10001,
  0b10011,
  0b10111,
  0b11111,
  0b10011,
  0b10011,
  0b10011
};
byte SpaceB[] = //Custom character to indicate a free spot
{
  0b11111,
  0b10001,
  0b11001,
  0b11101,
  0b11111,
  0b11001,
  0b11001,
  0b11001
};
byte SpaceC[] = //Custom character to indicate a free spot
{
  0b10011,
  0b10011,
  0b10011,
  0b10011,
  0b10000,
  0b10000,
  0b10000,
  0b11111
};
byte SpaceD[] = //Custom character to indicate a free spot
{
  0b11001,
  0b11001,
  0b11001,
  0b11001,
  0b00001,
  0b00001,
  0b00001,
  0b11111
};
byte NoSpaceA[] = //Custom character to indicate a occupied spot
{
  0b11111,
  0b10000,
  0b10000,
  0b11000,
  0b11100,
  0b11110,
  0b10111,
  0b10011
};
byte NoSpaceB[] = //Custom character to indicate a occupied spot
{
  0b11111,
  0b00001,
  0b00001,
  0b00011,
  0b00111,
  0b01111,
  0b11101,
  0b11001
};
byte NoSpaceC[] = { //Custom character to indicate a occupied spot
  0b10011,
  0b10111,
  0b11110,
  0b11100,
  0b11000,
  0b10000,
  0b10000,
  0b11111
};
byte NoSpaceD[] = { //Custom character to indicate a occupied spot
  0b11001,
  0b11101,
  0b01111,
  0b00111,
  0b00011,
  0b00001,
  0b00001,
  0b11111
};
void setup() {
  lcd.init(); //Starts the display
  lcd.backlight(); //Turns on the display backlight
  //Create the custom characters
  lcd.createChar(1, SpaceA);
  lcd.createChar(2, SpaceB);
  lcd.createChar(3, SpaceC);
  lcd.createChar(4, SpaceD);
  lcd.createChar(5, NoSpaceA);
  lcd.createChar(6, NoSpaceB);
  lcd.createChar(7, NoSpaceC);
  lcd.createChar(8, NoSpaceD);
  //Define all LEDs as Output
  pinMode(ledOccupied1, OUTPUT);
  pinMode(ledFree1, OUTPUT);
  pinMode(ledOccupied2, OUTPUT);
  pinMode(ledFree2, OUTPUT);
}

void loop() {
  //Value variables will store all informations from the sensors
  val1 = ultrasonic1.Ranging(CM);
  val2 = ultrasonic2.Ranging(CM);
  //If the first spot is occupied
  if ((val1 < 10) && (val2 > 10)) {
    digitalWrite(ledOccupied1, HIGH);
    digitalWrite(ledFree1, LOW);
    digitalWrite(ledOccupied2, LOW);
    digitalWrite(ledFree2, HIGH);
    lcd.clear();
    lcd.write(5);
    lcd.setCursor(1, 0);
    lcd.write(6);
    lcd.setCursor(0, 1);
    lcd.write(7);
    lcd.setCursor(1, 1);
    lcd.write(8);
    lcd.setCursor(7, 0);
    lcd.write(1);
    lcd.setCursor(8, 0);
    lcd.write(2);
    lcd.setCursor(7, 1);
    lcd.write(3);
    lcd.setCursor(8, 1);
    lcd.write(4);
    delay(500);
  }
  //If the second spot is occupied
  else if ((val1 > 10) && (val2 < 10)) {
    digitalWrite(ledOccupied1, LOW);
    digitalWrite(ledFree1, HIGH);
    digitalWrite(ledOccupied2, HIGH);
    digitalWrite(ledFree2, LOW);
    lcd.clear();
    lcd.write(1);
    lcd.setCursor(1, 0);
    lcd.write(2);
    lcd.setCursor(0, 1);
    lcd.write(3);
    lcd.setCursor(1, 1);
    lcd.write(4);
    lcd.setCursor(7, 0);
    lcd.write(5);
    lcd.setCursor(8, 0);
    lcd.write(6);
    lcd.setCursor(7, 1);
    lcd.write(7);
    lcd.setCursor(8, 1);
    lcd.write(8);
    delay(500);
  }
  //If the first and second spots are free
  else if ((val1 > 10) && (val2 > 10)) {
    digitalWrite(ledOccupied1, LOW);
    digitalWrite(ledFree1, HIGH);
    digitalWrite(ledOccupied2, LOW);
    digitalWrite(ledFree2, HIGH);
    lcd.clear();
    lcd.write(1);
    lcd.setCursor(1, 0);
    lcd.write(2);
    lcd.setCursor(0, 1);
    lcd.write(3);
    lcd.setCursor(1, 1);
    lcd.write(4);
    lcd.setCursor(7, 0);
    lcd.write(1);
    lcd.setCursor(8, 0);
    lcd.write(2);
    lcd.setCursor(7, 1);
    lcd.write(3);
    lcd.setCursor(8, 1);
    lcd.write(4);
    delay(500);
  }
  //If the first and second spots are occupied
  else if ((val1 < 10) && (val2 < 10)) {
    digitalWrite(ledOccupied1, HIGH);
    digitalWrite(ledFree1, LOW);
    digitalWrite(ledOccupied2, HIGH);
    digitalWrite(ledFree2, LOW);
    lcd.clear();
    lcd.write(5);
    lcd.setCursor(1, 0);
    lcd.write(6);
    lcd.setCursor(0, 1);
    lcd.write(7);
    lcd.setCursor(1, 1);
    lcd.write(8);
    lcd.setCursor(7, 0);
    lcd.write(5);
    lcd.setCursor(8, 0);
    lcd.write(6);
    lcd.setCursor(7, 1);
    lcd.write(7);
    lcd.setCursor(8, 1);
    lcd.write(8);
    delay(500);
  }
  else {
    lcd.clear();
    digitalWrite(ledOccupied1, LOW);
    digitalWrite(ledFree1, LOW);
    digitalWrite(ledOccupied2, LOW);
    digitalWrite(ledFree2, LOW);
  }
}

Credits

bruno_opaiva

bruno_opaiva

6 projects • 4 followers

Comments