#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include<Servo.h>
Servo Myservo;
int IRSensor_1 = 4,IRSensor_2 = 5,IRSensor_3 = 6; // connect IR sensor DO to arduino pin 2
int led_1 = 8,led_2=9,led_3=10; // connect LED to arduino pin 13 or monitor inbuilt LED
int c1 = 0,c2=0,c3=0;
int park_1=0,park_2=0,park_3=0;
int but1=2,but2=7,but3=11,con_but = 3;
int srvo = 12;
int con_flag = 0 , cb = 0;
LiquidCrystal_I2C lcd(0x27,20,4);
void setup()
{
pinMode(IRSensor_1, INPUT); // sensor pin INPUT
pinMode(IRSensor_2, INPUT); // sensor pin INPUT
pinMode(IRSensor_3, INPUT); // sensor pin INPUT
pinMode(but1, INPUT);
pinMode(but2, INPUT);
pinMode(but3, INPUT);
pinMode(con_but, INPUT);
pinMode(led_1, OUTPUT); // LED pin OUTPUT
pinMode(led_2, OUTPUT); // LED pin OUTPUT
pinMode(led_3, OUTPUT); // LED pin OUTPUT
Myservo.attach(srvo); // Initiate Servo motor
lcd.init(); //initailize the LCD
lcd.backlight();
lcd.print("Car Parking");
delay(2000);
lcd.clear();
lcd.print("Total car parked");
lcd.setCursor(0,1);
lcd.print("today");
delay(2000);
lcd.clear();
Serial.begin(9600);
}
void loop(){
int statusSensor_1 = digitalRead(IRSensor_1);
int statusSensor_2 = digitalRead(IRSensor_2);
int statusSensor_3 = digitalRead(IRSensor_3);
//Select the slot
int b1 = digitalRead(but1);
int b2 = digitalRead(but2);
int b3 = digitalRead(but3);
//For parking slot - 1
if (statusSensor_1 == 0 && park_1 ==0){
c1 +=1;
park_1 = 1;
}
else if (statusSensor_1 == 1) {
park_1 =0;
digitalWrite(led_1, LOW);
}
//For parking slot - 2
if (statusSensor_2 == 0 && park_2 ==0){
c1 +=1;
park_2 = 1;
}
else if (statusSensor_2 == 1) {
park_2 =0;
digitalWrite(led_2, LOW);
}
//For parking slot - 3
if (statusSensor_3 == 0 && park_3 ==0){
c1 +=1;
park_3 = 1;
}
else if (statusSensor_3 == 1) {
park_3 =0;
digitalWrite(led_3, LOW);
}
//For the LED indication
if (park_1 == 1){
digitalWrite(led_1, HIGH);
}
if (park_2 == 1){
digitalWrite(led_2, HIGH);
}
if (park_3 == 1){
digitalWrite(led_3, HIGH);
}
lcd.setCursor(0,0);
lcd.print("Total cars : ");
lcd.setCursor(13,0);
lcd.print(c1+c2+c3);
lcd.setCursor(0,1);
lcd.print("Slot : ");
lcd.setCursor(8,1);
if (park_1 == 1){lcd.print(0);}else{lcd.print(1);}
lcd.setCursor(10,1);
if (park_2 == 1){lcd.print(0);}else{lcd.print(2);}
lcd.setCursor(12,1);
if (park_3 == 1){lcd.print(0);}else{lcd.print(3);}
if (b1==0 && b2==0 && b3==0){
lcd.setCursor(0,2);
lcd.print("Press the button");
}
else if(park_1 == 0 || park_2 == 0 ||park_3 == 0){
if (park_1 == 0 && b1 == 1 && con_flag ==0){
lcd.setCursor(0,2);
lcd.print("Price : Rs.50");
con_flag = 1;
}
else if (con_flag == 0){
lcd.setCursor(0,2);
lcd.print("Slot unavailable");
con_flag = 0;
}
if (park_2 == 0 && b2 == 1 && con_flag ==0){
lcd.setCursor(0,2);
lcd.print("Price : Rs.50");
con_flag = 1;
}
else if (con_flag == 0){
lcd.setCursor(0,2);
lcd.print("Slot unavailable");
con_flag = 0;
}
if (park_3 == 0 && b3 == 1 && con_flag ==0){
lcd.setCursor(0,2);
lcd.print("Price : Rs.50");
con_flag = 1;
}
else if (con_flag == 0){
lcd.setCursor(0,2);
lcd.print("Slot unavailable");
con_flag = 0;
}
Serial.println(cb);
if (con_flag == 1){
int i =0;
while (cb !=1 && i<250){
cb = digitalRead(con_but);
i = i+1;
}
}
Serial.println(cb);
if (cb == 1 && con_flag == 1){
Myservo.write(0);
delay(5000);
Myservo.write(90);
delay(5000);
con_flag = 0;
cb = 0;
}
}
else{
lcd.setCursor(0,2);
lcd.print("parking unavailable");
con_flag = 0;
delay(5000);
}
lcd.setCursor(0,0);
//lcd.print("Press the button");
//lcd.setCursor(0,0);
}