๐ŸŽ‰ 75% of content is free forever โ€” Unlock Premium from $10/mo โ†’
CW
NEWSLIVESearch All Content
๐Ÿ’ผ Servicesโ„น๏ธ Aboutโœ‰๏ธ ContactView Pricing Plansfrom $10

Drone Hardware: Flight Controllers, ESCs, and Sensors

๐ŸŸข Free Lesson

Drone Hardware: Flight Controllers, ESCs, and Sensors

A quadcopter is a feedback loop made of metal, silicon, and copper. Four spinning propellers generate thrust, a handful of micro-electromechanical sensors report motion, and a microcontroller runs a control law thousands of times per second to keep the frame level. Before you can write autonomy code โ€” obstacle avoidance, waypoint planning, visual odometry โ€” you need a clear mental map of which board talks to which sensor, over which bus, at what rate. This lesson walks the full signal chain from battery connector to propeller shaft.

By the end you will be able to identify every major component on a modern F4 flight controller, explain why the IMU is sampled at 1 kHz while the barometer runs at 100 Hz, read raw accelerometer and gyro data from Python over I2C, and pick a sensible motor-and-ESC pairing for a first build.

The flight controller is a real-time system, not a computer

The flight controller (FC) is a 30 ร— 30 mm PCB, but its job is nothing like running an operating system. An STM32F405 โ€” the most common FC microcontroller โ€” is an ARM Cortex-M4 running at 168 MHz with a single-precision floating-point unit and 1 MB of flash. That sounds modest next to a phone processor, and it is: the chip has no memory protection, no preemptive scheduler, and roughly 192 KB of SRAM. What it does have is deterministic timing. The attitude control loop must finish inside a fixed budget โ€” typically 125 ยตs for an 8 kHz PID loop โ€” on every single cycle, without exception.

That real-time constraint shapes every hardware decision on the board. Interrupt latency matters more than peak throughput. The inertial measurement unit is wired to hardware SPI or a dedicated high-speed I2C port, never a shared low-priority bus. The blackbox logger streams to external QSPI flash in the background without stealing cycles from the loop. When you open an FC schematic, read it as a timing diagram first and a component list second. The MCU also exposes several UARTs for GPS, radio control, and telemetry, plus PWM or DShot outputs for the ESCs, an analog-to-digital converter for battery voltage sensing, and I2C or SPI headers for external sensors such as a LiDAR rangefinder.

On-board sensors and the buses they ride

A typical F4 board carries a six-axis inertial measurement unit (accelerometer plus gyroscope, such as the MPU6050 or ICM42688), a barometric pressure sensor (BMP280 or BMP388), and often a magnetometer (QMC5883L). Each serves a different purpose and runs at a different rate, because the underlying physics change on different timescales.

SensorWhat it measuresTypical rateBusFused into
GyroscopeAngular velocity (degrees per second)1โ€“8 kHzSPI or I2CAttitude rate control
AccelerometerLinear acceleration (g)1โ€“8 kHzSPI or I2CAttitude correction, takeoff detect
BarometerAir pressure, converted to altitude50โ€“100 HzI2CHeight estimate, climb-rate tone
MagnetometerEarth magnetic field50โ€“100 HzI2CYaw heading, GPS course lock
GPS receiverSatellite pseudoranges5โ€“25 HzUART (NMEA or UBX)Position, velocity, return-to-home
LiDAR or ToF rangefinderDistance to nearest surface10โ€“40 HzUART or I2CTerrain following, precision landing

Angular velocity can change significantly within a millisecond, so the gyro must be sampled fast or the controller will chase stale data. Air pressure changes slowly and the sensor itself is noisy โ€” the BMP388 datasheet quotes roughly ยฑ0.5 m of altitude resolution โ€” so 100 Hz is plenty and averaging improves the estimate further.

On the bus side, SPI wins whenever the sensor supports it: a dedicated chip-select line means no addressing overhead and clock speeds above 10 MHz. I2C is fine for slow sensors but shares a two-wire bus, so a single misbehaving device can stall everything else. Many boards therefore put the IMU on SPI and the barometer and magnetometer on I2C.

Firmware also runs a complementary or Kalman filter that fuses fast but drifting gyro integration with slow but absolute accelerometer and magnetometer corrections. The result is the stable roll, pitch, and yaw estimate that the PID controller actually consumes.

From PWM to three-phase AC: ESCs and motors

Brushless DC motors cannot be driven by a steady voltage. Each motor has permanent magnets on the rotating bell and copper windings on the fixed stator; the electronic speed controller (ESC) energizes the windings in sequence to drag the rotor around. The flight controller sends the ESC a digital command โ€” historically a 400 Hz to 8 kHz PWM pulse, now often a DShot packet at 16 to 32 kHz โ€” and the ESC commutates the motor to match.

Motor names encode stator dimensions: a 2207 motor is 22 mm wide and 7 mm tall. The KV rating is RPM per volt at no load; a 2300 KV motor on a 4S pack (14.8 V nominal) will spin near 34,000 RPM unloaded. Propeller diameter and pitch then convert that shaft speed into thrust and current draw. Always match the ESC current rating to the motor's peak draw with at least 20โ€“30 percent headroom. A 30 A ESC for a motor peaking at 25 A is comfortable; a 25 A ESC for that same motor is a thermal failure waiting to happen on a hot day.

Power distribution and BECs

The battery feeds a power distribution board (PDB), often integrated into a 4-in-1 ESC board. The PDB routes raw pack voltage โ€” 12.6 to 25.2 V depending on cell count โ€” to each ESC and provides filtered taps for the rest of the system. A battery eliminator circuit (BEC), usually a switching regulator, steps pack voltage down to 5 V for the receiver, GPS, and camera, and sometimes a second regulated rail at 12 V for the video transmitter.

Two details matter in practice. First, the flight controller's own 3.3 V and 5 V rails are budgeted in milliamps. Adding a LiDAR, a camera, and a companion computer can exceed the onboard regulator, in which case you need an external BEC. Second, electrical noise from the ESCs couples into the IMU and the video feed. Star-grounding at the PDB, low-ESR capacitor banks across the ESC leads, and routing I2C harnesses away from motor wires are not optional polish โ€” they are the difference between a clean PID tune and a drone that oscillates for no visible reason.

How a sensor reading becomes a motor command

The entire stack collapses into one loop that runs on every IMU sample. The Python sketch below mirrors the structure of real flight firmware: read sensors, fuse attitude, run the PID controllers, mix, and output motor commands.

python
class FlightStack:
    """One iteration of a quadcopter flight loop (simplified)."""

    def __init__(self):
        self.kp, self.ki, self.kd = 4.0, 0.04, 15.0
        self.integral = 0.0
        self.prev_error = 0.0
        self.prev_roll = 0.0

    def read_imu(self):
        # Real firmware performs an SPI burst read of six 16-bit registers.
        return {"gyro_x": 12.4, "gyro_y": -3.1, "accel_z": 0.998}

    def fuse_attitude(self, gyro_x_dps, accel_z_g, dt):
        # Complementary filter: gyro for rate, accelerometer for gravity.
        import math
        roll_gyro = self.prev_roll + gyro_x_dps * dt
        roll_accel = math.asin(max(-1.0, min(1.0, accel_z_g)))
        roll = 0.98 * roll_gyro + 0.02 * roll_accel
        self.prev_roll = roll
        return roll

    def pid(self, setpoint, measurement, dt):
        error = setpoint - measurement
        self.integral += error * dt
        derivative = (error - self.prev_error) / dt if dt > 0 else 0.0
        self.prev_error = error
        return self.kp * error + self.ki * self.integral + self.kd * derivative

    def motor_mix(self, roll, pitch, yaw, throttle):
        # X-configuration mixer; order is M1 front-left through M4 rear-right.
        m1 = throttle + roll - pitch + yaw
        m2 = throttle - roll - pitch - yaw
        m3 = throttle + roll + pitch - yaw
        m4 = throttle - roll + pitch + yaw
        return [max(1000, min(2000, int(m))) for m in (m1, m2, m3, m4)]

    def step(self, dt=0.000125):
        imu = self.read_imu()
        attitude = self.fuse_attitude(imu["gyro_x"], imu["accel_z"], dt)
        roll_cmd = self.pid(0.0, attitude, dt)
        return self.motor_mix(roll_cmd, 0.0, 0.0, 1500)


stack = FlightStack()
print(stack.step())

Notice the loop budget: at 8 kHz, one period is 125 ยตs. Everything inside step โ€” sensor read, filter, PID, mixer โ€” must complete well inside that window. This is why core firmware is written in C against bare-metal registers, while Python lives on a companion computer that talks to the FC over MAVLink at 10 to 30 Hz, handling perception and planning tasks that tolerate higher latency.

Reading the IMU directly during bring-up

Most AI drone projects pair an FC with a companion computer (Raspberry Pi, Jetson) over UART or USB. For hardware bring-up, though, talking to the IMU directly over I2C is the fastest way to verify wiring and orientation. The driver below wakes an MPU6050, configures ยฑ4 g and ยฑ500 degrees-per-second ranges, and streams converted readings.

python
import time

class MPU6050:
    """Minimal MPU6050 driver over smbus2."""

    def __init__(self, bus=1, addr=0x68):
        import smbus2
        self.bus = smbus2.SMBus(bus)
        self.addr = addr
        self.bus.write_byte_data(self.addr, 0x6B, 0x00)  # wake device
        self.bus.write_byte_data(self.addr, 0x1C, 0x08)  # +/-4 g
        self.bus.write_byte_data(self.addr, 0x1B, 0x08)  # +/-500 dps

    def _read16(self, reg):
        hi = self.bus.read_byte_data(self.addr, reg)
        lo = self.bus.read_byte_data(self.addr, reg + 1)
        val = (hi << 8) | lo
        return val - 65536 if val > 32767 else val

    def read_all(self):
        return {
            "ax": self._read16(0x3B) / 8192.0,
            "ay": self._read16(0x3D) / 8192.0,
            "az": self._read16(0x3F) / 8192.0,
            "gx": self._read16(0x43) / 65.5,
            "gy": self._read16(0x45) / 65.5,
            "gz": self._read16(0x47) / 65.5,
        }


imu = MPU6050()
while True:
    d = imu.read_all()
    print(f"accel {d['ax']:+.2f} {d['ay']:+.2f} {d['az']:+.2f} g   "
          f"gyro {d['gx']:+.1f} {d['gy']:+.1f} {d['gz']:+.1f} dps")
    time.sleep(0.01)

Place the board flat and the Z accelerometer should read close to +1.0 g. Lift one edge and watch the matching axis move โ€” that orientation check saves hours of debugging once the same sensor is mounted inverted inside a frame.

Sizing a first build

Choosing parts is mostly about matching thrust to mass while keeping electrical margins. A useful starting matrix for common classes:

Build classMotorsPropsPackAll-up weightNotes
3-inch micro1404 3800 KV3ร—2.5ร—32S 450 mAh~80 gIndoor, low inertia
5-inch freestyle2306 1700 KV5ร—5.1ร—36S 1100 mAh~450 gThrust-to-weight near 6:1
5-inch cine2207 2400 KV5ร—4.0ร—34S 1300 mAh~600 gSmoother, carries camera
7-inch long range2812 1300 KV7ร—3.5ร—26S 1800 mAh~900 gEfficiency over agility
Heavy lift X84014 500 KV ร—810ร—4.5ร—26S 5000 mAh~4 kgMotor redundancy

Compute thrust-to-weight by multiplying single-motor static thrust (from a thrust-stand chart or datasheet) by the motor count, then dividing by all-up weight. Below 2:1 the aircraft will not fly cleanly, 4:1 is a solid general-purpose target, and racing frames push past 8:1 at the cost of endurance.

Common Mistakes

Using a 25 A ESC with a motor that peaks at 28 A

Fix: Size ESCs at 1.3 to 1.5 times the motor peak current; thermal margin is cheap insurance.

Soft-mounting the FC on foam so soft that the PID loop adds lag

Fix: Use the frame maker's mounting hardware. Heavy isolation filters vibration but injects phase lag the controller cannot see.

Powering a Jetson or LiDAR from the flight controller 5 V pad

Fix: Check the regulator milliamp rating first; companion computers need a dedicated 5 V BEC rated 3 to 5 A.

Leaving the magnetometer next to the ESC power leads

Fix: Mount the compass at least 5 cm from high-current wiring or yaw will oscillate as throttle changes.

Best Practices

  • Log every flight to blackbox flash; post-mortem PID tuning is impossible without data.
  • Keep I2C runs under 10 cm and twisted; prefer SPI for the IMU whenever the board exposes it.
  • Label the ESC-to-motor mapping (M1 front-left, M2 front-right, M3 rear-left, M4 rear-right) before the first arm.
  • Verify sensor orientation in software against a physical tilt test before any hover.
  • Carry a spare 5 V BEC and UART harness in the field kit; most dead avionics are wiring faults.

Key Takeaways

  • The flight controller is a hard real-time system: the full sensor-to-motor loop must finish inside one PID period, typically 125 ยตs at 8 kHz.
  • Sensors run at rates matched to their physics โ€” gyro at 1 kHz or above, barometer near 100 Hz โ€” and firmware fuses them with a complementary or Kalman filter.
  • ESCs convert PWM or DShot commands into three-phase motor drive; match their current rating to peak motor draw with 30 percent headroom.
  • Power flows battery to PDB or 4-in-1 ESC to BEC rails at 5 V and 12 V; companion computers need their own regulated supply.
  • A safe bring-up sequence is: verify IMU orientation over I2C, bench-test motor mapping, then hover in a netted area before running any autonomy code.
CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-12

โ€”
โ˜†โ˜†โ˜†โ˜†โ˜†
0 ratings

Rate & Feedback

Need Expert Drone AI Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement