#include <Wire.h>
#include <MPU6050.h>
#include <HX711.h>
MPU6050 mpu;
HX711 scale;
const int ledPin = 13;
const int buzzerPin = 9;
const int buttonPin = 6;
bool buttonPressed = false;
void setup() {
Serial.begin(9600);
mpu.initialize();
scale.begin(A2, A3);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
// Read accelerometer data
int16_t ax, ay, az;
mpu.getAcceleration(&ax, &ay, &az);
// Read load cell data
float weight = scale.get_units();
// Check for fall condition
if (az < -8000 && weight < 10.0) { // Replace 10.0 with your threshold weight
// Fall detected
digitalWrite(ledPin, HIGH);
tone(buzzerPin, 1000); // Activate buzzer
delay(1000); // Buzzer on for 1 second
noTone(buzzerPin); // Turn off buzzer
digitalWrite(ledPin, LOW);
// Add any other necessary actions
}
// Check if the pushbutton is pressed
if (digitalRead(buttonPin) == LOW) {
if (!buttonPressed) {
// Perform actions when the button is pressed (e.g., reset, acknowledge)
// Add your button-triggered actions here
buttonPressed = true;
}
} else {
buttonPressed = false;
}
delay(1000); // Adjust delay as needed
}