smart WiFi Car Parking System node mcu with parking slot and bill status

 

WiFi Car Parking System 

Components:

  • ESP8266 (NodeMCU)

  • IR Sensors (4 for 4 parking slots)

  • Bluetooth/WiFi for mobile app control or monitoring

  • LEDs (optional) to visually indicate the slot status


Circuit:



  1. IR Sensors:

    • IR Sensor 1 (Slot 1): OUT → D6

    • IR Sensor 2 (Slot 2): OUT → D7

    • IR Sensor 3 (Slot 3): OUT → D8

    • IR Sensor 4 (Slot 4): OUT → D9

  2. ESP8266:

    • GND → GND

    • VCC → 3.3V or 5V depending on your ESP8266 variant

  3. LEDs (optional):

    • LED 1: Slot 1 – Connected to D1

    • LED 2: Slot 2 – Connected to D2

    • LED 3: Slot 3 – Connected to D3

    • LED 4: Slot 4 – Connected to D4


Code


#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <NTPClient.h>
#include <WiFiUdp.h>

const char *ssid = "wifiname";  
const char *password = "password";  

ESP8266WebServer server(80);


const int slot1Pin = D6;
const int slot2Pin = D7;
const int slot3Pin = D8;
const int slot4Pin = D9;


WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", 19800, 60000);  


unsigned long entryTime[4] = {0, 0, 0, 0};  


float ratePerMinute = 5.0;

void setup() {
  Serial.begin(115200);

 
  pinMode(slot1Pin, INPUT);
  pinMode(slot2Pin, INPUT);
  pinMode(slot3Pin, INPUT);
  pinMode(slot4Pin, INPUT);


  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi!");

  
  timeClient.begin();
  timeClient.update();


  server.on("/", HTTP_GET, []() {
    String html = "<html><head><style>"
                  "body { font-family: Arial, sans-serif; background-color: #f0f0f0; text-align: center; }"
                  "h1 { color: #333; }"
                  "p { font-size: 20px; color: #555; }"
                  ".status { font-weight: bold; color: #007bff; }"
                  "</style></head><body>";
    html += "<h1>Parking Slot Status</h1>";
    html += "<p>Slot 1: <span class='status'>" + getSlotStatus(slot1Pin, 0) + "</span></p>";
    html += "<p>Slot 2: <span class='status'>" + getSlotStatus(slot2Pin, 1) + "</span></p>";
    html += "<p>Slot 3: <span class='status'>" + getSlotStatus(slot3Pin, 2) + "</span></p>";
    html += "<p>Slot 4: <span class='status'>" + getSlotStatus(slot4Pin, 3) + "</span></p>";
    html += "</body></html>";
    server.send(200, "text/html", html);
  });

  server.begin();
}

void loop() {
  server.handleClient();
  timeClient.update();
}

String getSlotStatus(int pin, int slotIndex) {
  int sensorValue = digitalRead(pin);
  
  if (sensorValue == LOW) {  
    if (entryTime[slotIndex] == 0) {  
      entryTime[slotIndex] = timeClient.getEpochTime();
    }
    return "Occupied - Bill: " + String(calculateBill(slotIndex)) + " LKR";
  } else {
    if (entryTime[slotIndex] != 0) {  
      entryTime[slotIndex] = 0;
    }
    return "Available";
  }
}

float calculateBill(int slotIndex) {
  if (entryTime[slotIndex] == 0) {
    return 0.0;  
  }

  unsigned long parkingDuration = timeClient.getEpochTime() - entryTime[slotIndex];  
  float parkingDurationInMinutes = parkingDuration / 60.0;

  
  float bill = parkingDurationInMinutes * ratePerMinute;

  return bill;
}

Post a Comment

0 Comments