Car Parking Simulator
A simulation of a real life car parking using Arduino, Ultrasonic sensors, LCD Display and RGB LEDs.
Components and supplies
1
I2C 16x2 Arduino LCD Display Module
4
Resistor 221 ohm
1
Arduino UNO
20
Jumper wires (generic)
4
Male/Female Jumper Wires
1
Solderless Breadboard Full Size
1
USB-A to B Cable
2
Ultrasonic Sensor - HC-SR04 (Generic)
2
RGB Diffused Common Cathode
Apps and platforms
1
Arduino IDE
Project description
Code
Code
c_cpp
Code of the project, made using Arduino IDE
1#include <Ultrasonic.h> //Library for the ultrasonic sensor 2#include<LiquidCrystal_I2C.h> //Library for the display 3#include<Wire.h> 4LiquidCrystal_I2C lcd (0x27, 16, 2); //Creates an object lcd 5Ultrasonic ultrasonic1 (13, 12); //Creates an object ultrasonic1 6Ultrasonic ultrasonic2 (11, 10); //Creates an object ultrasonic1 7int ledOccupied1 = 9; //LED to indicate if the spot is occupied 8int ledFree1 = 8; //LED to indicate if the spot is free 9int ledOccupied2 = 7; //LED to indicate if the spot is occupied 10int ledFree2 = 6; //LED to indicate if the spot is free 11int val1; //val1 as a value variable for ultrasonic sensor 12int val2; //val1 as a value variable for ultrasonic sensor 13byte SpaceA[] = //Custom character to indicate a free spot 14{ 15 0b11111, 16 0b10001, 17 0b10011, 18 0b10111, 19 0b11111, 20 0b10011, 21 0b10011, 22 0b10011 23}; 24byte SpaceB[] = //Custom character to indicate a free spot 25{ 26 0b11111, 27 0b10001, 28 0b11001, 29 0b11101, 30 0b11111, 31 0b11001, 32 0b11001, 33 0b11001 34}; 35byte SpaceC[] = //Custom character to indicate a free spot 36{ 37 0b10011, 38 0b10011, 39 0b10011, 40 0b10011, 41 0b10000, 42 0b10000, 43 0b10000, 44 0b11111 45}; 46byte SpaceD[] = //Custom character to indicate a free spot 47{ 48 0b11001, 49 0b11001, 50 0b11001, 51 0b11001, 52 0b00001, 53 0b00001, 54 0b00001, 55 0b11111 56}; 57byte NoSpaceA[] = //Custom character to indicate a occupied spot 58{ 59 0b11111, 60 0b10000, 61 0b10000, 62 0b11000, 63 0b11100, 64 0b11110, 65 0b10111, 66 0b10011 67}; 68byte NoSpaceB[] = //Custom character to indicate a occupied spot 69{ 70 0b11111, 71 0b00001, 72 0b00001, 73 0b00011, 74 0b00111, 75 0b01111, 76 0b11101, 77 0b11001 78}; 79byte NoSpaceC[] = { //Custom character to indicate a occupied spot 80 0b10011, 81 0b10111, 82 0b11110, 83 0b11100, 84 0b11000, 85 0b10000, 86 0b10000, 87 0b11111 88}; 89byte NoSpaceD[] = { //Custom character to indicate a occupied spot 90 0b11001, 91 0b11101, 92 0b01111, 93 0b00111, 94 0b00011, 95 0b00001, 96 0b00001, 97 0b11111 98}; 99void setup() { 100 lcd.init(); //Starts the display 101 lcd.backlight(); //Turns on the display backlight 102 //Create the custom characters 103 lcd.createChar(1, SpaceA); 104 lcd.createChar(2, SpaceB); 105 lcd.createChar(3, SpaceC); 106 lcd.createChar(4, SpaceD); 107 lcd.createChar(5, NoSpaceA); 108 lcd.createChar(6, NoSpaceB); 109 lcd.createChar(7, NoSpaceC); 110 lcd.createChar(8, NoSpaceD); 111 //Define all LEDs as Output 112 pinMode(ledOccupied1, OUTPUT); 113 pinMode(ledFree1, OUTPUT); 114 pinMode(ledOccupied2, OUTPUT); 115 pinMode(ledFree2, OUTPUT); 116} 117 118void loop() { 119 //Value variables will store all informations from the sensors 120 val1 = ultrasonic1.Ranging(CM); 121 val2 = ultrasonic2.Ranging(CM); 122 //If the first spot is occupied 123 if ((val1 < 10) && (val2 > 10)) { 124 digitalWrite(ledOccupied1, HIGH); 125 digitalWrite(ledFree1, LOW); 126 digitalWrite(ledOccupied2, LOW); 127 digitalWrite(ledFree2, HIGH); 128 lcd.clear(); 129 lcd.write(5); 130 lcd.setCursor(1, 0); 131 lcd.write(6); 132 lcd.setCursor(0, 1); 133 lcd.write(7); 134 lcd.setCursor(1, 1); 135 lcd.write(8); 136 lcd.setCursor(7, 0); 137 lcd.write(1); 138 lcd.setCursor(8, 0); 139 lcd.write(2); 140 lcd.setCursor(7, 1); 141 lcd.write(3); 142 lcd.setCursor(8, 1); 143 lcd.write(4); 144 delay(500); 145 } 146 //If the second spot is occupied 147 else if ((val1 > 10) && (val2 < 10)) { 148 digitalWrite(ledOccupied1, LOW); 149 digitalWrite(ledFree1, HIGH); 150 digitalWrite(ledOccupied2, HIGH); 151 digitalWrite(ledFree2, LOW); 152 lcd.clear(); 153 lcd.write(1); 154 lcd.setCursor(1, 0); 155 lcd.write(2); 156 lcd.setCursor(0, 1); 157 lcd.write(3); 158 lcd.setCursor(1, 1); 159 lcd.write(4); 160 lcd.setCursor(7, 0); 161 lcd.write(5); 162 lcd.setCursor(8, 0); 163 lcd.write(6); 164 lcd.setCursor(7, 1); 165 lcd.write(7); 166 lcd.setCursor(8, 1); 167 lcd.write(8); 168 delay(500); 169 } 170 //If the first and second spots are free 171 else if ((val1 > 10) && (val2 > 10)) { 172 digitalWrite(ledOccupied1, LOW); 173 digitalWrite(ledFree1, HIGH); 174 digitalWrite(ledOccupied2, LOW); 175 digitalWrite(ledFree2, HIGH); 176 lcd.clear(); 177 lcd.write(1); 178 lcd.setCursor(1, 0); 179 lcd.write(2); 180 lcd.setCursor(0, 1); 181 lcd.write(3); 182 lcd.setCursor(1, 1); 183 lcd.write(4); 184 lcd.setCursor(7, 0); 185 lcd.write(1); 186 lcd.setCursor(8, 0); 187 lcd.write(2); 188 lcd.setCursor(7, 1); 189 lcd.write(3); 190 lcd.setCursor(8, 1); 191 lcd.write(4); 192 delay(500); 193 } 194 //If the first and second spots are occupied 195 else if ((val1 < 10) && (val2 < 10)) { 196 digitalWrite(ledOccupied1, HIGH); 197 digitalWrite(ledFree1, LOW); 198 digitalWrite(ledOccupied2, HIGH); 199 digitalWrite(ledFree2, LOW); 200 lcd.clear(); 201 lcd.write(5); 202 lcd.setCursor(1, 0); 203 lcd.write(6); 204 lcd.setCursor(0, 1); 205 lcd.write(7); 206 lcd.setCursor(1, 1); 207 lcd.write(8); 208 lcd.setCursor(7, 0); 209 lcd.write(5); 210 lcd.setCursor(8, 0); 211 lcd.write(6); 212 lcd.setCursor(7, 1); 213 lcd.write(7); 214 lcd.setCursor(8, 1); 215 lcd.write(8); 216 delay(500); 217 } 218 else { 219 lcd.clear(); 220 digitalWrite(ledOccupied1, LOW); 221 digitalWrite(ledFree1, LOW); 222 digitalWrite(ledOccupied2, LOW); 223 digitalWrite(ledFree2, LOW); 224 } 225}
Downloadable files
Schematics
Schematics of the project, made using Tinkercad
Schematics

Schematics
Schematics of the project, made using Tinkercad
Schematics

Comments
Only logged in users can leave comments