Untitled
unknown
plain_text
2 years ago
3.2 kB
7
Indexable
#include <LiquidCrystal.h>
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include "DHT.h"
LiquidCrystal lcd(19,23,18,17,16,15);
#define DHTPIN 25 // Pin where the DHT11 is connected to the ESP32 (change this to your pin number)
#define DHTTYPE DHT11 // Type of the DHT sensor used
DHT dht(DHTPIN, DHTTYPE);
#define REPORTING_PERIOD_MS 1000
// PulseOximeter is the higher level interface to the sensor
// it offers:
// * beat detection reporting
// * heart rate calculation
// * SpO2 (oxidation level) calculation
PulseOximeter pox;
uint32_t tsLastReport = 0;
// Callback (registered below) fired when a pulse is detected
void onBeatDetected()
{
Serial.println("Beat!");
}
void setup()
{
Serial.begin(115200);
Serial.print("Initializing pulse oximeter..");
lcd.begin(20,4);
lcd.clear();
dht.begin();
// Initialize the PulseOximeter instance
// Failures are generally due to an improper I2C wiring, missing power supply
// or wrong target chip
if (!pox.begin()) {
Serial.println("FAILED");
for(;;);
} else {
Serial.println("SUCCESS");
}
// The default current for the IR LED is 50mA and it could be changed
// by uncommenting the following line. Check MAX30100_Registers.h for all the
// available options.
// pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
// Register a callback for the beat detection
pox.setOnBeatDetectedCallback(onBeatDetected);
}
void loop()
{
// Make sure to call update as fast as possible
pox.update();
// Asynchronously dump heart rate and oxidation levels to the serial
// For both, a value of 0 means "invalid"
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
Serial.print("Heart rate:");
Serial.print(pox.getHeartRate());
Serial.print("bpm / SpO2:");
Serial.print(pox.getSpO2());
Serial.println("%");
tsLastReport = millis();
}
//delay(2000); // Delay between sensor readings
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t Temperature: ");
Serial.print(temperature);
Serial.println(" *C");
//lcd.clear();
lcd.setCursor(0,0); //column,row)
lcd.print("Place finger firmly");
lcd.setCursor(0,1);
lcd.print("Heart rate:");
lcd.setCursor(12,1);
lcd.print (pox.getHeartRate());
lcd.setCursor(16,1);
lcd.print("BPM");
lcd.setCursor(0,2);
lcd.print("SP02:");
lcd.setCursor(6,2);
lcd.print (pox.getSpO2());
lcd.setCursor(8,2);
lcd.print("%");
lcd.setCursor(0,3); // Temp and Humidity sensor display
lcd.print("Hum:");
lcd.setCursor(5,3);
lcd.print(humidity);
lcd.setCursor(9,3);
lcd.print("Temp:");
lcd.setCursor(15,3);
lcd.print(temperature);
}Editor is loading...
Leave a Comment