#include <Wire.h>
#include <I2Cdev.h>
#include <MPU6050.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
// Pedometer variables
MPU6050 accelgyro;
int16_t ax, ay, az;
unsigned long lastStepTime = 0;
unsigned long stepInterval = 300; // Time in milliseconds between steps
int stepCount = 0;
// Temperature sensor variables
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// Pulse sensor variables
#define PULSE_SENSOR_PIN A0
int pulseSensorValue;
int previousPulseSensorValue = 0; // Initialize previous value to 0
int heartRate = 0;
unsigned long lastPulseSensorTime = 0;
unsigned long pulseSensorInterval = 1000; // Time in milliseconds between pulse sensor readings
// LED pins
#define LED_FEVER 3
#define LED_STEP_COUNT 4
#define LED_HEART_RATE 5
// LCD pins
#define LCD_RS 7
#define LCD_EN 8
#define LCD_D4 9
#define LCD_D5 10
#define LCD_D6 11
#define LCD_D7 12
LiquidCrystal lcd(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
void setup() {
Wire.begin();
accelgyro.initialize();
sensors.begin(); // Start the temperature sensor library
pinMode(LED_FEVER, OUTPUT);
pinMode(LED_STEP_COUNT, OUTPUT);
pinMode(LED_HEART_RATE, OUTPUT);
lcd.begin(16, 2); // Initialize the LCD (16 columns, 2 rows)
}
void loop() {
// Pedometer code
accelgyro.getAcceleration(&ax, &ay, &az);
if (abs(ax) > 1000 && millis() - lastStepTime > stepInterval) {
stepCount++;
lastStepTime = millis();
digitalWrite(LED_STEP_COUNT, HIGH); // Turn on step count LED
delay(1000); // Keep LED on for 1 second
digitalWrite(LED_STEP_COUNT, LOW); // Turn off step count LED
}
// Temperature sensor code
sensors.requestTemperatures();
float tempC = sensors.getTempCByIndex(0);
if (tempC > 39.5) { // If temperature is above 39.5°C, turn on fever LED
digitalWrite(LED_FEVER, HIGH);
} else {
digitalWrite(LED_FEVER, LOW);
}
// Pulse sensor code
if (millis() - lastPulseSensorTime > pulseSensorInterval) {
pulseSensorValue = analogRead(PULSE_SENSOR_PIN);
if (pulseSensorValue != previousPulseSensorValue) {
// Check if the pulse sensor value is within a reasonable range
if (pulseSensorValue > 100 && pulseSensorValue < 900) {
heartRate = map(pulseSensorValue, 100, 900, 30, 220); // Map sensor value to heart rate
if (heartRate > 100) { // If heart rate is above 100 bpm, turn on heart rate LED
digitalWrite(LED_HEART_RATE, HIGH);
} else {
digitalWrite(LED_HEART_RATE, LOW);
}
}
}
previousPulseSensorValue = pulseSensorValue;
lastPulseSensorTime = millis();
}
// Update LCD display
lcd.clear(); // Clear the LCD display
lcd.setCursor(0, 0); // Set the cursor to the first column of the first row
lcd.print("Steps: ");
lcd.print(stepCount);
lcd.print(" HR: ");
lcd.print(heartRate);
lcd.setCursor(0, 1); // Set the cursor to the first column of the second row
lcd.print("Temp: ");
lcd.print(tempC);
lcd.print(" C");
if (tempC > 39.5) {
lcd.print(" FEVER");
} else {
lcd.print(" ");
}
delay(100); // Adjust this delay as needed
}