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

Arduino UNO Controlled BLDC Motor Stabilization System with MPU-6050 IMU

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled BLDC Motor Stabilization System with MPU-6050 IMU

Circuit Documentation

Summary of the Circuit

This circuit is designed to control a Brushless DC (BLDC) motor via an Electronic Speed Controller (ESC) to stabilize a cube using an MPU-6050 Inertial Measurement Unit (IMU) sensor. The system reads the orientation of the cube and adjusts the motor speed to maintain the original position. The Arduino UNO serves as the central microcontroller unit, interfacing with the MPU-6050 for orientation data and controlling the ESC, which in turn drives the BLDC motor. A lipo battery provides power to the system, and an AMS1117 voltage regulator ensures stable voltage supply to the Arduino UNO.

Component List

Arduino UNO

Lipo Battery 2200mAh 30C

BLDC Motor

Electronic Speed Controller (ESC)

MPU-6050

AMS1117

Wiring Details

Arduino UNO

Lipo Battery 2200mAh 30C

BLDC Motor

Electronic Speed Controller (ESC)

MPU-6050

AMS1117

Documented Code

/*
 * Reaction Flywheel Stabilization System
 * This code is designed to control a BLDC motor via an ESC to stabilize a cube
 * using an MPU-6050 IMU sensor. The system will read the orientation of the cube
 * and adjust the motor speed to maintain the original position.
 */

#include <Wire.h>
#include <MPU6050.h>

MPU6050 mpu;

const int escPin = 9; // ESC signal connected to pin D9
int16_t ax, ay, az;
int16_t gx, gy, gz;

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Initialize MPU-6050
  Wire.begin();
  mpu.initialize();
  if (!mpu.testConnection()) {
    Serial.println("MPU6050 connection failed");
    while (1);
  }

  // Initialize ESC pin
  pinMode(escPin, OUTPUT);
  analogWrite(escPin, 0); // Start with motor off
}

void loop() {
  // Read raw accelerometer and gyroscope data
  mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

  // Process sensor data to determine orientation
  float angleX = atan2(ay, az) * 180 / PI;
  float angleY = atan2(ax, az) * 180 / PI;

  // Calculate motor speed based on orientation
  int motorSpeed = map(angleX, -90, 90, 0, 255);
  motorSpeed = constrain(motorSpeed, 0, 255);

  // Write motor speed to ESC
  analogWrite(escPin, motorSpeed);

  // Print data for debugging
  Serial.print("AngleX: "); Serial.print(angleX);
  Serial.print(" AngleY: "); Serial.println(angleY);
  Serial.print(" Motor Speed: "); Serial.println(motorSpeed);

  // Delay for stability
  delay(100);
}

This code is responsible for initializing the MPU-6050 sensor and reading its data to determine the orientation of the cube. It then calculates the motor speed required to maintain the cube's position and sends the corresponding signal to the ESC, which controls the BLDC motor. The serial output can be used for debugging and monitoring the system's performance.