#define BLYNK_TEMPLATE_ID "TMPL3RJudAt8S"
#define BLYNK_TEMPLATE_NAME "cattle monitoring system"
#define BLYNK_AUTH_TOKEN "Your Auth Token"
#include <DHT.h>
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <BlynkSimpleEsp32.h>
#define REPORTING_PERIOD_MS 1000
#define DHTPIN 4
#define DHTTYPE DHT22
#define AO_PIN 34
#define A1_PIN 35
Adafruit_MPU6050 mpu;
DHT dht(DHTPIN, DHTTYPE);
PulseOximeter pox;
uint32_t tsLastReport = 0;
void onBeatDetected() {
Serial.println("Beat!");
}
void setup() {
Serial.begin(9600);
Blynk.begin(BLYNK_AUTH_TOKEN, "Your_SSID", "Your_Password"); // Replace with your Wi-Fi credentials
Serial.println(F("DHT test!"));
dht.begin();
Serial.println("Warming up the MQ2 sensor");
delay(2000);
Serial.println("Warming up the vibration sensor");
delay(2000);
Serial.print("Initializing pulse oximeter..");
if (pox.begin()) {
Serial.println("FAILED");
for (;;)
;
} else {
Serial.println("SUCCESS");
}
pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
pox.setOnBeatDetectedCallback(onBeatDetected);
Serial.begin(115200);
while (!Serial)
delay(10);
Serial.println("Adafruit MPU6050 test!");
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
Serial.println("MPU6050 Found!");
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
// ... (rest of the setup remains the same)
// Manually set the Blynk template properties
Blynk.setProperty(BLYNK_TEMPLATE_ID, "label", "DHT_Humidity", "Humidity");
Blynk.setProperty(BLYNK_TEMPLATE_ID, "label", "DHT_Temperature", "Temperature");
Blynk.setProperty(BLYNK_TEMPLATE_ID, "label", "DHT_HeatIndex", "Heat Index");
Blynk.setProperty(BLYNK_TEMPLATE_ID, "label", "PulseOx_HeartRate", "Heart Rate");
Blynk.setProperty(BLYNK_TEMPLATE_ID, "label", "PulseOx_SpO2", "SpO2");
}
void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
float hif = dht.computeHeatIndex(f, h);
float hic = dht.computeHeatIndex(t, h, false);
Serial.print(h);
Serial.print(",");
Serial.print(t);
Serial.print(",");
Serial.print(f);
Serial.print(",");
Serial.print(hic);
Serial.print(",");
Serial.print(hif);
pox.update();
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
Blynk.virtualWrite(BLYNK_TEMPLATE_ID, "DHT_Humidity", h);
Blynk.virtualWrite(BLYNK_TEMPLATE_ID, "DHT_Temperature", t);
Blynk.virtualWrite(BLYNK_TEMPLATE_ID, "DHT_HeatIndex", hic);
Blynk.virtualWrite(BLYNK_TEMPLATE_ID, "PulseOx_HeartRate", pox.getHeartRate());
Blynk.virtualWrite(BLYNK_TEMPLATE_ID, "PulseOx_SpO2", pox.getSpO2());
tsLastReport = millis();
}
int gasValue = analogRead(AO_PIN);
int vibvalue = analogRead(A1_PIN);
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
Serial.print(",");
Serial.print(gasValue);
Serial.print(",");
Serial.print(vibvalue);
Serial.print(",");
Serial.print(a.acceleration.x);
Serial.print(",");
Serial.print(a.acceleration.y);
Serial.print(",");
Serial.print(a.acceleration.z);
Serial.print(",");
Serial.print(g.gyro.x);
Serial.print(",");
Serial.print(g.gyro.y);
Serial.print(",");
Serial.print(g.gyro.z);
Serial.print(",");
Serial.print(temp.temperature);
Serial.println("");
delay(500);
Blynk.run();
}