How to combine arduino code for max30100 with LM35

Hi all,

Can someone help me how to combine 2 coding for max30100 with LM35. I already try but when upload only temperature sensor function.

For max30100 coding,

#include <Wire.h>
#include “MAX30100_PulseOximeter.h”

#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…”);

// 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();
}
}

For temperature coding (LM35),

int val;
int tempPin = 1;

void setup()
{
Serial.begin(9600);
}
void loop()
{
val = analogRead(tempPin);
float mv = ( val/1024.0)5000;
float cel = mv/10;
float farh = (cel
9)/5 + 32;

Serial.print(“TEMPRATURE = “);
Serial.print(cel);
Serial.print(”*C”);
Serial.println();
delay(1000);

/* uncomment this to get temperature in farenhite
Serial.print(“TEMPRATURE = “);
Serial.print(farh);
Serial.print(”*F”);
Serial.println();

*/
}

Is what this what you tried?

#include <Wire.h>
#include "MAX30100_PulseOximeter.h"

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

uint8_t tempPin = 1;   //<---------This is the PIN the LM53 is connected! CHANGE accordingly
uint16_t val;
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..");

  // 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()
{
  analogRead(tempPin);
  val = analogRead(tempPin);
  float mv = ( val / 1024.0) * 5000;
  float cel = mv / 10;

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

    Serial.print("TEMPRATURE = ");
    Serial.print(cel);
    Serial.print("*C");
    Serial.println();

    /* uncomment this to get temperature in farenhite
      float farh = (cel*9)/5 + 32;
      Serial.print("TEMPRATURE = ");
      Serial.print(farh);
      Serial.print("*F");
      Serial.println();
    */
    
    tsLastReport = millis();
  }
}

the care point here is the variable “tempPin”. Change its value to the actual pin the LM35 is connected on your board.

Hope that helps.

tq so much for your help.. it works.. :-)..