#include <LiquidCrystal.h> // include the LCD library
LiquidCrystal lcd(12, 11, 10, 9, 8, 7); // set up the LCD pins
int hrPin = A0; // set up the heart rate sensor pin
int redPin = 4; // set up the red LED pin
int greenPin = 5; // set up the green LED pin
int hrValue = 0; // variable to store the heart rate value
void setup() {
pinMode(redPin, OUTPUT); // set the red LED pin as an output
pinMode(greenPin, OUTPUT); // set the green LED pin as an output
lcd.begin(16, 2); // initialize the LCD
}
void loop() {
hrValue = analogRead(hrPin); // read the heart rate sensor value
int bpm = map(hrValue, 0, 1023, 0, 255); // map the heart rate value to BPM
lcd.clear();
lcd.print("Heart Rate:"); // print the initial message on the LCD
if (bpm > 100) { // if heart rate is high
digitalWrite(redPin, HIGH); // turn on the red LED
digitalWrite(greenPin, LOW); // turn off the green LED
lcd.setCursor(0, 1); // set the LCD cursor to the second line
lcd.print("HIGH"); // print "HIGH" on the LCD
} else if (bpm < 60) { // if heart rate is low
digitalWrite(redPin, LOW); // turn off the red LED
digitalWrite(greenPin, HIGH); // turn on the green LED
lcd.setCursor(0, 1); // set the LCD cursor to the second line
lcd.print("LOW"); // print "LOW" on the LCD
} else { // if heart rate is normal
digitalWrite(redPin, LOW); // turn off the red LED
digitalWrite(greenPin, HIGH); // turn on the green LED
lcd.setCursor(0, 1); // set the LCD cursor to the second line
lcd.print("NORMAL"); // print "NORMAL" on the LCD
}
delay(1000); // wait for 1 second before taking another reading
}