At its core, a drone flies by using a microcontroller to continuously read inertial sensors and adjust the speed of its brushless motors via electronic speed controllers to maintain thrust and orientation. While the props generate the physical lift, the actual 'flying'—the hovering, turning, and resisting of wind—is entirely a software and embedded hardware problem. If you are building a custom quadcopter or programming an ESP32-based flight controller, understanding this intersection of aerodynamics and real-time processing is mandatory.
The Core Mechanism: Aerodynamics Meets the PID Loop
What people commonly confuse about drone flight is the difference between aerodynamic lift and active stabilization. A quadcopter is aerodynamically unstable; it is essentially an inverted pendulum. If you were to apply equal, static voltage to all four motors, the drone would not hover. The slightest asymmetry in motor winding, propeller pitch, or center of gravity would cause it to flip and crash in milliseconds.
The physical lift is generated by the propellers pushing air downward (Newton's third law). But the flight is managed by a Proportional-Integral-Derivative (PID) control loop running on the flight controller (FC). The FC's microcontroller—typically an STM32F405 or STM32H743 running at 168MHz to 480MHz—reads the onboard Inertial Measurement Unit (IMU) thousands of times per second to detect pitch, roll, and yaw errors, then instantly corrects them.
Think of it like balancing a broomstick upright on the palm of your hand. You aren't just holding it still; your eyes (the IMU) detect a slight tilt, your brain (the PID loop) calculates how fast it's falling, and your hand (the motors) moves to catch it before it drops. The drone is doing this 8,000 times every single second.
The Microcontroller's Job: Sensor Fusion and Motor Control
Modern flight controllers rely on high-performance IMUs like the ICM-42688P, which combine a 3-axis gyroscope and a 3-axis accelerometer. The gyro measures rotational velocity (how fast the drone is tilting), while the accelerometer measures linear acceleration (where gravity is pulling). The microcontroller fuses these signals using a complementary or Kalman filter to determine the drone's exact attitude in 3D space.
A Worked Numeric Example: The P-Term in Action
Let's look at a real-world numeric example of how the PID loop keeps the drone level during a hover. Assume your drone requires a base throttle value of 1350 (on a scale of 1000 to 2000) to maintain a steady hover in still air.
- The Disturbance: A gust of wind tilts the drone 4 degrees to the right (a positive roll error).
- The Sensor Read: The ICM-42688P gyro detects this 4-degree error and sends the data via SPI to the STM32 microcontroller.
- The P-Term Calculation: The Proportional (P) gain is set to 5.0 in your tuning software. The microcontroller multiplies the error by the P-gain:
4 degrees × 5.0 = 20. - The Correction: The FC adds this correction value of 20 to the left motors and subtracts 20 from the right motors.
- The Output: The left motors receive a throttle command of 1370 (spinning faster to push that side up), and the right motors receive 1330 (spinning slower to let that side drop).
This happens in a fraction of a millisecond. If the P-gain is too low, the drone drifts and feels 'mushy'. If the P-gain is too high (e.g., set to 15.0), the correction value becomes 60, the motors overcompensate, and the drone enters a violent, high-frequency oscillation known as a 'P-bounce' before tearing itself apart.
Where You Meet This In Practice: Circuit and Protocol Choices
When you move from theory to actually wiring and programming a drone, the physics of flight dictate your embedded design choices. Here is where the rubber meets the road on the workbench.
1. ESC Protocols: PWM vs. DShot
Legacy drones used analog PWM (Pulse Width Modulation) to tell the ESCs how fast to spin the motors. PWM is slow and susceptible to electrical noise. If you are building a drone today, you must use a digital protocol like DShot600 or Bidirectional DShot. DShot sends digital packets of 16 bits (11 bits for throttle value, 1 bit for telemetry request, 4 bits for CRC checksum). Bidirectional DShot allows the ESC to send the actual motor RPM back to the flight controller on the same wire, allowing the FC's RPM filtering to notch out motor noise from the gyro signal, resulting in buttery-smooth flight.
2. Power Rail Filtering (The LC Filter)
Brushless motors and ESCs generate massive amounts of electrical noise and voltage spikes (back-EMF) when commutating. If this noise reaches the 3.3V logic rail powering your IMU, the sensor will read 'phantom' vibrations, causing the PID loop to react to ghosts and fry your motors. In practice, you must design or verify an LC (Inductor-Capacitor) filter on the FC's power input. A typical setup uses a 10µH shielded power inductor paired with low-ESR ceramic capacitors to create a clean, isolated 5V and 3.3V rail for the microcontroller and sensors.
3. SPI Routing and IMU Placement
Because the PID loop relies on microsecond timing, the IMU must be connected via SPI, not I2C (which is too slow for 8kHz polling). Furthermore, the IMU must be physically mounted as close to the center of mass as possible, often on a soft silicone dampening pad to isolate it from high-frequency frame vibrations while still transmitting the rigid-body rotational forces.
Frequently Asked Questions
How do drones fly in wind without drifting?
While the inner PID loop handles attitude (keeping the drone level), resisting wind drift requires an outer control loop. In GPS-equipped drones (like those running ArduPilot), the microcontroller reads GPS velocity and position data. If the wind pushes the drone backward, the outer loop calculates a positional error and commands the inner loop to pitch the drone forward slightly, angling the thrust vector to fight the wind. In FPV racing drones without GPS, the pilot's eyes and thumbs act as the outer loop, making manual stick corrections.
How do drones fly upside down or perform flips?
Aerodynamically, standard propellers only push air 'down' relative to their pitch. To fly upside down, the drone doesn't reverse the props; it simply flips 180 degrees and continues to push air toward the sky (which is now 'down' relative to the inverted drone). The microcontroller achieves this by maxing out the throttle on two adjacent motors while cutting throttle to the other two, creating a massive torque differential that snaps the frame into a roll or flip in under 200 milliseconds. Modern flight controllers use 'Acro Mode' (rate mode), where the stick input dictates the rotational speed (degrees per second) rather than a target angle, allowing the pilot to hold the drone inverted.
How do drones fly when one motor fails?
In a standard quadcopter, a single motor failure usually results in an unrecoverable spin and a crash, because the remaining three motors cannot counteract the yaw torque of the dead motor. However, advanced flight controllers running specialized firmware (like ArduPilot's Motor Interlock or hexacopter configurations) can detect the sudden RPM drop via Bidirectional DShot telemetry. In a hexacopter (6 motors), the FC instantly recalculates the mixing matrix, sacrificing yaw authority to maintain pitch and roll stability, allowing the pilot to limp the drone home. Some cutting-edge 2026 algorithms even attempt to induce a controlled, continuous spin on a quadcopter to use centrifugal force and remaining thrust for a stabilized, albeit spinning, descent.






