#include <LiquidCrystal.h>
// Initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int sensorPin = A0; // Pin connected to the sensor
void setup() {
// Set up the LCD's number of columns and rows
lcd.begin(16, 2);
// Print a message to the LCD
lcd.print("Heartbeat Sensor");
// Initialize serial communication for debugging purposes
Serial.begin(9600);
}
void loop() {
// Read the input on analog pin 0 (value between 0 and 1023)
int sensorValue = analogRead(sensorPin);
// Convert the analog reading (0 to 1023) to a voltage (0 to 5V)
float voltage = sensorValue * (5.0 / 1023.0);
// Convert the voltage to a heartbeat value
int heartbeat = map(sensorValue, 0, 1023, 0, 150); // Adjust based on your sensor's characteristics
// Print the voltage and heartbeat to the Serial Monitor for debugging
Serial.print("Sensor Value: ");
Serial.print(sensorValue);
Serial.print(" Voltage: ");
Serial.print(voltage);
Serial.print(" V Heartbeat: ");
Serial.print(heartbeat);
Serial.println(" bpm");
// Set the cursor to column 0, line 1
lcd.setCursor(0, 1);
// Print the heartbeat value to the LCD
lcd.print("Heartbeat: ");
lcd.print(heartbeat);
lcd.print(" bpm ");
// Wait for a while before repeating the loop
delay(1000); // Update every second
}