How to write coding for buzzer with oximeter sensor + temperature

Hi All,

Can someone guide and help to adjust my coding. Actually i doing a project to detect heart rate,spo2 and temperature. My problem is how i can use “BUZZER TO ALERT MY DATA”.
-WHEN TEMPERATURE MORE THAN 38 AND BELOW THAN 37 THE BUZZER WILL ALERT WITH SOUND
-WHEN SPO2 READING LESS THAN 98 BUZZER WILL ALERT WITH SOUND
-WHEN HEART RATE READING MORE THAN 140 AND LESS THAN 80 BUZZER WILL ALERT WITH SOUND

Please help me where is the correct codding to add at below data:

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

for (;;);

Please use code tags.

code tag? sorry cant understnd

usherul:
code tag? sorry cant understnd

See read this before posting a programming question

hi friend i still cant find solution how to use buzzer sensor. I dont know how to write the coding for buzzer. pls help me

You help us first by adding the code tags that you have already been asked for.

Then if you’re printing the right values for temp,heart rate and oxygen you just need to add a few if statements and the code you need to make a sound with whatever buzzer you are using. We can’t know what that is because you’ve told us nothing about your buzzer, how it is powered or where it is connected. And then there’s what sound it is supposed to make and how long for.

Steve

Ok let me explain…

  1. Here is combination coding for max30100 + lm35 (already solve)

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

int Buzz = A2; // hydz buzzer

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

pinMode(Buzz,OUTPUT); // buzzer

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

if (val<35) // buzzer
{digitalWrite(Buzz,HIGH);}
else
{digitalWrite (Buzz,LOW);}

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

  1. Here is buzzer HYDZ coding to alert the data for temperature if the value temperature<35

int Buzz=A2;

void setup()
{
pinMode(Buzz,OUTPUT);
}

void loop()
{
if (val<30)
{digitalWrite(Buzz,HIGH);}
else
{digitalWrite (Buzz,LOW);}
}

*I already combine buzzer coding with the first coding but the problem is sound from buzzer keep continue and cant detect the temperature if more than 30. izit i put the coding at the right place?

usherul:
Serial.println(“FAILED”);
for (;;);

Yes indeed, failed.

  1. Here is combination coding for max30100 + lm35 (already solve)

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

int Buzz = A2; // hydz buzzer

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

pinMode(Buzz,OUTPUT); // buzzer

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

if (val<35) // buzzer
{digitalWrite(Buzz,HIGH);}
else
{digitalWrite (Buzz,LOW);}

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

  1. Here is buzzer HYDZ coding to alert the data for temperature if the value temperature<35

int Buzz=A2;

void setup()
{
pinMode(Buzz,OUTPUT);
}

void loop()
{
if (val<30)
{digitalWrite(Buzz,HIGH);}
else
{digitalWrite (Buzz,LOW);}
}

*I already combine buzzer coding with the first coding but the problem is sound from buzzer keep continue and cant detect the temperature if more than 30. izit i put the coding at the right place

Oh great! You put in a space. Now go and read the instructions like you were asked to. UKHeliBob even gave you the direct link so it's only one click away.