Arduino Nano-Based Posture Detector with MPU6050 Gyroscopes and Flex Sensor
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
The circuit in question appears to be designed for posture monitoring, utilizing a combination of flex sensors and gyroscopes to detect the user's posture. It includes an Arduino Nano as the central microcontroller, which processes the sensor data and provides feedback through LEDs and a buzzer. The circuit is powered by a 9V battery and includes resistors for current limiting and pull-down configurations.
Component List
Resistors
- 220 Ohm Resistors (2x): Used for current limiting, possibly for LEDs to prevent damage.
- 10k Ohm Resistor: Likely used as a pull-down resistor for the buzzer.
Sensors
- MPU6050 Accelerometer + Gyroscope (2x): These sensors detect motion and orientation, providing data to the Arduino for posture analysis.
- 2.2 inch Basic Flex Resistor: This flex sensor changes resistance when bent, allowing the detection of bending motions.
Actuators
- Buzzer: Provides audible feedback when the posture is incorrect.
- LED (Red): Indicates incorrect posture.
- LED (Green): Indicates correct posture.
Power Supply
- 9V Battery: Provides power to the circuit.
Microcontroller
- Arduino Nano: Acts as the central processing unit for the circuit, reading sensor data and controlling the actuators.
Wiring Details
Buzzer
- PIN: Connected to Arduino Nano D9 (Digital Pin 9).
- GND: Connected to the common ground net.
LEDs
- Green LED:
- Anode: Connected to Arduino Nano D10 (Digital Pin 10).
- Cathode: Connected to a 220 Ohm resistor.
- Red LED:
- Anode: Connected to Arduino Nano D11/MOSI (Digital Pin 11).
- Cathode: Connected to a 220 Ohm resistor.
Flex Sensor
- Pin 1: Connected to a 10k Ohm resistor, which is connected to the common ground net.
- Pin 2: Connected to Arduino Nano A0 (Analog Pin 0).
MPU6050 Accelerometer + Gyroscope
- VCC: Connected to the positive terminal of the 9V battery through Arduino Nano VIN.
- GND: Connected to the common ground net.
- SDA: One sensor's SDA is connected to Arduino Nano A1 (Analog Pin 1), and the other to A2 (Analog Pin 2).
Resistors
- 220 Ohm Resistors (2x): Connected between the cathodes of the LEDs and the common ground net.
- 10k Ohm Resistor: Connected between the buzzer's GND and the common ground net.
Power Supply
- 9V Battery:
- + (Positive): Connected to Arduino Nano VIN.
- - (Negative): Connected to the common ground net.
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.println(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); // Sound the buzzer at 1kHz for 500ms
} else {
digitalWrite(LED_GOOD_PIN, HIGH);
digitalWrite(LED_WRONG_PIN, LOW);
}
delay(100);
}
The code is designed to read values from the flex sensor and two gyroscopes. If any of the readings fall below predefined thresholds, it is assumed that the posture is incorrect. In such a case, the red LED is turned on, the green LED is turned off, and the buzzer is activated. If the posture is correct, the green LED is turned on, and the red LED is turned off. The sensor values and posture status are printed to the serial monitor for debugging purposes.