#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL3WT83LmfX"
#define BLYNK_TEMPLATE_NAME "HEALTHCAREIOT"
#define BLYNK_AUTH_TOKEN "l4k-iF5CS6z6YtgrcqPSxMS8PGcZazGi"
#include <LiquidCrystal_I2C.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Wire.h>
// Initialize LCD with I2C address 0x27
LiquidCrystal_I2C lcd(0x27, 16, 2);
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
// Sensor Pins mapped to your Wokwi diagram potentiometers
const int PIN_BPM = 2;
const int PIN_SPO2 = 3;
const int PIN_TEMP = 4;
int currentBPM = 0;
int currentSpo2 = 0;
float currentTemp = 0.0;
// Correctly declare the timer object
BlynkTimer timer;
void sendSensorData() {
// 1. Read the potentiometers
int rawBPM = analogRead(PIN_BPM);
int rawSpo2 = analogRead(PIN_SPO2);
int rawTemp = analogRead(PIN_TEMP);
// 2. Manipulate/Map the raw data into realistic health numbers
currentBPM = map(rawBPM, 0, 4095, 60, 140); // BPM ranges from 60 to 140
currentSpo2 = map(rawSpo2, 0, 4095, 90, 100); // SpO2 ranges from 90% to 100%
currentTemp = 35.0 + (float(rawTemp) / 4095.0) * 6.0; // Temp ranges from 35.0C to 41.0C
// 3. Display text and variables on the LCD
lcd.clear();
// First row: "BPM: 75 SpO2: 98"
lcd.setCursor(0,0);
lcd.print("BPM:");
lcd.print(currentBPM);
lcd.print(" SpO2:");
lcd.print(currentSpo2);
// Second row: "Temp: 37.5C"
lcd.setCursor(0,1);
lcd.print("Temp: ");
lcd.print(currentTemp);
lcd.print("C");
// 4. Send the manipulated data to the Blynk Website
Blynk.virtualWrite(V0, currentBPM);
Blynk.virtualWrite(V1, currentSpo2);
Blynk.virtualWrite(V2, currentTemp);
}
void setup() {
Serial.begin(115200);
Serial.println("IOT Based Health Monitoring System");
// Explicitly set I2C pins to match your Wokwi wiring
Wire.begin(6, 7); // SDA = 6, SCL = 7
// Initialize Screen and display startup text
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("IoT Health");
lcd.setCursor(0,1);
lcd.print("Monitor System");
delay(1500);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Connecting to");
lcd.setCursor(0,1);
lcd.print("WiFi & Blynk...");
// Connect to Blynk
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Connected!");
delay(1000);
// Set the timer to read the potentiometers every 2 seconds
timer.setInterval(2000L, sendSensorData);
}
void loop() {
delay(10); // Keeps Wokwi simulation running smoothly
Blynk.run();
timer.run();
}Loading
esp32-c6-devkitc-1
esp32-c6-devkitc-1