#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu;
const int buttonPin = 17; // Replace with the actual pin connected to the push button
int buttonState = 0;
int stepCount = 0;
int lastAccelY = 0;
void setup() {
Wire.begin();
mpu.initialize();
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
stepCount = 0;
}
// Read accelerometer data
int16_t accelX, accelY, accelZ;
mpu.getAcceleration(&accelX, &accelY, &accelZ);
// Read temperature
float temperature = mpu.getTemperature() / 340.0 + 36.53; // Convert raw value to degrees Celsius
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
// Detect a step when acceleration along the Y-axis crosses a threshold
if (accelY > lastAccelY && accelY > 5000) {
stepCount++;
}
lastAccelY = accelY;
Serial.print("Steps: ");
Serial.println(stepCount);
delay(1000); // Adjust the delay as needed
}