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