0% found this document useful (0 votes)
227 views2 pages

Max 30100 Final

This code configures an ESP8266 microcontroller to connect to WiFi and read pulse oximeter sensor data using a MAX30100 pulse oximeter sensor. It retrieves the heart rate and SpO2 levels from the sensor and sends the data to a ThingSpeak channel every 5 seconds. The pulse oximeter is initialized, heartbeat detection callbacks are registered, and the sensor data is continuously updated and printed to the serial monitor.

Uploaded by

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

Max 30100 Final

This code configures an ESP8266 microcontroller to connect to WiFi and read pulse oximeter sensor data using a MAX30100 pulse oximeter sensor. It retrieves the heart rate and SpO2 levels from the sensor and sends the data to a ThingSpeak channel every 5 seconds. The pulse oximeter is initialized, heartbeat detection callbacks are registered, and the sensor data is continuously updated and printed to the serial monitor.

Uploaded by

s.r.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <ThingSpeak.

h>
#include <ESP8266WiFi.h> // Include ESP8266 library
#include <ESP8266WebServer.h>
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#define REPORTING_PERIOD_MS 1000
const char* ssid = "xxxxxxxxxx";
const char* password = "xxxxxxxxxx";
WiFiClient client;
unsigned long myChannelNumber = xxxxxx;
const char * myWriteAPIKey = "xxxxxxxxxxxxxx";
uint8_t aq=0;
PulseOximeter pox;
uint32_t tsLastReport = 0;
void onBeatDetected()
{
Serial.println("Beat!");
}

void setup()
{
Serial.begin(115200);
pox.begin();

Serial.print("Initializing pulse oximeter..");

// 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);
delay(10);
// connect to wifi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Print the IP address
Serial.println(WiFi.localIP());
ThingSpeak.begin(client);
}
void loop()
{
static boolean data_state = false;
// 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();
}
// Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to
store up to 8 different
// pieces of information in a channel. Here, we write to field 1.
if( data_state )
{
ThingSpeak.writeField(myChannelNumber, 4, aq, myWriteAPIKey);
data_state = false;
}
else
{
data_state = true;
}
delay(5000); // ThingSpeak will only accept updates every 5 seconds.
}

You might also like