Arduino code MAX30100 and DS18B20 doesn't work

hello guys, I'm working on a project that use MAX30100 pulse oximetry and DS18B20 Temperature sensor.
when I merged their codes together, MAX30100 doesn't work, but when I play each one they work probably. if anyone can help please.
this is the code while I'm a new user and can't upload it

#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#define REPORTING_PERIOD_MS 1000
// Define to which pin of the Arduino the output of the TMP36 is connected:

PulseOximeter pox;
uint32_t tsLastReport = 0;

void onBeatDetected()
{
Serial.println("Beat!");
}

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

float Celcius=0;
void setup()
{
Serial.begin(9600);
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");
}
 pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);

// Register a callback for the beat detection
pox.setOnBeatDetectedCallback(onBeatDetected);
  sensors.begin();

}

void loop()
{
// Make sure to call update as fast as possible

sensors.requestTemperatures();
Celcius=sensors.getTempCByIndex(0);

Serial.print(" C ");
Serial.println(Celcius);
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();
}

}

@ibrahimome, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with your project :wink: See About the Installation & Troubleshooting category.

Can you please read How to get the best out of this forum and apply what you read about code tags to the code in your post. Thanks.

Which MAX30100 library did you install? There are three under Library Manager:

MAX30100 by Connor Huffine
MAX30100_milan by OXullo Intersecans
MAX30100lib by OXullo Intersecans

which one is better?? i work on OXullo Library
but when I operate each sensor on his own they work, but when i combine the both sensors the MAX30100 Gives results (0) so it is only work without giving results

I have no reason to believe that any one library is better than the others. I just need to know which one you are using so I can try to help.

What does Serial Monitor say when you start your sketch?

i have tried them all, when i start the DS18B20 with MAX30100 serial monitor gives me a very good results for temperature, but!! the Heart Rate and SPo2 the results were zeros

sensors results

So it looks like you are getting temperature updates only twice a second. That means that something in your use of the temperature sensor is causing large delays. The pulse sensor can't see pulses if it only gets 2 samples per second.

Figure out how to avoid delays in the DS18B20 library. One option might be to read the temperature only once per minute.

ok i'll copy the whole code and kindly tell me what is the wrong.
there is no delays in the code!

#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#define REPORTING_PERIOD_MS 1000
// Define to which pin of the Arduino the output of the TMP36 is connected:

PulseOximeter pox;
uint32_t tsLastReport = 0;

void onBeatDetected()
{
Serial.println("Beat!");
}

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

float Celcius=0;
void setup()
{
Serial.begin(9600);
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");
}
 pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);

// Register a callback for the beat detection
pox.setOnBeatDetectedCallback(onBeatDetected);
  sensors.begin();

}

void loop()
{
// Make sure to call update as fast as possible

{
sensors.requestTemperatures();
Celcius=sensors.getTempCByIndex(0);

Serial.print(" C ");
Serial.println(Celcius);}
{ 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();
}}

}

By default, 'waitForConversion' is true. When you call 'requestTemperatures' you get a delay
while waiting for the conversions to complete.

void DallasTemperature::requestTemperatures() 
{
  _wire->reset();
  _wire->skip();
  _wire->write(STARTCONVO, parasite);

  // ASYNC mode?
  if (!waitForConversion)
    return;

  blockTillConversionComplete(bitResolution);
}

ok, please can you make me a favor and write the whole code in order to try it please?

I'm afraid that's not how it works on this forum. It's not a free code writing service. If you want someone to write your code for you, head to the Jobs and Paid Consultancy Forum and negotiate a mutually agreeable price.

Alternately, you can see the WaitForConversion and WaitForConversion2 examples that come with the DallasTemperature library. They demonstrate how to use it in a non-blocking manner.

Ok, thanks for your kind assistance.

Hi! Did you solve the problem? I have the same issue and I need to solve it rapidly :frowning:

Unfortunately not yet🙁 and now I'm facing another problem with SIM800L EvB it's getting hot when i connect it and didn't register on the network ever🙁 although the whole connection is correct

:slightly_frowning_face: If you solve the problem of the Values please notify me. I’ll also do the same if i solve it before you.

Ok deal

Ok. What I realised after looking for the issue is that both sensors work without the esp8266wifiserver. After I put the code for the WiFi server,I get the results only for one sensors. After many tryings,I realised that If I comment the requestTemperatures() function,the max30100 works and the ds18b20 sensors shows only one temperatures which doesn’t change.
I think that it s a problem at requestTemperatures() function from Dallas library.
void DallasTemperature::requestTemperatures()
{
_wire->reset();
_wire->skip();
_wire->write(STARTCONVO, parasite);

// ASYNC mode?
if (!waitForConversion)
return;

blockTillConversionComplete(bitResolution);
}

Can anyone help,please?

Turn off the WaitForConversion option and use a millis() timer to fetch the temperature and kick off a new conversion at intervals no faster than the sensor can complete a conversion.

As @gfvalvo said back in reply 13: