I made an Arduino temperature project ds18b20 + lcd i2c + pulse sensor + led, everything went smoothly except the pulse sensor. My pulse sensor is why the bpm can be above 200 bpm after installing ds18b20. Can you detect the error of my code?
#define USE_ARDUINO_INTERRUPTS true
#define ONE_WIRE_BUS 2
#include <DallasTemperature.h>
#include <PulseSensorPlayground.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const int PulseWire = 0;
const int LED12 = 12;
int PulseSensorPurplePin = 0;
int Signal;
int Threshold = 550;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
PulseSensorPlayground pulseSensor;
void setup() {
lcd.begin();
sensors.begin();
pulseSensor.analogInput(PulseWire);
pulseSensor.blinkOnPulse(LED12);
pulseSensor.setThreshold(Threshold);
Serial.begin(9600);
if (pulseSensor.begin()) {
lcd.setCursor(0,0);
lcd.print("GONIT SENSOR");
lcd.setCursor(0,1);
lcd.print("VERSION 1.0");
delay(3000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Suhu: 0");
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("BPM: 0");
}
}
void loop() {
int myBPM = pulseSensor.getBeatsPerMinute();
Signal = analogRead(PulseSensorPurplePin);
sensors.requestTemperatures();
lcd.setCursor(0,0);
lcd.print("Suhu: ");
lcd.print(sensors.getTempCByIndex(0));
lcd.print("C");
delay(500);
if (pulseSensor.sawStartOfBeat()) {
lcd.setCursor(0,1);
lcd.print("BPM: ");
lcd.setCursor(5,1);
lcd.print(myBPM);
Serial.println(myBPM);
}
if(myBPM > 0){
digitalWrite(LED12,HIGH);
} else {
digitalWrite(LED12,LOW);
}
delay(20);
}