Course Content
IoT Engineering Course using ESP32 with 12 Real-World Projects

📡 Smart Parking System – Home WiFi Mode ( Blynk )

✅ Connect to Internet
✅ Send parking data to Blynk Cloud
✅ Show live slot status on mobile
✅ Show total available slots
✅ Control gate automatically

1️⃣ Blynk IoT Setup (Step-by-step)
2️⃣ Datastream Configuration
3️⃣ Dashboard Setup
4️⃣ Complete ESP32 Code
5️⃣ Full Code Explanation

🌐 PART 1 – BLYNK IOT SETUP

Go to:

👉 https://blynk.cloud
Login / Sign Up


🟣 Step 1: Create Template

Click New Template

Fill:

  • Template Name → SmartParking

  • Hardware → ESP32

  • Connection Type → WiFi

Click Create.


🟣 Step 2: Create Datastreams (Very Important)

Go to:

Template → Datastreams → New Datastream → Virtual Pin

Create these:


🔹 V0 – Total Available Slots

  • Name → Available Slots

  • Virtual Pin → V0

  • Data Type → Integer

  • Min → 0

  • Max → 5

  • Save


🔹 V1 – Slot 1 Status

  • Name → Slot1

  • Virtual Pin → V1

  • Data Type → Integer

  • Min → 0

  • Max → 1

(1 = Available, 0 = Occupied)


🔹 V2 – Slot 2 Status

Same as above
Virtual Pin → V2


🔹 V3 – Slot 3 Status

Virtual Pin → V3


🔹 V4 – Slot 4 Status

Virtual Pin → V4


🔹 V5 – Slot 5 Status

Virtual Pin → V5


🔹 V6 – Parking Message

  • Name → Parking Status

  • Virtual Pin → V6

  • Data Type → String


🟣 Step 3: Create Device

Go to:

Devices → New Device → From Template

Select SmartParking template
Device Name → Parking_01

Click Create.


🟣 Step 4: Copy Credentials

Open Device → Device Info

Copy:

  • BLYNK_TEMPLATE_ID

  • BLYNK_TEMPLATE_NAME

  • BLYNK_AUTH_TOKEN

You will paste them in code.


📱 PART 2 – BLYNK MOBILE DASHBOARD SETUP

Open Blynk IoT App.

Select your device.

Add Widgets:


🟢 Widget 1: Gauge (Total Slots)

  • Virtual Pin → V0

  • Range → 0 to 5


🟢 Widget 2–6: LED Widgets (Slot Status)

Add 5 LED widgets:

  • Slot1 → V1

  • Slot2 → V2

  • Slot3 → V3

  • Slot4 → V4

  • Slot5 → V5

Green = Available
Red = Occupied


🟡 Widget 7: Label (Parking Message)

Virtual Pin → V6


Now dashboard is ready.


💻 PART 3 – COMPLETE ESP32 CODE (Blynk IoT Version)

Install libraries first:

Sketch → Manage Libraries → Install:

  • Blynk

  • Servo (if not installed)

#define BLYNK_TEMPLATE_ID "TMPL3dZSykeR9"
#define BLYNK_TEMPLATE_NAME "parking system"
#define BLYNK_AUTH_TOKEN "eZxTaLBVerEHslZe6VB5XEEi_Vg3iEw0"

#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <ESP32Servo.h>

char ssid[] = "NextGen";
char pass[] = "12345678";

BlynkTimer timer;

// IR Sensors
#define IR1 14
#define IR2 27
#define IR3 26
#define IR4 25
#define IR5 33

// Ultrasonic Sensor
#define TRIG 4
#define ECHO 19

// Servo
Servo gateServo;
#define SERVO_PIN 18

long duration;
float distance;

void sendData()
{
  int available = 0;

  int slot1 = digitalRead(IR1);
  int slot2 = digitalRead(IR2);
  int slot3 = digitalRead(IR3);
  int slot4 = digitalRead(IR4);
  int slot5 = digitalRead(IR5);

  // If IR sensor HIGH means slot empty
  if (slot1 == HIGH) available++;
  if (slot2 == HIGH) available++;
  if (slot3 == HIGH) available++;
  if (slot4 == HIGH) available++;
  if (slot5 == HIGH) available++;

  // Send to Blynk
  Blynk.virtualWrite(V0, available);

  Blynk.virtualWrite(V1, slot1);
  Blynk.virtualWrite(V2, slot2);
  Blynk.virtualWrite(V3, slot3);
  Blynk.virtualWrite(V4, slot4);
  Blynk.virtualWrite(V5, slot5);

  // Ultrasonic Distance
  digitalWrite(TRIG, LOW);
  delayMicroseconds(2);

  digitalWrite(TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG, LOW);

  duration = pulseIn(ECHO, HIGH);
  distance = duration * 0.034 / 2;

  Serial.print("Distance: ");
  Serial.println(distance);

  if (distance > 0 && distance < 15)
  {
    if (available > 0)
    {
      gateServo.write(90);
      Blynk.virtualWrite(V6, "Gate Open - Slots Available");

      delay(3000);

      gateServo.write(0);
    }
    else
    {
      gateServo.write(0);
      Blynk.virtualWrite(V6, "Parking Full - Gate Closed");
    }
  }
}

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

  pinMode(IR1, INPUT);
  pinMode(IR2, INPUT);
  pinMode(IR3, INPUT);
  pinMode(IR4, INPUT);
  pinMode(IR5, INPUT);

  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);

  gateServo.setPeriodHertz(50);
  gateServo.attach(SERVO_PIN, 500, 2400);
  gateServo.write(0);

  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

  timer.setInterval(2000L, sendData);
}

void loop()
{
  Blynk.run();
  timer.run();
}


🧠 FULL CODE EXPLANATION


1️⃣ Template Credentials

These connect ESP32 to Blynk Cloud.

Without them → Device will not connect.


2️⃣ BlynkTimer

We use timer instead of delay() because:

Blynk needs continuous communication.

Delay blocks cloud communication.


3️⃣ sendData() Function

Runs every 2 seconds.

It:

  • Reads IR sensors

  • Counts available slots

  • Sends data to virtual pins

  • Checks ultrasonic

  • Controls gate

  • Sends status message


4️⃣ Virtual Pins

V0 → Total available slots
V1–V5 → Individual slot status
V6 → Parking message


📊 What You Will See in App

When slots available:

Gauge → 3
LEDs → Some ON (green)
Label → Gate Open – Slots Available

When full:

Gauge → 0
All LEDs OFF
Label → Parking Full – Gate Closed


🎓 Viva Explanation

“In this version, ESP32 connects to WiFi and communicates with Blynk Cloud. Each parking slot status is sent to virtual pins. The mobile dashboard displays real-time slot availability. The ultrasonic sensor detects vehicles and the servo motor controls the gate. The system allows remote monitoring and smart city integration.”

Scroll to Top