#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu1, mpu2, mpu3;
unsigned long lastMovementTime = 0; // Variable to store the time of the last movement
void setup() {
Serial.begin(9600);
// Initialize the MPU6050 sensors
Wire.begin();
mpu1.initialize();
mpu2.initialize();
mpu3.initialize();
// Verify connections
Serial.println((mpu1.testConnection() && mpu2.testConnection() && mpu3.testConnection()) ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));
// Set the sensor sensitivity (adjust if necessary)
mpu1.setFullScaleGyroRange(MPU6050_GYRO_FS_250);
mpu1.setFullScaleAccelRange(MPU6050_ACCEL_FS_2);
mpu2.setFullScaleGyroRange(MPU6050_GYRO_FS_250);
mpu2.setFullScaleAccelRange(MPU6050_ACCEL_FS_2);
mpu3.setFullScaleGyroRange(MPU6050_GYRO_FS_250);
mpu3.setFullScaleAccelRange(MPU6050_ACCEL_FS_2);
}
void interpretMovement(float accelerationMagnitude) {
// Interpret the movement based on acceleration magnitude
if (accelerationMagnitude < 500) {
Serial.println("Fetal in Normal Position: Relatively low-amplitude and slow-frequency variations in acceleration.");
Serial.println("Interpretation: This indicates the baby is likely sleeping or resting in a stable position.");
} else if (accelerationMagnitude < 1500) {
Serial.println("Fetal Stretching or Rolling: Moderate-amplitude and longer-duration variations in acceleration.");
Serial.println("Interpretation: This suggests the baby is stretching, rolling, or changing position.");
} else {
Serial.println("Fetal Kicks: High-amplitude and short-duration spikes in acceleration.");
Serial.println("Interpretation: This indicates the baby is kicking, which is a common and reassuring sign of fetal well-being.");
}
}
void loop() {
// Read accelerometer data from each sensor
int16_t ax1, ay1, az1, ax2, ay2, az2, ax3, ay3, az3;
mpu1.getAcceleration(&ax1, &ay1, &az1);
mpu2.getAcceleration(&ax2, &ay2, &az2);
mpu3.getAcceleration(&ax3, &ay3, &az3);
// Calculate the magnitude of acceleration for each sensor
float accelerationMagnitude1 = sqrt(ax1*ax1 + ay1*ay1 + az1*az1);
float accelerationMagnitude2 = sqrt(ax2*ax2 + ay2*ay2 + az2*az2);
float accelerationMagnitude3 = sqrt(ax3*ax3 + ay3*ay3 + az3*az3);
// Calculate the average acceleration magnitude
float averageAcceleration = (accelerationMagnitude1 + accelerationMagnitude2 + accelerationMagnitude3) / 3.0;
// Interpret the movement based on average acceleration magnitude
interpretMovement(averageAcceleration);
// Check if there is movement
if (averageAcceleration > 500) { // Adjust threshold as needed
// Record the time of movement
lastMovementTime = millis();
} else {
// Check for inactivity
unsigned long elapsedTime = millis() - lastMovementTime;
if (elapsedTime > 4 * 3600 * 1000) { // 4 hours of inactivity
Serial.println("Fetal in Abnormal Condition: Changes in the overall pattern of acceleration.");
Serial.println("Interpretation: This may indicate a potential problem with the baby's health.");
Serial.println("However, further assessment by a healthcare professional is necessary.");
}
}
delay(100); // Adjust delay as needed
}