In recent years, the rapid advancement of intelligent control technologies, sensor systems, and micro-electromechanical systems has positioned unmanned aerial vehicles (UAVs) as a focal point of research and development. Among various UAV configurations, the quadrotor has gained significant attention due to its simple structure, maneuverability, vertical take-off and landing capabilities, and hovering performance. These attributes make the quadrotor ideal for applications such as aerial photography, agricultural monitoring, logistics, and environmental surveillance. However, the control of a quadrotor UAV presents considerable challenges, including susceptibility to wind disturbances, slow dynamic responses, and instability under external influences. To address these issues, we have designed and implemented a comprehensive control system centered around an STM32 microcontroller, integrated with MPU6050 attitude sensors, brushless motor drivers, and wireless communication modules. This paper details the theoretical foundations, hardware design, software implementation, and experimental validation of our quadrotor control system, emphasizing the use of PID algorithms for precise attitude control. Through extensive testing, we demonstrate that our system achieves stable flight and robust performance, paving the way for broader applications of quadrotor technology.
The quadrotor UAV operates by adjusting the rotational speeds of its four motors, which in turn alter the lift forces generated by the rotors. An inertial measurement unit (IMU) captures real-time data on the vehicle’s motion, and attitude estimation algorithms process this data to provide feedback for autonomous flight control. The dynamics of the quadrotor are governed by Newton-Euler equations, which describe the relationship between external forces and the vehicle’s motion. We begin by modeling the translational and rotational movements of the quadrotor, as these form the basis for control system design.
For translational motion, the dynamics are expressed as:
$$ m \ddot{\mathbf{r}} = \mathbf{F}_g + \mathbf{F}_t $$
where \( m \) represents the mass of the quadrotor, \( \ddot{\mathbf{r}} = [\ddot{x}, \ddot{y}, \ddot{z}]^T \) is the acceleration vector in the inertial frame, \( \mathbf{F}_g = [0, 0, -mg]^T \) is the gravitational force, and \( \mathbf{F}_t = [0, 0, R]^T \) is the total lift force from the rotors, with \( R = \sum_{i=1}^{4} R_i \) being the sum of individual rotor lifts.
Rotational motion is described by the Euler equations:
$$ I \dot{\boldsymbol{\omega}} + \boldsymbol{\omega} \times (I \boldsymbol{\omega}) = \mathbf{M} $$
Here, \( I \) is the inertia matrix of the quadrotor, \( \boldsymbol{\omega} = [p, q, r]^T \) is the angular velocity vector in the body-fixed frame, \( \dot{\boldsymbol{\omega}} \) is the angular acceleration, and \( \mathbf{M} = [M_x, M_y, M_z]^T \) denotes the total torque generated by the rotors.
The lift force \( F_i \) for each rotor is calculated using:
$$ F_i = C \rho (A r_i)^2 $$
where \( C \) is the lift coefficient, \( \rho \) is air density, \( A \) is the rotor disk area, and \( r_i \) is the rotational speed of the i-th rotor. The torques include roll (\( M_x \)), pitch (\( M_y \)), and yaw (\( M_z \)) components, given by:
$$ M_x = l (F_2 – F_4), \quad M_y = l (F_1 – F_3), \quad M_z = C_Q \sum_{i=1}^{4} (-1)^i r_i^2 $$
In these equations, \( l \) is the distance from the rotor center to the quadrotor’s center of mass, and \( C_Q \) is the torque coefficient. These mathematical models are essential for simulating quadrotor behavior and designing control strategies.

The flight control module serves as the computational core of the quadrotor, handling real-time data acquisition, sensor fusion, attitude estimation, and execution of control algorithms. It utilizes a six-axis sensor to measure acceleration and angular velocity, and applies filtering techniques such as complementary or Kalman filters to compute roll, pitch, and yaw angles. These angles are critical for stable hovering, attitude adjustments, and autonomous flight operations. Data communication between the quadrotor and ground station is facilitated through serial interfaces like UART, SPI, or I2C. The ground control station transmits commands via a remote controller, which outputs PPM signals decoded by a ground control board. Wireless modules, such as the NRF24L01, enable bidirectional data transfer, allowing the quadrotor to receive control inputs and send back status information like battery voltage, altitude, and GPS coordinates.
For control, we employ a PID (Proportional-Integral-Derivative) algorithm, renowned for its simplicity, efficiency, and robustness in various applications, including aerospace and automation. The continuous-time PID control law is:
$$ u(t) = K_p \left[ e(t) + \frac{1}{T_i} \int_0^t e(\tau) \, d\tau + T_d \frac{de(t)}{dt} \right] $$
where \( u(t) \) is the control output, \( e(t) \) is the error signal, \( K_p \) is the proportional gain, \( T_i \) is the integral time constant, and \( T_d \) is the derivative time constant. The transfer function of this controller is:
$$ G(s) = \frac{u(s)}{e(s)} = K_p \left( 1 + \frac{1}{T_i s} + T_d s \right) $$
However, for digital implementation on a microcontroller, we discretize the PID algorithm. The discrete form is:
$$ u(k) = K_p \left[ e(k) + \frac{T}{T_i} \sum_{j=0}^{k} e(j) + T_d \frac{e(k) – e(k-1)}{T} \right] $$
where \( T \) is the sampling period. To reduce computational load and avoid error accumulation, we use an incremental PID algorithm. By applying recurrence relations, the control increment is derived as:
$$ \Delta u(k) = u(k) – u(k-1) = A e(k) + B e(k-1) – C e(k-2) $$
with coefficients:
$$ A = K_p \left( 1 + \frac{T}{T_i} + \frac{T_d}{T} \right), \quad B = K_p \left( 1 + \frac{2T_d}{T} \right), \quad C = K_p \frac{T_d}{T} $$
This incremental approach only requires the past three error samples, enhancing efficiency and precision in quadrotor control.
In designing the quadrotor control system, hardware selection is crucial for performance and reliability. We chose the STM32 microcontroller based on the ARM Cortex-M3 core for its high computational power, low power consumption, and rich peripheral set. Operating at up to 72 MHz, it delivers 1.25 DMIPS/MHz, efficiently handling complex control tasks. The STM32 includes 64 KB of flash memory for code storage and supports various interfaces. Below is a summary of key hardware components:
| Component | Model/Specification | Key Features |
|---|---|---|
| Microcontroller | STM32 (ARM Cortex-M3) | 72 MHz max frequency, 64 KB flash, multiple peripherals |
| Attitude Sensor | MPU6050 | 6-axis IMU, high sensitivity, low power, I2C/SPI interface |
| Wireless Module | NRF24L01 | SOC design, >1 Mbps data rate, SPI communication |
| Motor Driver | Brushless ESC | PWM input, electronic commutation, over-current protection |
The MPU6050 sensor is integral for attitude estimation, providing accelerometer and gyroscope data with high linearity and low noise. Its circuit design includes pull-up resistors for I2C communication and decoupling capacitors for stable operation. For propulsion, we selected brushless motors paired with electronic speed controllers (ESCs). The ESCs convert PWM signals from the STM32 into phased currents to drive the motors, enabling precise speed control. The NRF24L01 wireless module ensures reliable communication with the ground station, using SPI for data exchange and supporting high-speed transmission to handle real-time commands and telemetry.
Software development for the quadrotor focuses on real-time execution and efficiency. We programmed the system in C language, initializing hardware interfaces and software modules upon startup. The main loop operates at 400 Hz, processing sensor data, executing control algorithms, and generating PWM outputs within a single interrupt service routine to avoid priority conflicts. Key functions include attitude reading from the MPU6050, PID control calculations, and PWM duty cycle adjustments for motor control. For instance, the PID parameters for roll, pitch, and yaw are tuned to achieve stability, and the control outputs are combined with throttle inputs to compute individual motor speeds. The code snippet below illustrates part of the main control logic:
float roll, pitch, yaw; // Attitude angles
float target_roll = 0.0f; // Target angles
float target_pitch = 0.0f;
float target_yaw = 0.0f;
float throttle = 0.0f; // Throttle input
PID_TypeDef pid_roll, pid_pitch, pid_yaw; // PID instances
int main(void) {
SystemInit(); // Initialize system clock and peripherals
PWM_Init(); // Set up PWM outputs
MPU6050_Init(); // Initialize sensor
PID_Init(&pid_roll, 1.0f, 0.1f, 0.01f); // Initialize PID gains
PID_Init(&pid_pitch, 1.0f, 0.1f, 0.01f);
PID_Init(&pid_yaw, 1.0f, 0.1f, 0.01f);
while (1) {
MPU6050_ReadData(&roll, &pitch, &yaw); // Read sensor data
float roll_output = PID_Calculate(&pid_roll, target_roll, roll);
float pitch_output = PID_Calculate(&pid_pitch, target_pitch, pitch);
float yaw_output = PID_Calculate(&pid_yaw, target_yaw, yaw);
// Compute motor PWM values
float motor1 = throttle + roll_output + pitch_output + yaw_output;
float motor2 = throttle - roll_output + pitch_output - yaw_output;
float motor3 = throttle + roll_output - pitch_output - yaw_output;
float motor4 = throttle - roll_output - pitch_output + yaw_output;
// Constrain outputs to safe range
motor1 = constrain(motor1, 1000, 2000);
motor2 = constrain(motor2, 1000, 2000);
motor3 = constrain(motor3, 1000, 2000);
motor4 = constrain(motor4, 1000, 2000);
// Output PWM signals to ESCs
PWM_SetDutyCycle(TIM2, motor1);
PWM_SetDutyCycle(TIM3, motor2);
PWM_SetDutyCycle(TIM4, motor3);
PWM_SetDutyCycle(TIM1, motor4);
}
}
Experimental results demonstrate that our quadrotor control system achieves stable flight and accurate attitude control. We conducted tests under various conditions, including wind disturbances, to evaluate robustness. The incremental PID algorithm effectively minimized overshoot and settling time, while the sensor fusion provided reliable attitude estimates. The table below summarizes performance metrics from our experiments:
| Metric | Value/Range | Notes |
|---|---|---|
| Attitude Stability | ±2° error in roll/pitch | Under moderate wind conditions |
| Response Time | < 100 ms | For step input changes |
| Communication Latency | < 10 ms | Between ground station and quadrotor |
| Power Consumption | ~5 W during hover | With all systems active |
These results validate the feasibility of our design, showing that the quadrotor can maintain stability and respond promptly to control inputs. The system’s performance is comparable to commercial solutions, highlighting its potential for practical applications.
In conclusion, we have successfully designed and implemented a quadrotor UAV control system using an STM32 microcontroller, MPU6050 sensor, and PID control algorithms. By deriving detailed dynamical models and employing incremental PID for digital control, we achieved precise attitude regulation and stable flight. The hardware components were carefully selected for their performance and integration capabilities, while the software architecture ensures real-time operation. This work provides a foundation for further advancements in quadrotor technology, such as incorporating machine learning for adaptive control or expanding swarm capabilities. Future efforts will focus on optimizing power efficiency and enhancing autonomy for complex missions, ultimately promoting the adoption of quadrotor systems in diverse fields.
