How ducphan18/self-balance-car works
Project Overview
• This is an Arduino-based self-balancing car. Its purpose is to leverage sensor data (from the MPU6050, an accelerometer/gyroscope) and a PID control loop to compute and drive the appropriate commands through a motor driver (L298N) to keep the car balanced.
• The project includes custom libraries for sensor communication (I2Cdev, MPU6050), motor control (LMotorController), and the control algorithm (PID) along with associated example sketches.
Identifying Main Components (Modules)
a. Hardware Components:
• Arduino Nano (central microcontroller running the self_balance_car.ino sketch)
• MPU6050 sensor
• Motor Driver (L298N)
• Motors (2 gear motors attached to rubber wheels)
• Power supply parts (LM2596 step-down module, battery base with 18650 batteries)
• Connections (wiring and breadboard as per Schematic)
b. Software Components (Code Modules):
• Main Sketch: “self_balance_car.ino” which ties together the libraries to perform the balancing algorithm.
• Sensor Interface: Libraries “I2Cdev” and “MPU6050” (plus its multiple variants and examples) manage all communication with the sensor and process raw data.
• Control Algorithm: “PID” library implements the control loop used for dynamically adjusting motor signals based on sensor feedback.
• Motor Control: “LMotorController” library abstracts the motor control commands sent to the L298N driver.
• Additional support: Example sketches within the libraries, which illustrate usage but aren’t necessarily part of the core functionality.
Architectural Relationships & Interactions
• Data Flow:
• Sensor Data Acquisition: The MPU6050 captures orientation/acceleration data and communicates via I2C (handled by I2Cdev) to the Arduino.
• Data Processing & Control: The main sketch processes the sensor data using the MPU6050 library. Then, a PID algorithm computes the necessary adjustment in motor speed to achieve balance.
• Actuation: The motor commands are then passed to the LMotorController, which drives the motors through the L298N.
• Communication: Note the directional data flows – sensor → control algorithm → motor control – with feedback loops inherent in PID control.
Final Elements
• All components should be clearly labeled.
• Interconnections and key libraries that implement these functions.