Measure Spo2 ,heart rate ,body temperature and motion

my project is measure heart rate and O2 saturation by using MAX 30100 , body temperature by MAAX30205 and body motion by using GY521 . All sensors are connected to same i2C bus. When I upload the code for individual sensor it work fine but when I upload the code that join them together MAX30100 turn on but it give me Zero reading the code below for MAX30100 alone and the results

#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;

// Callback routine is executed when a pulse is detected
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_27_1MA);

    // Register a callback routine
    pox.setOnBeatDetectedCallback(onBeatDetected);
}

void loop() {
    // 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("%");

        tsLastReport = millis();
    }
}

 ![1|491x217](upload://uzi8tRJWACpn1QI7Uz3soAHZdyP.png)

And the bellow code for all sensors

#include<Wire.h>
#include "Protocentral_MAX30205.h"
#include "MAX30100_PulseOximeter.h"
#define REPORTING_PERIOD_MS     1000




MAX30205 tempSensor;

const int MPU=0x68; 
 
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;

// Create a PulseOximeter object
PulseOximeter pox;
// Time at which the last beat occurred
uint32_t tsLastReport = 0;
// Callback routine is executed when a pulse is detected
void onBeatDetected() {
    Serial.println("Beat!");
}

void setup() {
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);  
  Wire.write(0);    
  Wire.endTransmission(true);
  Serial.begin(9600);
  tempSensor.begin();

  
  
   // set mode control register to active mod
 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_27_1MA);

  // Register a callback routine
    pox.setOnBeatDetectedCallback(onBeatDetected); 

  while(!tempSensor.scanAvailableSensors()){
    Serial.println("Couldn't find the temperature sensor, please connect the sensor." );
    delay(5000);// put your setup code here, to run once:
}

}
void loop() {
 
  pox.update();
 
 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();
    }
 
  Wire.beginTransmission(MPU);
  Wire.write(0x3B);  
  Wire.endTransmission(false);
  Wire.requestFrom(MPU,12,true);  
  AcX=Wire.read()<<8|Wire.read();    
  AcY=Wire.read()<<8|Wire.read();  
  AcZ=Wire.read()<<8|Wire.read();  
  GyX=Wire.read()<<8|Wire.read();  
  GyY=Wire.read()<<8|Wire.read();  
  GyZ=Wire.read()<<8|Wire.read();  
  
  Serial.print("Accelerometer: ");
  Serial.print("X = "); Serial.print(AcX);
  Serial.print(" | Y = "); Serial.print(AcY);
  Serial.print(" | Z = ");  Serial.println(AcZ); 
  
  Serial.print("Gyroscope: ");
  Serial.print("X  = "); Serial.print(GyX);
  Serial.print(" | Y = "); Serial.print(GyY);
  Serial.print(" | Z = "); Serial.println(GyZ);
  Serial.println(" ");
  delay(1000);
  
  float temp = tempSensor.getTemperature(); // read temperature for every 100ms
  Serial.print(temp ,2);
  Serial.println("'c" );
  delay(100);// put your main code here, to run repeatedly:

  
}

2

I am new on coding if you can help me solve this issue

Increase the baudrate to match at least triple output from 3 sensors.

;i made it Serial.begin(115200)
but i still get the same results

Does this work: connect the wires for all devices but run a test code only exercising one device. Does that work?

1 Like

yes, this way work but i want them to work together

Better use the non-blocking if(millis()...) code.

How can I use it? and where In the code ?
could you guide me because i am new on coding

Look at your code a few lines above.
Or have a look at the BlinkWithoutDelay in the IDE examples.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.