// Viral Science www.viralsciencecreativity.com www.youtube.com/c/viralscience
// Arduino Car Parking System
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change the HEX address
#include <Servo.h>
Servo myservo1;
int IR1 = 2;
int IR2 = 4;
int Slot = 4; // Enter Total number of parking Slots
int flag1 = 0;
int flag2 = 0;
void setup()
{
lcd.init();
lcd.backlight();
pinMode(IR1, INPUT);
pinMode(IR2, INPUT);
myservo1.attach(3);
myservo1.write(100);
lcd.setCursor(0, 0);
lcd.print(" ARDUINO ");
lcd.setCursor(0, 1);
lcd.print(" PARKING SYSTEM ");
delay(2000);
lcd.clear();
Serial.begin(9600)
}
void loop()
{
Serial.println("loop start");
if (digitalRead(IR1) == LOW && flag1 == 0)
{
Serial.println("IR1: LOW flag1: 0");
if (Slot > 0)
{
Serial.print("X ");
Serial.println(Slot);
flag1 = 1;
if (flag2 == 0)
{
myservo1.write(0);
Slot = Slot - 1;
}
}
else
{
Serial.println("Full");
lcd.setCursor(0, 0);
lcd.print(" SORRY :( ");
lcd.setCursor(0, 1);
lcd.print(" Parking Full ");
delay(3000);
lcd.clear();
}
}
if (digitalRead(IR2) == LOW && flag2 == 0)
{
Serial.println("IR2: LOW flag2: 0");
flag2 = 1;
if (flag1 == 0)
{
myservo1.write(0);
Slot = Slot + 1;
}
}
if (flag1 == 1 && flag2 == 1)
{
Serial.println("flag1: 1 flag2: 1");
delay(1000);
myservo1.write(100);
flag1 = 0, flag2 = 0;
}
lcd.setCursor(0, 0);
lcd.print(" WELCOME! ");
lcd.setCursor(0, 1);
lcd.print("Slot Left: ");
lcd.print(Slot);
Serial.println("loop end");
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}