Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Nano-Based Posture Detector with MPU6050 Gyroscopes and Flex Sensor

View and Edit Project In Cirkit DesignerImage of Arduino Nano-Based Posture Detector with MPU6050 Gyroscopes and Flex Sensor

Circuit Documentation

Summary

The circuit is designed to monitor posture using flex and gyroscopic sensors and provide feedback through visual and auditory indicators. It consists of an Arduino Nano microcontroller interfaced with two MPU6050 accelerometer and gyroscope modules, a flex resistor, two LEDs (one red, one green), a buzzer, and three resistors. The Arduino Nano controls the system, reads sensor values, and activates the LEDs and buzzer based on the sensor readings to indicate good or bad posture.

Component List

Resistor (220 Ohms)

Resistor (10k Ohms)

MPU6050 Accelerometer + Gyroscope (Wokwi Compatible)

2.2 inch Basic Flex Resistor

Buzzer

LED: Two Pin (red)

LED: Two Pin (green)

Arduino Nano

9V Battery

Wiring Details

Buzzer

LED: Two Pin (green)

LED: Two Pin (red)

2.2 inch Basic Flex Resistor

MPU6050 Accelerometer + Gyroscope (Wokwi Compatible)

Arduino Nano

9V Battery

Documented Code

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);
  } else {
    digitalWrite(LED_GOOD_PIN, HIGH);
    digitalWrite(LED_WRONG_PIN, LOW);
  }
  delay(100);
}

This code is responsible for reading the values from the flex sensor and the two gyroscopes. If any of the readings fall below the defined thresholds, it indicates bad posture by turning on the red LED, turning off the green LED, and sounding the buzzer. If the posture is good, the green LED is turned on, and the red LED is turned off. The sensor values and status are printed to the serial monitor for debugging purposes.