Arduino Nano-Based Posture Monitoring System with MPU6050 Sensors and Buzzer Alert
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to monitor posture using a combination of a flex sensor and two MPU6050 accelerometer + gyroscope modules. The circuit includes an Arduino Nano microcontroller, LEDs to indicate good or bad posture, and a buzzer to alert the user when bad posture is detected. The system reads values from the sensors and determines if the posture is good or bad based on predefined thresholds.
Component List
Resistor (220 Ohms)
- Description: Standard resistor
- Pins: pin1, pin2
Resistor (10k Ohms)
- Description: Standard resistor
- Pins: pin1, pin2
MPU6050 Accelerometer + Gyroscope (Wokwi Compatible)
- Description: 6-axis motion tracking device
- Pins: INT, AD0, XCL, XDA, SDA, SCL, GND, VCC
2.2 inch Basic Flex Resistor
- Description: Flex sensor
- Pins: Pin 2, pin 1
Buzzer
- Description: Piezoelectric buzzer
- Pins: PIN, GND
LED: Two Pin (red)
- Description: Red LED
- Pins: cathode, anode
LED: Two Pin (green)
- Description: Green LED
- Pins: cathode, anode
Arduino Nano
- Description: Microcontroller board
- Pins: D1/TX, D0/RX, RESET, GND, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11/MOSI, D12/MISO, VIN, 5V, A7, A6, A5, A4, A3, A2, A1, A0, AREF, 3V3, D13/SCK
9V battery
- Description: Power source
- Pins: +, -
Wiring Details
Resistor (220 Ohms)
Resistor 1
- pin1: Connected to the cathode of the green LED
- pin2: Connected to GND
Resistor 2
- pin1: Connected to the cathode of the red LED
- pin2: Connected to GND
Resistor (10k Ohms)
- pin1: Connected to pin 1 of the flex sensor
- pin2: Connected to GND
MPU6050 Accelerometer + Gyroscope (Wokwi Compatible)
MPU6050 1
- GND: Connected to GND
- VCC: Connected to VIN
- SCL: Connected to A5
- SDA: Connected to A4
MPU6050 2
- GND: Connected to GND
- VCC: Connected to VIN
- SCL: Connected to A5
- SDA: Connected to A4
2.2 inch Basic Flex Resistor
- Pin 2: Connected to A0
- pin 1: Connected to pin1 of the 10k Ohm resistor
Buzzer
- PIN: Connected to D9
- GND: Connected to GND
LED: Two Pin (red)
- cathode: Connected to pin1 of the 220 Ohm resistor
- anode: Connected to D11/MOSI
LED: Two Pin (green)
- cathode: Connected to pin1 of the 220 Ohm resistor
- anode: Connected to D10
Arduino Nano
- VIN: Connected to the positive terminal of the 9V battery
- GND: Connected to the negative terminal of the 9V battery and other GND connections
9V battery
- +: Connected to VIN of the Arduino Nano
- -: Connected to GND
Documented Code
#include <Arduino_BuiltIn.h>
const int FLEX_PIN = A0;
const int GYRO1_PIN = A1;
const int GYRO2_PIN = A2;
const int BUZZER_PIN = 9;
const int LED_GOOD_PIN = 10;
const int LED_WRONG_PIN = 11;
const int FLEX_THRESHOLD = 400;
const int GYRO_THRESHOLD = 20;
int flexValue = 0;
int gyro1Value = 0;
int gyro2Value = 0;
bool goodposture = true;
void setup() {
Serial.begin(9600);
pinMode(FLEX_PIN, INPUT);
pinMode(GYRO1_PIN, INPUT);
pinMode(GYRO2_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(LED_GOOD_PIN, OUTPUT);
pinMode(LED_WRONG_PIN, OUTPUT);
}
void loop() {
flexValue = analogRead(FLEX_PIN);
gyro1Value = analogRead(GYRO1_PIN);
gyro2Value = analogRead(GYRO2_PIN);
Serial.print("Flex:");
Serial.print(flexValue);
Serial.print("Gyro_1:");
Serial.print(gyro1Value);
Serial.print("Gyro_2:");
Serial.print(gyro2Value);
if ((flexValue < FLEX_THRESHOLD) || (gyro1Value < GYRO_THRESHOLD) || (gyro2Value < GYRO_THRESHOLD)) {
goodposture = false;
} else {
goodposture = true;
}
if (!goodposture) {
digitalWrite(LED_WRONG_PIN, HIGH);
digitalWrite(LED_GOOD_PIN, LOW);
tone(BUZZER_PIN, 1000, 500);
} else {
digitalWrite(LED_GOOD_PIN, HIGH);
digitalWrite(LED_WRONG_PIN, LOW);
}
delay(100);
}
This code reads the values from the flex sensor and the two MPU6050 modules. If any of the values fall below their respective thresholds, it indicates bad posture by lighting up the red LED and sounding the buzzer. If the values are above the thresholds, it indicates good posture by lighting up the green LED.