#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#define servoPin 9
#define inSensor A0
#define outSensor A1
int counterCar;
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD
Servo gateServo;
void setup() {
lcd.init(); // initialize the LCD
lcd.backlight(); // Turn on the
pinMode(inSensor, INPUT);
pinMode(outSensor, INPUT);
gateServo.attach(servoPin);
gateServo.write(90);
lcd.home();
lcd.print("Parking System");
counterCar = 0;
lcd.setCursor(0,1);
lcd.print("No of Car = ");
lcd.print(counterCar);
}
void loop() {
if(digitalRead(inSensor) == LOW){
while(digitalRead(inSensor) == LOW){
gateServo.write(170);
delay(100);
}
counterCar++;
lcd.setCursor(12,1);
lcd.print(counterCar);
gateServo.write(90);
delay(500);
}
if(digitalRead(outSensor) == LOW){
while(digitalRead(outSensor) == LOW){
gateServo.write(170);
delay(100);
}
counterCar--;
if(counterCar < 0) counterCar = 0;
lcd.setCursor(12,1);
lcd.print(counterCar);
gateServo.write(90);
delay(500);
}
}