I’m using MAX30100 sensor with XIAO ESP32 C3 board. the sensor works fine with the board offline (without blynk code). But transmitting the data to blynk shows no result.
I’ve attached the serial output.
here’s the code:
ps: I’ve tried making separate functions for the sensor and timer but it doesn’t work.
/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "TMPLlZN8S84U"
#define BLYNK_DEVICE_NAME "inhaler"
#define BLYNK_AUTH_TOKEN "DzVKgZ3LDDrwqczSf0zE-JX9G6XZSSer"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32_SSL.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "vivo 1713";
char pass[] = "ablgaozra";
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#define REPORTING_PERIOD_MS 1000
// Create a PulseOximeter object
PulseOximeter pox;
// Time at which the last beat occurred
uint32_t tsLastReport = 0;
/****************max30102**********************/
void onBeatDetected() {
Serial.println("Beat!");
}
void setup()
{ Serial.begin(9600);
Serial.print("Initializing pulse oximeter..");
// Initialize sensor
if (!pox.begin()) {
Serial.println("FAILED");
for (;;);
} else {
Serial.println("SUCCESS");
}
// Configure sensor to use 7.6mA for LED drive
pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
// Register a callback routine
pox.setOnBeatDetectedCallback(onBeatDetected);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}
void loop()
{
Blynk.run();
// Read from the sensor
pox.update();
// Grab the updated heart rate and SpO2 levels
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
Serial.print("Heart rate:");
Serial.print(pox.getHeartRate());
Serial.print("bpm / SpO2:");
Serial.print(pox.getSpO2());
Serial.println("%");
Blynk.virtualWrite(V1, pox.getSpO2());
Blynk.virtualWrite(V4, pox.getHeartRate());
tsLastReport = millis();
}
}

Please replace the screenshot of your serial monitor with the actual serial monitor text, copied and pasted between triple backticks in the same way that you post code.
It would be really helpful to see the entire serial monitor text from boot-up, not just the part that is shown in the screenshot.
I’d start by updating your Blynk library to the latest release.
Providing a link to the MAX30100 library you are using may also be helpful.
I’d suggest you post that code, as your current cluttered void loop isn’t Blynk friendly.
Pete.
here’s the library link
I’ve updated the blynk library.
here’s the updated code:
/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "TMPLlZN8S84U"
#define BLYNK_DEVICE_NAME "inhaler"
#define BLYNK_AUTH_TOKEN "DzVKgZ3LDDrwqczSf0zE-JX9G6XZSSer"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32_SSL.h>
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
BlynkTimer timer;
#define REPORTING_PERIOD_MS 1000
#define DHTPIN D1 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 11
// Create a PulseOximeter object
PulseOximeter pox;
// Time at which the last beat occurred
uint32_t tsLastReport = 0;
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS = 1000;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Mughals";
char pass[] = "mughals2343";
/****************temperature**********************/
void temp()
{
sensors_event_t event;
dht.temperature().getEvent(&event);
int temp = event.temperature;
if (isnan(temp)) {
Serial.println(F("Error reading temperature!"));
}
else {
Serial.print(F("Temperature: "));
Serial.print(temp);
Serial.println(F("°C"));
Blynk.virtualWrite(V2, temp);
}
// Get humidity event and print its value.
dht.humidity().getEvent(&event);
int hum = event.relative_humidity;
if (isnan(hum)) {
Serial.println(F("Error reading humidity!"));
}
else {
Serial.print(F("Humidity: "));
Serial.print(hum);
Serial.println(F("%"));
Blynk.virtualWrite(V3, hum);
}
}
/****************max30100**********************/
void onBeatDetected() {
Serial.println("Beat!");
}
void mx_ini()
{
if (!pox.begin()) {
Serial.println("FAILED");
for (;;);
} else {
Serial.println("SUCCESS");
}
// Configure sensor to use 7.6mA for LED drive
pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
// Register a callback routine
pox.setOnBeatDetectedCallback(onBeatDetected);
}
void mx()
{
pox.update();
// Grab the updated heart rate and SpO2 levels
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
Serial.print("Heart rate:");
Serial.print(pox.getHeartRate());
Serial.print("bpm / SpO2:");
Serial.print(pox.getSpO2());
Serial.println("%");
Blynk.virtualWrite(V1, pox.getHeartRate());
Blynk.virtualWrite(V4, pox.getSpO2());
tsLastReport = millis();
}
}
void setup()
{
Serial.begin(115200);
dht.begin();
mx_ini();
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(1000L, temp);
timer.setInterval(100L, mx);
}
void loop()
{
Blynk.run();
timer.run();
}
and here’s the serial monitor content:
ESP-ROM:esp32c3-api1-20210207
SUCCESS
[170] Connecting to Mughals
[2707] Connected to WiFi
[2707] IP: 192.168.10.12
[2707]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v1.2.0 on ESP32
#StandWithUkraine 71%
Heart rate:0.00bpm / SpO2:0%
Temperature: 34°C
Humidity: 71%
Temperature: 34°C
Humidity: 71%
Heart rate:0.00bpm / SpO2:0%
Temperature: 34°C
Humidity: 71%
Heart rate:0.00bpm / SpO2:0%
Temperature: 34°C
Humidity: 71%
you could try moving the pox.update()
to the loop. Although, it may (or may not) make for an unstable connection with BLYNK. I would also get rid of the millis()
stuff as it should not be needed since you are using timers. Try this:
/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "TMPLlZN8S84U"
#define BLYNK_DEVICE_NAME "inhaler"
#define BLYNK_AUTH_TOKEN "DzVKgZ3LDDrwqczSf0zE-JX9G6XZSSer"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32_SSL.h>
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
BlynkTimer timer;
#define REPORTING_PERIOD_MS 1000
#define DHTPIN D1 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 11
// Create a PulseOximeter object
PulseOximeter pox;
// Time at which the last beat occurred
uint32_t tsLastReport = 0;
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS = 1000;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Mughals";
char pass[] = "mughals2343";
/****************temperature**********************/
void temp()
{
sensors_event_t event;
dht.temperature().getEvent(&event);
int temp = event.temperature;
if (isnan(temp)) {
Serial.println(F("Error reading temperature!"));
}
else {
Serial.print(F("Temperature: "));
Serial.print(temp);
Serial.println(F("°C"));
Blynk.virtualWrite(V2, temp);
}
// Get humidity event and print its value.
dht.humidity().getEvent(&event);
int hum = event.relative_humidity;
if (isnan(hum)) {
Serial.println(F("Error reading humidity!"));
}
else {
Serial.print(F("Humidity: "));
Serial.print(hum);
Serial.println(F("%"));
Blynk.virtualWrite(V3, hum);
}
}
/****************max30100**********************/
void onBeatDetected() {
Serial.println("Beat!");
}
void mx_ini()
{
if (!pox.begin()) {
Serial.println("FAILED");
for (;;);
} else {
Serial.println("SUCCESS");
}
// Configure sensor to use 7.6mA for LED drive
pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
// Register a callback routine
pox.setOnBeatDetectedCallback(onBeatDetected);
}
void mx()
{
int HR = pox.getHeartRate();
int Oxy = pox.getSpO2();
Serial.print("Heart rate:");
Serial.print(HR);
Serial.print("bpm / SpO2:");
Serial.print(Oxy);
Serial.println("%");
Blynk.virtualWrite(V1, HR);
Blynk.virtualWrite(V4, Oxy);
}
void setup()
{
Serial.begin(115200);
dht.begin();
mx_ini();
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(1000L, temp);
delay(100); //stagger timers
timer.setInterval(1000L, mx);
}
void loop()
{
Blynk.run();
pox.update();
timer.run();
}
There’s nothing wrong with the connection with blynk overall. The temp sensor works fine.
Understood. What I was saying is that adding things to the void loop()
could possibly cause connection issues.
The examples for that sensor (max301000) say that the pox.update()
should be ran as fast as possible, thus the suggestion to add it to the void loop()
.
I do not have this sensor so I have no way of testing if 1) this corrects the issue and 2) if it causes connection/stability issues with BLYNK.
1 Like
I’ve implemented your suggestion and it worked. Thanks. could you explain what was the issue?
As mentioned the example says this needs to be ran as fast as possible. Not sure why. Might have to due with timing within the sensor, or catching the signal that is triggered when it detects a heartbeat.
You may want to run this program for a bit to confirm its connection is stable.
Otherwise glad it worked.