#define BLYNK_TEMPLATE_ID "TMPLahbzupmn"
#define BLYNK_DEVICE_NAME "Smart Parking System"
#define BLYNK_AUTH_TOKEN "trBE_eTWPrpFiD3vCULsThrh7s6bkgDW"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <LiquidCrystal_I2C.h>
#include<ESP32Servo.h>
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
#define Entry_sensor 26
#define Slot1_sensor 18
#define Slot2_sensor 19
#define Exit_sensor 4
int state_entry;
int state_slot1;
int state_slot2;
int state_exit;
// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin V1
BLYNK_WRITE(V0)
{
int state_slot1= digitalRead(Slot1_sensor);
int pinValue = param.asInt(); // assigning incoming value from pin V0 to a variable
Blynk.virtualWrite(V0, state_slot1);
// process received value
}
BLYNK_WRITE(V1)
{
int state_slot2= digitalRead(Slot2_sensor);
int pinValue_1 = param.asInt(); // assigning incoming value from pin V1 to a variable
digitalRead(Slot2_sensor);
Blynk.virtualWrite(V0, state_slot2);
// process received value
}
LiquidCrystal_I2C lcd(0x27,16,2);
Servo Servo1;
Servo Servo2;
int zero=0;
int one=1;
void setup()
{
pinMode(Entry_sensor, INPUT);
pinMode(Slot1_sensor, INPUT);
pinMode(Slot2_sensor, INPUT);
pinMode(Exit_sensor, INPUT);
Servo1.attach(25);
Servo2.attach(23);
lcd.init();
// Debug console
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
lcd.init();
lcd.print(" Smart Parking..");
lcd.setCursor(0, 1);
lcd.print(" System");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Slot 1= A");
lcd.setCursor(0, 1);
lcd.print("Slot 2= A");
delay(2000);
}
void loop()
{
Blynk.run();
int state_entry = digitalRead(Entry_sensor);
int state_slot1 = digitalRead(Slot1_sensor);
int state_slot2 = digitalRead(Slot2_sensor);
int state_exit = digitalRead(Exit_sensor);
if(state_entry == LOW){
Servo1.write(90);
}
else{
Servo1.write(179);
}
if(state_slot1 == HIGH){
lcd.setCursor(0, 0);
lcd.print("Slot 1= NA");
Blynk.virtualWrite(V0, HIGH);
delay(1000);
}
else{
lcd.setCursor(0, 0);
lcd.print("Slot 1= A");
Blynk.virtualWrite(V0, LOW);
delay(1000);
}
if(state_slot2 == HIGH){
lcd.setCursor(0, 1);
lcd.print("Slot 2= NA");
Blynk.virtualWrite(V1, HIGH);
delay(1000);
}
else{
lcd.setCursor(0, 1);
lcd.print("Slot 2= A");
Blynk.virtualWrite(V1, LOW);
delay(1000);
}
if(state_exit == LOW){
Servo2.write(90);
}
else{
Servo2.write(179);
}
}