0% found this document useful (0 votes)
4 views7 pages

ESP32 Arduino Program

The document contains an Arduino program for the ESP32 that monitors vital signs using Blynk, a cloud-based IoT platform. It integrates various sensors to measure ambient temperature, humidity, body temperature, and heart rate, sending the data to the Blynk app. The program includes setup and loop functions to initialize the sensors and continuously read and transmit data every two seconds.

Uploaded by

charishvillariza
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

ESP32 Arduino Program

The document contains an Arduino program for the ESP32 that monitors vital signs using Blynk, a cloud-based IoT platform. It integrates various sensors to measure ambient temperature, humidity, body temperature, and heart rate, sending the data to the Blynk app. The program includes setup and loop functions to initialize the sensors and continuously read and transmit data every two seconds.

Uploaded by

charishvillariza
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ESP32 Arduino Program

/************************************************************
* BLYNK CONFIG
************************************************************/
#define BLYNK_TEMPLATE_ID "TMPL6TFN8AYQK"
#define BLYNK_TEMPLATE_NAME "Vital Monitor"
#define BLYNK_AUTH_TOKEN "u7FYfYrUfn1HzB8iJspkzmn8gYVjyfJU"

#define BLYNK_PRINT Serial

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

/************************************************************
* WIFI
************************************************************/
char ssid[] = "VLM";
char pass[] = "MathLab304843!";

/************************************************************
* SENSORS
************************************************************/
#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include <MAX30105.h>
#include "heartRate.h"
#include "DHT.h"

/************************************************************
* PIN DEFINITIONS
************************************************************/
#define DHTPIN 4
#define DHTTYPE DHT11
#define I2C_SDA 21
#define I2C_SCL 22

/************************************************************
* CALIBRATION
************************************************************/
#define OBJECT_OFFSET -2.6
#define AMBIENT_OFFSET 0.0

/************************************************************
* OBJECTS
************************************************************/
DHT dht(DHTPIN, DHTTYPE);
MAX30105 particleSensor;
Adafruit_MLX90614 mlx;
BlynkTimer timer;

/************************************************************
* HEART RATE VARIABLES
************************************************************/
const byte RATE_SIZE = 4;
byte rates[RATE_SIZE];
byte rateSpot = 0;
long lastBeat = 0;
float beatsPerMinute = 0;
int beatAvg = 0;

/************************************************************
* BODY TEMP FUNCTION
************************************************************/
float readCalibratedBodyTemp() {
float rawTemp = [Link]();

if (rawTemp < 20 || rawTemp > 45 || isnan(rawTemp)) {


return 0;
}
return rawTemp + OBJECT_OFFSET;
}

/************************************************************
* SEND DATA TO BLYNK
************************************************************/
void sendToBlynk() {
float ambientTemp = [Link]();
float ambientHum = [Link]();
float bodyTemp = readCalibratedBodyTemp();

// V0 – Ambient Temperature
if (!isnan(ambientTemp)) {
[Link](V0, (int)ambientTemp);
}

// V1 – Ambient Humidity
if (!isnan(ambientHum)) {
[Link](V1, (int)ambientHum);
}

// V2 – Body Heat
if (bodyTemp > 0) {
[Link](V2, bodyTemp);
}

// V3 – Heartbeat
if (beatAvg > 0) {
[Link](V3, beatAvg);
}
// V4 – Activity Log
String activity = "";

if (bodyTemp > 0) {
if (bodyTemp < 35.5) activity += "Low body temp | ";
else if (bodyTemp < 37.2) activity += "Normal body temp | ";
else if (bodyTemp < 38.0) activity += "Slight fever | ";
else activity += "High fever | ";
} else {
activity += "Body temp not detected | ";
}

if (beatAvg > 0) {
activity += "HR: " + String(beatAvg) + " BPM";
} else {
activity += "Waiting for finger";
}

[Link](V4, activity);
}

/************************************************************
* SETUP
************************************************************/
void setup() {
[Link](115200);
delay(1000);

[Link](I2C_SDA, I2C_SCL);

[Link]("=== CALIBRATED VITAL MONITOR ===");


[Link]("Connecting to Blynk...");

[Link](BLYNK_AUTH_TOKEN, ssid, pass);

[Link]();
delay(2000);

if ([Link](0x5A, &Wire) || [Link](0x5B, &Wire)) {


[Link]("MLX90614 OK");
}

if ([Link](Wire, I2C_SPEED_STANDARD)) {
[Link]();
[Link](0x0F);
[Link]("MAX30102 OK");
}

[Link](2000L, sendToBlynk);
[Link]("System Ready");
}

/************************************************************
* LOOP
************************************************************/
void loop() {
[Link]();
[Link]();

long irValue = [Link]();


bool fingerDetected = (irValue > 30000);

if (fingerDetected && checkForBeat(irValue)) {


long delta = millis() - lastBeat;
lastBeat = millis();
beatsPerMinute = 60 / (delta / 1000.0);

if (beatsPerMinute > 40 && beatsPerMinute < 200) {


rates[rateSpot++] = (byte)beatsPerMinute;
rateSpot %= RATE_SIZE;

beatAvg = 0;
for (byte i = 0; i < RATE_SIZE; i++) {
beatAvg += rates[i];
}
beatAvg /= RATE_SIZE;
}
}

delay(20);
}

You might also like