#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize the LCD with the I2C address 0x27
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int heartRatePin = A0;
const int tempPin = A1;
const int bpPin = A2;
// Buzzer and LED pins
const int buzzerPin = 8;
const int ledPin = 9;
// NTC Thermistor configuration
const float BETA = 3950; // Beta coefficient of the thermistor
// Thresholds for alerts
const float TEMP_THRESHOLD = 30.0;
const int HEART_RATE_THRESHOLD = 95;
void setup() {
// Initialize the LCD
lcd.begin(16, 2);
lcd.print("Health Monitor");
// Initialize serial communication
Serial.begin(9600);
// Set up the pins
pinMode(heartRatePin, INPUT);
pinMode(tempPin, INPUT);
pinMode(bpPin, INPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
// Read values from the sensors
int heartRateValue = analogRead(heartRatePin);
int tempValue = analogRead(tempPin);
int bpValue = analogRead(bpPin);
// Convert heart rate sensor reading to meaningful value
int heartRate = map(heartRateValue, 0, 1023, 60, 100);
// Calculate temperature from the NTC thermistor
float celsius = 1 / (log(1 / (1023.0 / tempValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
// Convert blood pressure sensor reading to meaningful value
int bloodPressure = map(bpValue, 0, 1023, 80, 120);
// Check if the readings exceed thresholds and activate alerts
bool alert = false;
if (celsius > TEMP_THRESHOLD || heartRate > HEART_RATE_THRESHOLD) {
alert = true;
}
if (alert) {
tone(8, 262, 250);
digitalWrite(buzzerPin, HIGH);
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(buzzerPin, LOW);
digitalWrite(ledPin, LOW);
}
// Print values to serial monitor
Serial.print("Heart Rate: ");
Serial.print(heartRate);
Serial.print(" BPM, Temperature: ");
Serial.print(celsius);
Serial.print(" C, Blood Pressure: ");
Serial.print(bloodPressure);
Serial.println(" mmHg");
// Display values on the LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("HR:");
lcd.print(heartRate);
lcd.print(" BPM");
lcd.setCursor(0, 1);
lcd.print("Temp:");
lcd.print(celsius);
lcd.print("C BP:");
lcd.print(bloodPressure);
lcd.print("mmHg");
delay(1000); // Update every second
}