I'm doing a project using Arduino Uno, LM35 temperature sensor, and a pulse sensor to read the temperature and the BPM and display them on the LCD and serial monitor. First, I wrote the code for each sensor separately and there was no error and the reading looks correct and reliable. However, when I tried to combine the two codes, it doesn't show any errors but the reading looks not correct (like jumping, sometimes too high and sometimes low). So can you please help me. The code is attached below. Thanks in advance.
<pre>#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
float temp ;
int myBPM;
#define USE_ARDUINO_INTERRUPTS true // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h>
const int PulseWire = A0;
const int LED7 = 7;
int Threshold = 550;
PulseSensorPlayground pulseSensor;
void setup()
{
lcd.begin(16, 2);
Serial.begin(115200);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Patient Health");
lcd.setCursor(0,1);
lcd.print(" Monitoring ");
delay(4000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Initializing....");
delay(5000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Getting Data....");
pulseSensor.analogInput(PulseWire);
pulseSensor.blinkOnPulse(LED7);
pulseSensor.setThreshold(Threshold);
}
void loop()
{
pulse();
read_temp();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("BPM :");
lcd.setCursor(7,0);
lcd.print(myBPM);
}
void pulse(){
if (pulseSensor.begin()) {
Serial.println("We created a pulseSensor Object !");
lcd.setCursor(0,0);
lcd.print(" Heart Rate ");
lcd.setCursor(0,1);
lcd.print("Monitor");
int myBPM = pulseSensor.getBeatsPerMinute();
if (pulseSensor.sawStartOfBeat()) {
Serial.println("♥ A HeartBeat Happened ! ");
Serial.print("BPM: ");
Serial.println(myBPM);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("BPM: ");
lcd.print(myBPM);
}
delay(500);
}}
void read_temp()
{
int temp_val = analogRead(A5);
float mv = ((temp_val+0.5)/1024.0)*5000;
float cel = mv/10;
temp=cel;
Serial.print("Temperature:");
Serial.print(temp);
Serial.print("\xC2\xB0");
Serial.println("C");
lcd.setCursor(0,1);
lcd.print("Temp.:");
lcd.setCursor(7,1);
lcd.print(temp);
lcd.setCursor(13,1);
lcd.print((char)223);
lcd.print("C");
delay(500);
}
What I have tried:
I want to read two sensors values (LM35 temp sensor and pulse sensor) and display them on an LCD and the serial monitor.