#include <Servo.h>
#include <ESP8266WiFi.h>
int entrance = D5;
int exit_ = D6;
int slot1 = D1;
int slot2 = D2;
int slot3 = D3;
int slot4 = D4;
int cars = 0;
Servo gate;
void setup() {
gate.attach(D8);
pinMode(entrance, INPUT);
pinMode(exit_, INPUT);
pinMode(slot1, INPUT);
pinMode(slot2, INPUT);
pinMode(slot3, INPUT);
pinMode(slot4, INPUT);
Serial.begin(9600);
gate.write(0); //Gate will close
delay(1000);
}
void loop() {
int in = digitalRead(entrance);
int out = digitalRead(exit_);
int s1 = digitalRead(slot1);
int s2 = digitalRead(slot2);
int s3 = digitalRead(slot3);
int s4 = digitalRead(slot4);
if (cars == 5) {
Serial.println("PARKING FULL!");
}
else {
Serial.print("Occupied Parking Slots: ");
Serial.print(cars);
Serial.print("Available Slots: ");
if (s1 == 1){
Serial.print(" Slot 1, ");
}
if (s2 == 1){
Serial.print("Slot 2, ");
}
if (s3 == 1){
Serial.print("Slot 3, ");
}
if (s4 == 1){
Serial.print("Slot 4");
}
if (s1 == 0 && s2 == 0 && s3 == 0 && s4 == 0){
Serial.print("PARKING SPACES OCCUPIED!");
}
Serial.println();
}
if(in == 0 && cars < 5){
cars = cars + 1;
gate.write(90); //Gate will open
delay(1000);
gate.write(0);
}
if (out == 0 && cars > 0){
cars = cars - 1;
delay(1000);
}
}
Please help
Getting an answer is more probable if you ask your question properly.
Which data do you want to send for which purpose?
1 Like