#include <Wire.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Pin Definitions
#define DS18B20_PIN 4
#define SOS_BUTTON 15
#define BUZZER 5
#define POTENTIOMETER A0 // Simulating MAX30102
// Sensor Objects
OneWire oneWire(DS18B20_PIN);
DallasTemperature tempSensor(&oneWire);
Adafruit_MPU6050 mpu;
void setup() {
Serial.begin(115200);
pinMode(SOS_BUTTON, INPUT_PULLUP); // Changed to PULLUP for stability
pinMode(BUZZER, OUTPUT);
pinMode(POTENTIOMETER, INPUT);
// Initialize DS18B20
tempSensor.begin();
// Initialize MPU6050
if (!mpu.begin()) {
Serial.println("MPU6050 not detected!");
while (1);
}
Serial.println("MPU6050 initialized.");
}
void loop() {
// Read simulated heart rate (Potentiometer value as MAX30102 substitute)
int heartRate = map(analogRead(POTENTIOMETER), 0, 4095, 50, 180); // Scale to BPM range
Serial.print("Heart Rate: ");
Serial.print(heartRate);
Serial.println(" BPM");
// Read temperature
tempSensor.requestTemperatures();
float temperature = tempSensor.getTempCByIndex(0);
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
// Read accelerometer data for fall detection
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
float acceleration = sqrt(a.acceleration.x * a.acceleration.x +
a.acceleration.y * a.acceleration.y +
a.acceleration.z * a.acceleration.z);
Serial.print("Acceleration: ");
Serial.println(acceleration);
// Fall Detection
if (acceleration < 3.0) { // Adjust threshold as needed
Serial.println("🚨 Fall Detected!");
triggerBuzzer(500);
}
// Check SOS button
if (digitalRead(SOS_BUTTON) == LOW) { // LOW means pressed (due to PULLUP)
Serial.println("🚨 SOS Alert Triggered!");
triggerBuzzer(1000);
}
Serial.println("----------------------");
delay(1000); // Wait 1 second before next reading
}
// Function to trigger buzzer
void triggerBuzzer(int duration) {
digitalWrite(BUZZER, HIGH);
delay(duration);
digitalWrite(BUZZER, LOW);
}
Loading
ds18b20
ds18b20