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

🌉 Bridge Health Monitoring Using ESP32 + Flex Sensor + Blynk IoT

✅ Complete ESP32 Code
✅ Full Line-by-Line Explanation
✅ Blynk IoT Setup (Template + Virtual Pins)
✅ Widget Setup Guide
✅ Viva Explanation

🟣 STEP 1: Blynk IoT Setup (Very Important)

Go to:

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


🧩 1️⃣ Create Template

Click New Template

Fill:

  • Template Name → BridgeMonitor

  • Hardware → ESP32

  • Connection Type → WiFi

Click Create


🧩 2️⃣ Create Datastreams (Virtual Pins)

Go to Datastreams → New Datastream → Virtual Pin

Create 2 datastreams:


🔹 Datastream 1 (Sensor Value)

  • Name → Flex Value

  • Virtual Pin → V0

  • Data Type → Integer

  • Min → 0

  • Max → 4095

  • Save


🔹 Datastream 2 (Bridge Status)

  • Name → Bridge Status

  • Virtual Pin → V1

  • Data Type → String

  • Save


🧩 3️⃣ Create Device

Go to:

Devices → New Device → From Template

Select:

BridgeMonitor template

Device name → Bridge_01

Click Create


🧩 4️⃣ Copy Credentials

Open Device → Device Info

Copy:

  • BLYNK_TEMPLATE_ID

  • BLYNK_TEMPLATE_NAME

  • BLYNK_AUTH_TOKEN

You will paste these in code.


📱 STEP 2: Setup Mobile Dashboard

Open Blynk IoT App

Login

Select your device

Add Widgets:


🟢 Widget 1: Gauge (Flex Value)

  • Tap “+”

  • Select Gauge

  • Virtual Pin → V0

  • Range → 0 to 4095


🔴 Widget 2: Label (Bridge Status)

  • Add Label Widget

  • Virtual Pin → V1


🔔 Optional Widget 3: LED

  • Add LED Widget

  • Virtual Pin → V2 (we will add in code)

  • Color → Red


Now dashboard is ready.


💻 Complete ESP32 Code (Blynk IoT Version)

Install Libraries first:

Sketch → Manage Libraries → Install:

  • Blynk

  • WiFi (already installed)

// Bridge Health Monitoring System
// ESP32 + Flex Sensor + Blynk IoT

#define BLYNK_TEMPLATE_ID "Your_Template_ID"
#define BLYNK_TEMPLATE_NAME "BridgeMonitor"
#define BLYNK_AUTH_TOKEN "Your_Auth_Token"

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

char ssid[] = "YOUR_WIFI_NAME";
char pass[] = "YOUR_WIFI_PASSWORD";

const int flexPin = 34;
int flexValue = 0;
int threshold = 2500;

BlynkTimer timer;

void sendSensorData() {

flexValue = analogRead(flexPin);

Serial.print("Flex Value: ");
Serial.println(flexValue);

Blynk.virtualWrite(V0, flexValue);

if (flexValue > threshold) {
Blynk.virtualWrite(V1, "⚠️ Bridge Under Stress!");
Blynk.virtualWrite(V2, 255); // LED ON
} else {
Blynk.virtualWrite(V1, "✅ Bridge Safe");
Blynk.virtualWrite(V2, 0); // LED OFF
}
}

void setup() {

Serial.begin(115200);
pinMode(flexPin, INPUT);

Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

timer.setInterval(1000L, sendSensorData);
}

void loop() {

Blynk.run();
timer.run();
}

🧠 FULL CODE EXPLANATION


1️⃣ Template Definitions

 
 
#define BLYNK_TEMPLATE_ID
#define BLYNK_TEMPLATE_NAME
#define BLYNK_AUTH_TOKEN
 

These connect ESP32 to your Blynk Cloud account.

Without this → device will not connect.


2️⃣ Include Libraries

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

WiFi.h → Connect to router
BlynkSimpleEsp32.h → Connect to Blynk Cloud


3️⃣ WiFi Credentials

 
 
char ssid[] = “YOUR_WIFI_NAME”;
char pass[] = “YOUR_WIFI_PASSWORD”;
 

ESP32 connects to home WiFi.


4️⃣ Timer Object

 
 
BlynkTimer timer;
 

Used instead of delay().

Important because Blynk requires continuous background running.


5️⃣ sendSensorData() Function

Runs every 1 second.


🔹 Read Sensor

 
 
flexValue = analogRead(flexPin);
 

ADC range: 0–4095.


🔹 Send Value to Gauge

 
 
Blynk.virtualWrite(V0, flexValue);
 

V0 → Gauge Widget


🔹 Send Status Message

 
 
Blynk.virtualWrite(V1, “Bridge Safe”);
 

V1 → Label Widget


🔹 LED Control

 
 
Blynk.virtualWrite(V2, 255);
 

255 → LED ON
0 → LED OFF


6️⃣ setup()

 
 
Blynk.begin(…)
 

Connects ESP32 to:

WiFi + Blynk Cloud


7️⃣ loop()

 
 
Blynk.run();
timer.run();
 

Must run continuously.

Never use delay() inside loop for Blynk.


📊 What You Will See in Blynk App

When Safe:

Gauge → ~1800
Label → ✅ Bridge Safe
LED → OFF

When Bent:

Gauge → ~3100
Label → ⚠️ Bridge Under Stress
LED → ON


🔎 Complete System Logic (For Viva)

  1. Flex sensor detects bending.

  2. Resistance changes.

  3. Voltage divider converts resistance to voltage.

  4. ESP32 ADC converts to digital value.

  5. ESP32 connects to WiFi.

  6. ESP32 connects to Blynk Cloud server.

  7. Sensor data sent to virtual pins.

  8. Dashboard widgets display real-time data.

  9. If value > threshold → Warning alert.

  10. Engineer can monitor bridge remotely from anywhere.


🎓 Important Viva Questions

❓ What is Virtual Pin?
→ Software pin used for cloud communication.

❓ Why BlynkTimer instead of delay()?
→ delay() blocks cloud communication.

❓ Is this real-time monitoring?
→ Yes, cloud-based IoT monitoring.

❓ Can data be accessed globally?
→ Yes, from anywhere with internet.

Scroll to Top