#include <LiquidCrystal.h>
// Initialize the LCD with the appropriate pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int sensorPin = A0; // Pulse Sensor connected to A0
int threshold = 550; // Adjust this value according to your sensor
int bpm = 0;
unsigned long lastBeat = 0;
void setup() {
lcd.begin(16, 2); // Set up the LCD's number of columns and rows
lcd.print("Heart Rate:"); // Display a message on the LCD
pinMode(sensorPin, INPUT);
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(sensorPin);
if (sensorValue > threshold) {
unsigned long currentTime = millis();
if (currentTime - lastBeat > 500) { // Minimum time between beats
bpm = 60000 / (currentTime - lastBeat); // Calculate BPM
lastBeat = currentTime; // Update last beat time after calculating BPM
lcd.setCursor(0, 1); // Move cursor to the second line
lcd.print("BPM: ");
lcd.print(bpm); // Display BPM on the LCD
}
}
delay(100); // Small delay to stabilize the readings
}