#include <WiFi.
h>
#include <HTTPClient.h>
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#define WIFI_SSID "your_SSID" // Replace with your WiFi SSID
#define WIFI_PASS "your_PASSWORD" // Replace with your WiFi Password
#define THINGSPEAK_API_KEY "your_API_KEY" // Replace with your ThingSpeak API Key
#define THINGSPEAK_URL "http://api.thingspeak.com/update"
#define LM35_PIN 34 // LM35 Temperature Sensor (Analog)
#define ECG_PIN 35 // AD8232 ECG Sensor (Analog)
#define PRESSURE_PIN 32 // MPX5050 Pressure Sensor (Analog)
PulseOximeter pox;
float bpm = 0.0, spo2 = 0.0;
unsigned long lastUpdate = 0;
const int updateInterval = 15000; // Send data every 15 seconds
void onBeatDetected() {
Serial.println("Beat Detected!");
}
void setup() {
Serial.begin(115200);
// Connect to WiFi
WiFi.begin(WIFI_SSID, WIFI_PASS);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("\nConnected to WiFi");
// Initialize MAX30100
if (!pox.begin()) {
Serial.println("MAX30100 initialization failed!");
} else {
Serial.println("MAX30100 initialized.");
pox.setOnBeatDetectedCallback(onBeatDetected);
}
}
void loop() {
pox.update();
// Read LM35 Temperature Sensor
float temp = analogRead(LM35_PIN) * (3.3 / 4095.0) * 100.0;
// Read AD8232 ECG Signal
int ecgValue = analogRead(ECG_PIN);
// Read MPX5050 Pressure Sensor
float pressure = (analogRead(PRESSURE_PIN) * (3.3 / 4095.0)) * 50.0;
// Read MAX30100 Data
bpm = pox.getHeartRate();
spo2 = pox.getSpO2();
Serial.print("Temperature: "); Serial.print(temp); Serial.println(" °C");
Serial.print("ECG: "); Serial.println(ecgValue);
Serial.print("Pressure: "); Serial.print(pressure); Serial.println(" kPa");
Serial.print("Heart Rate: "); Serial.print(bpm); Serial.println(" BPM");
Serial.print("SpO2: "); Serial.print(spo2); Serial.println(" %");
// Send data to ThingSpeak every 15 seconds
if (millis() - lastUpdate > updateInterval) {
sendToThingSpeak(temp, ecgValue, pressure, bpm, spo2);
lastUpdate = millis();
}
delay(100);
}
void sendToThingSpeak(float temp, int ecg, float pressure, float bpm, float spo2) {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
String url = String(THINGSPEAK_URL) + "?api_key=" + THINGSPEAK_API_KEY +
"&field1=" + String(temp) +
"&field2=" + String(ecg) +
"&field3=" + String(pressure) +
"&field4=" + String(bpm) +
"&field5=" + String(spo2);
http.begin(url);
int httpCode = http.GET();
if (httpCode > 0) {
Serial.println("Data sent to ThingSpeak.");
} else {
Serial.println("Error sending data.");
}
http.end();
} else {
Serial.println("WiFi not connected!");
}
}
#include <WiFi.h>
#include <HTTPClient.h>
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#define WIFI_SSID "your_SSID" // Replace with your WiFi SSID
#define WIFI_PASS "your_PASSWORD" // Replace with your WiFi Password
#define THINGSPEAK_API_KEY "X00DXNM88P2B6P2Q
" // Replace with your ThingSpeak API Key
#define THINGSPEAK_URL "http://api.thingspeak.com/update"
#define ECG_PIN 35 // AD8232 ECG Sensor (Analog)
#define LM35_PIN 34 // LM35 Temperature Sensor (Analog)
#define PRESSURE_PIN 32 // MPX5050 Pressure Sensor (Analog)
PulseOximeter pox;
float bpm = 0.0, spo2 = 0.0;
unsigned long lastUpdate = 0;
const int updateInterval = 15000; // Send data every 15 seconds
void onBeatDetected() {
Serial.println("Beat Detected!");
}
void setup() {
Serial.begin(115200);
// Connect to WiFi
WiFi.begin(WIFI_SSID, WIFI_PASS);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("\nConnected to WiFi");
// Initialize MAX30100
if (!pox.begin()) {
Serial.println("MAX30100 initialization failed!");
} else {
Serial.println("MAX30100 initialized.");
pox.setOnBeatDetectedCallback(onBeatDetected);
}
}
void loop() {
pox.update();
// Read ECG Signal
int ecgValue = analogRead(ECG_PIN);
// Read LM35 Temperature Sensor
float temp = analogRead(LM35_PIN) * (3.3 / 4095.0) * 100.0;
// Read MPX5050 Pressure Sensor
float pressure = (analogRead(PRESSURE_PIN) * (3.3 / 4095.0)) * 50.0;
// Read MAX30100 Data
bpm = pox.getHeartRate();
spo2 = pox.getSpO2();
Serial.println("---- Sensor Readings ----");
Serial.print("ECG: "); Serial.println(ecgValue);
Serial.print("Body Temperature: "); Serial.print(temp); Serial.println(" °C");
Serial.print("Oxygen Level: "); Serial.print(bpm); Serial.println(" BPM");
Serial.print("Blood Pressure: "); Serial.print(pressure); Serial.println("
kPa");
Serial.print("SpO2: "); Serial.print(spo2); Serial.println(" %");
// Send data to ThingSpeak every 15 seconds
if (millis() - lastUpdate > updateInterval) {
sendToThingSpeak(ecgValue, temp, bpm, pressure, spo2);
lastUpdate = millis();
}
delay(100);
}
void sendToThingSpeak(int ecg, float temp, float bpm, float pressure, float spo2) {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
String url = String(THINGSPEAK_URL) + "?api_key=" + THINGSPEAK_API_KEY +
"&field1=" + String(ecg) + // ECG
"&field2=" + String(temp) + // Body Temperature
"&field3=" + String(bpm) + // Oxygen Level
"&field4=" + String(pressure) + // Blood Pressure
"&field5=" + String(spo2); // SpO2
http.begin(url);
int httpCode = http.GET();
if (httpCode > 0) {
Serial.println("Data sent to ThingSpeak.");
} else {
Serial.println("Error sending data.");
}
http.end();
} else {
Serial.println("WiFi not connected!");
}
}