Build a Low-Cost Micro ESP32 Quadcopter Drone

Share
ESP32 Quadcopter Drone

Drone swarms usually make the news with hundreds of expensive aircraft and a ground station to match. Losing one of those drones is a real loss, so they are rarely sent into a collapsed building or a smoke-filled corridor. So, what if each drone in the swarm was cheap enough that losing one did not matter, and the rest of the swarm simply carried on?

Circuit Digest sponsored the Builder in Residence: Hardware Edition Hackathon in collaboration with TinkerSpace, Kochi. Supporting the next generation of hardware innovators, makers, and builders!

In this project, we built ResQmesh, a micro quadcopter meant to be one node of such a swarm, and this article shows how to build one. It runs on a Seeed Studio XIAO ESP32-S3 with an MPU9250 IMU, four 720 coreless motors switched by AO3400A MOSFETs and a 3D-printed frame, and the parts come to ₹2,224 per drone. Our own firmware runs a 500 Hz flight loop on one core and the radio on the other. The micro quadcopter has reached the hand-test stage: it pushes back when tilted, as it should, but it has not flown free yet, and the swarm code has not been tried on more than one drone. You can also check out similar drone projects and ESP32 projects done previously here at Circuit Digest.

What is an ESP32 Quadcopter Drone?

ResQmesh is a swarm drone platform where every node is small and cheap. The design rule was that each drone must cost less than ₹3,000. That rules out brushless motors with ESCs, STM32 flight controllers and GPS, and points at the XIAO ESP32-S3, which has two 240 MHz cores, Wi-Fi and ESP-NOW on a board about the size of a postage stamp. Circuit Digest has also built a low-cost drone using ESP32 with the same 720 coreless motors. If interested, do check it out.

How Does the ESP32 Quadcopter Drone Work?

The work is split between the two cores of the ESP32-S3. Core 1 runs the flight loop every 2000 µs: it reads the MPU9250 over 400 kHz I2C, works out the roll and pitch with a complementary filter, runs the PID loops and sets the PWM for the four MOSFETs. Core 0 runs the Wi-Fi access point, the web page for the phone, ESP-NOW and the USB serial console. The pilot joins the drone's own Wi-Fi network, opens its web page and flies with two on-screen joysticks. 

Block Diagram of the ESP32 Quadcopter Drone

The dashed boxes are written in code but not tested yet. The leader drone re-broadcasts each phone command over ESP-NOW for follower drones, and code/ESP32-CONTROLLER has firmware for a handheld two-gimbal transmitter, which the logs do not mention being built. The ESP32 water level monitor using ESP-NOW on Circuit Digest is a simpler place to see how ESP-NOW sends data between two boards.

Block Diagram of ESP32 Quadcopter Drone

Below is the flowchart of the flight loop.

ESP32 Quadcopter Drone Flight Loop Flowchart

If no control packet arrives for 750 ms, or the drone tilts past 60°, the loop goes to failsafe, and the motors drop to zero. When armed, the angle loop turns the stick angle into a target rotation rate, the rate loop turns that into a correction for each axis, and the mixer combines them into four motor values.

Components Required for the ESP32 Quadcopter Drone

Below is the list of components required to build one drone, with the prices from our bill of materials.

Components-Required-for-ResQmesh-ESP32-Quadcopter-Drone
S.NoComponentDescriptionQuantityCost
1.Seeed Studio XIAO ESP32-S3Flight controller and radio1850
2.MPU9250 IMU (GY-9250 board)Gyro and accelerometer on I2C1420
3.720 Coreless MotorTwo CW and two CCW4300
4.55 mm PropellerTwo CW and two CCW480
5.AO3400A N-Channel MOSFETLow-side motor switch, SOT-23448
6.1N5819 Schottky DiodeFlyback protection416
7.Passives470µF bulk capacitor, 100nF caps, 100Ω and 100kΩ resistors, 4.7kΩ I2C pull-ups1 set60
8.1S LiPo, 3.7V 380mAhFlight battery, 25C1320
9.3D-Printed FramePLA180
10.Wire, JST Connector, Perfboard30 AWG silicone wire, harness and driver board1 set50

The AO3400A is the part that makes the price work. Its gate threshold is between 0.65V and 1.45V, so the ESP32's 3.3V pins switch it fully on without a gate driver IC. We chose the 380mAh pack because each extra 50mAh adds 2 to 3 grams, and our estimate with it was about 4.5 minutes of hover. Leave LoRa off the drone itself: an SX1262 breakout weighs 6.8 grams, close to the whole 7.4-gram frame, so we moved it to the plan for ground relay stations. For how long a pack like this lasts, refer to our article on calculating the run time of a drone LiPo battery.

Circuit Diagram of the ESP32 Quadcopter Drone

Below is the circuit diagram for the ResQmesh micro quadcopter.

Circuit Diagram of ESP32 Quadcopter Drone

The brain of the drone is the XIAO ESP32-S3, powered from the LiPo through its BAT+ pad on the back. Each motor has the same channel: the motor's + lead goes to the battery rail, its − lead goes to the drain of an AO3400A, and the source goes to ground. A 1N5819 across each motor, cathode to the + lead, clamps the spike when the MOSFET turns off, and a 100nF capacitor across the motor tabs takes out the brush noise. The gate is driven through a 100Ω resistor, with a 100kΩ pull-down so the motors stay off while the ESP32 boots. The KiCad schematic and our board both use 100kΩ, though the README says 10kΩ. A 470µF capacitor across the battery handles the current steps, and all motor grounds return to the battery's negative pad, away from the IMU's ground. That is all about the circuit. If MOSFETs are new to you, our tutorial on what a MOSFET is and how it works covers the basics.

Below is one motor channel from our KiCad schematic.

ESP32 Quadcopter Drone KiCad Motor Driver Schematic

It passed KiCad's electrical rules check, but we never ordered a PCB, as that would have broken the budget, so it serves as the map for a hand-wired perfboard.

XIAO ESP32-S3 Pin Connections

FunctionGPIO (Firmware)XIAO PadConnects To
Motor 1, front-left (CW)GPIO4D3100Ω to AO3400A gate
Motor 2, front-right (CCW)GPIO1D0100Ω to AO3400A gate
Motor 3, rear-right (CW)GPIO2D1100Ω to AO3400A gate
Motor 4, rear-left (CCW)GPIO3D2100Ω to AO3400A gate
I2C SDAGPIO5D4IMU SDA, 4.7kΩ to 3V3
I2C SCLGPIO6D5IMU SCL, 4.7kΩ to 3V3
Status LEDGPIO21OnboardActive LOW
Battery senseGPIO8D9Not fitted, monitor disabled

These are the pins that firmware/config.h drives, and the KiCad schematic also puts the motors on D0 to D3. The README in code/ESP32-DRONE shows an older pin table, so wire to this table or to config.h, not to that README.

3D Printing the ESP32 Quadcopter Drone Frame

Below is the printed frame on the printer bed.

3D Printed ESP32 Quadcopter Drone Unibody Frame

The cad folder's README links two Bambu Studio project files. Print FireFlo_v2_7mm, the unibody X frame with 7mm motor bores: its project is set to PLA, 0.2mm layers, six walls, 25% grid infill and no supports, and the slicer puts it at 7.35 grams, which matches the 7.4 grams on our scale. The other file, dreamcatcher_8.5mm, is a frame with rings around the propellers and 8.5mm bores, at 12.71 grams. Use the solid unibody frame: a skeletal X of about 5 grams flexed until the motor pods tilted by nearly 3°, which the IMU reads as the drone tilting, and a ducted frame of about 12 grams lost hover efficiency.

The motor bores need one slicer change. Our first print gave 6.85mm bores in place of 7.00mm, and pressing a motor in split the pod. Set horizontal hole expansion to +0.12mm (the project file has it at 0) for about 7.02mm, a firm press fit. More printed builds are in our 3D printing projects.

Assembling the ESP32 Quadcopter Drone

Charge the LiPo and keep the propellers off until the bench tests are done. Then follow the steps below.

Step 1⇒ Build the MOSFET Driver Board

SOT-23 legs are 0.95mm apart, and perfboard holes are 2.54mm apart, so bend each source leg down onto a bare copper wire that serves as the ground bus, and bridge each gate with its 100Ω resistor before any flexible wire goes on. Fit the 100kΩ pull-downs and the 1N5819 diodes next. Below is the driver board at each stage.

ESP32 Quadcopter Drone Hand Wired-MOSFET Driver Board

Step 2⇒ Wire the IMU

Connect the GY-9250 to 3V3, GND, D4 (SDA) and D5 (SCL), and add the two 4.7kΩ pull-ups from SDA and SCL to 3.3V. Without them, our IMU answered at address 0x68 with WHO_AM_I 0x71 and then froze the bus after about 15 seconds, as the ESP32's weak internal pull-ups round off the 400 kHz clock edges. With them, the bus ran for 4 hours without a dropped frame. If you are new to this kind of sensor, our MPU6050 with ESP32 tutorial is a good start.

Step 3⇒ Fit the Motors and the Harness

Press the motors into the bores in the layout from the mixer: front-left and rear-right spin clockwise, front-right and rear-left anticlockwise. Solder a 100nF capacitor across each motor's tabs and twist each motor's leads at about 4 turns per centimetre to cut the noise they radiate. Run every motor ground back to the battery's negative pad, and put the 470µF capacitor across the battery leads.

Step 4⇒ Stack the Boards

Stack the XIAO and the IMU on the driver board, connect the battery to the BAT+ pad, and check each motor channel against the pin table before the first power-up. Below is the assembled drone.

Assembled ESP32 Quadcopter Drone

Flashing the ESP32 Quadcopter Drone Firmware

The flight firmware this article explains is in code/ESP32-DRONE/firmware, an Arduino sketch.

Step 1⇒ Build and Upload with Arduino CLI

Install the ESP32 board package and run these two commands from code/ESP32-DRONE, with your own port in place of COM14:

arduino-cli compile --fqbn esp32:esp32:XIAO_ESP32S3 firmware
arduino-cli upload -p COM14 --fqbn esp32:esp32:XIAO_ESP32S3 firmware

On Windows, flash_drone.bat runs the same two commands and finds the port, but edit its CLI_PATH first, as it points to our laptop. The platformio.ini in the same folder builds the slightly different ESP-IDF copy in the main folder.

Step 2⇒ Run the Host Tests and the Simulator

The tests build with g++ on a PC from code/ESP32-DRONE/tests, against the main folder's sources:

g++ -std=c++11 -Wall -I../main run_all_tests.cpp ../main/pid.cpp ../main/attitude.cpp ../main/mixer.cpp ../main/receiver.cpp ../main/battery.cpp ../main/safety.cpp ../main/imu.cpp -o test_runner
./test_runner

On the current code, the suite reports 77 passed and 0 failed. run_simulation.bat builds simulate_flight.cpp the same way, but its step 7 waits only 250 ms against the 750 ms timeout, so the drone stays in FLIGHT and the "FAILSAFE" line it prints is hard-coded. Make that gap longer than 750 ms.

Bench Testing and Calibration

Do these checks with the propellers off.

Step 1⇒ Check the Motors

Open the USB serial console at 115200 baud and type test_motor 1 5 to test_motor 4 5; the command takes a duty of 0 to 25%. Motors 1 and 3 must spin clockwise and motors 2 and 4 anticlockwise.

Step 2⇒ Check and Calibrate the IMU

Type attitude and tilt the drone by 20° to check that roll and pitch follow, and use calibrate with the drone still and disarmed to redo the zero-bias calibration. Without an IMU the firmware stops at boot, so set IMU_BENCH_TEST_MODE to 1 to test the radio side on a bare board.

Step 3⇒ Connect the Phone

Join the drone's Wi-Fi network, ResQmesh-Drone, with the password from config.h (change the default first), and open http://192.168.4.1. Arming needs the throttle below 10%, a calibrated IMU and the drone within 20° of level, and the red KILL button stops the motors. For another ESP32-S3 web page served from its own access point, see our smart home automation using access point mode project.

Step 4⇒ Hand Test

Fit the propellers, hold the drone loosely, arm it and raise the throttle to 25%. Tip the nose down, and the front motors should speed up while the rear ones slow. The starting gains in config.h (angle Kp 4.0, rate 0.65, 0.45 and 0.025 for roll and pitch, 1.20 and 0.80 for yaw) have not been tuned in free flight, so tune them on a tether first.

ESP32 Quadcopter Drone Firmware Code Explanation

The firmware is C++ on the ESP32 Arduino core with ESP-IDF drivers, one file per job. Below are the parts that matter most.

Pins and PWM Settings

#define PIN_I2C_SDA 5      // XIAO D4 (GPIO5)
#define PIN_I2C_SCL 6      // XIAO D5 (GPIO6)
#define I2C_FREQ_HZ 400000 // 400 kHz Fast-Mode
#define PIN_MOTOR_FL 4 // Motor 1: Front-Left (GPIO4)
#define PIN_MOTOR_FR 1 // Motor 2: Front-Right (GPIO1)
#define PIN_MOTOR_RR 2 // Motor 3: Rear-Right (GPIO2)
#define PIN_MOTOR_RL 3 // Motor 4: Rear-Left (GPIO3)
#define MOTOR_PWM_FREQ_HZ 20000 // 20 kHz ultrasonic frequency (no coil whine)
#define MOTOR_PWM_BITS 10       // 10-bit resolution -> 0 to 1023

All pins, gains and limits live in config.h, and these defines are what the firmware uses, even where the comment block above them lists older pads. The PWM runs at 20 kHz because the motors squealed at 1 to 4 kHz, and above about 18 kHz the coil noise is out of hearing range. The same file sets a flight ceiling of 800 out of 1023 to avoid brownouts, and MotorController::init() holds the motor pins LOW before the PWM starts.

The 500 Hz Loop on Core 1

next_wake_us += CONTROL_LOOP_PERIOD_US;
int64_t now_us = esp_timer_get_time();
if (now_us > next_wake_us + LOOP_OVERRUN_TOL_US) {
   fc->stats_.overruns++;
   next_wake_us = now_us; // Resync
}
fc->runIteration(now_us);

flightLoopTask() is pinned to Core 1 at priority 24. Each pass adds 2000 µs to the wake time, counts an overrun if it is more than 200 µs late, and calls runIteration() to read the IMU and run the attitude filter, safety checks, PID and mixer. We measured one iteration at 420 µs on an oscilloscope. The safety checks have one gap: BATTERY_MONITOR_ENABLED is 0, so the monitor reports a fixed 3.85V, and there is no low-battery cutoff until you fit the divider.

Anti-Saturation Mixer

if (max_m > MIXER_OUT_MAX) {
   float excess = max_m - MIXER_OUT_MAX;
   for (int i = 0; i < NUM_MOTORS; i++) {
       out.m[i] -= excess;
   }
   out.saturated = true;
}

In the simulator, at 95% throttle with a hard roll, one motor wanted 1120 while the PWM tops out at 1023, and clipping it would lose the difference that keeps the drone level. QuadMixer::mix() lowers all four motors by the excess instead. Watch one thing: motors.cpp then clamps each motor to 800, so the clipping comes back between 800 and 1023. Setting MIXER_OUT_MAX to 800 keeps the two limits in step.

Relaying the Phone's Sticks to the Swarm

if (target_id != node_id_) {
   SwarmControlPacket swarm_pkt;
   swarm_pkt.header.target_id = target_id;
   swarm_pkt.header.sender_id = node_id_;
   swarm_pkt.throttle = (uint16_t)std::max(0.0f, std::min(1000.0f, t));
   swarm_pkt.crc = computeCRC((const uint8_t *)&swarm_pkt, sizeof(swarm_pkt) - sizeof(uint16_t));
   esp_now_send(s_bcast_mac, (const uint8_t *)&swarm_pkt, sizeof(swarm_pkt));
}

When the phone's command is not meant only for the leader, processWebSocketFrame() in receiver.cpp copies the sticks into a SwarmControlPacket with a CRC-16 and broadcasts it over ESP-NOW. Followers answer with a 10 Hz heartbeat, which fills the peer table on the phone.

Live Video Demonstration

Below is the Builder in Residence video, where we talk through the drone and its firmware.

Output: Testing the ESP32 Quadcopter Drone

With the motors spinning at 20 kHz, we measured 45mV across one AO3400A at about 1.5A, which is 30mΩ and 0.067W of heat, and the MOSFETs stayed cold after 3 minutes at full throttle. In the hand test at 25% throttle, tipping the nose down made the front motors speed up and the rear ones slow, and tilting it left made the left motors push it back to level. That is as far as the testing has gone. A tethered hover, PID tuning in free air and pairing three drones over ESP-NOW are the next steps. The repository gives three different all-up weights: 32.2 grams in the last weekly log, 43.6 grams in the README's weight table and 58 grams in the README story after a later correction, so weigh your own build. TODO: final measured all-up weight.

Troubleshooting the ESP32 Quadcopter Drone

SymptomLikely CauseFix
I2C freezes after about 15 secondsWeak internal pull-ups at 400 kHzAdd 4.7kΩ pull-ups from SDA and SCL to 3.3V
Motors squeal at low throttlePWM in the audio range (1 to 4 kHz)Set MOTOR_PWM_FREQ_HZ to 20000 with 10-bit duty
Motors twitch while flashing or bootingFloating MOSFET gatesFit the 100kΩ gate pull-downs; the firmware also pulls the pins low before PWM starts
Motor pod cracks when the motor is pressed inPrinted bore shrinks to about 6.85mmSet horizontal hole expansion to +0.12mm in the slicer
Upload fails, or the port is busyA serial monitor holds the port, or the board is not in bootloader modeClose the monitor; hold B, tap R, release B and upload again
Battery always reads 3.85VBATTERY_MONITOR_ENABLED is 0Wire a 100kΩ/100kΩ divider from BAT+ to GPIO8 and set it to 1
Simulator step 7 still shows FLIGHTThe step waits 250 ms, but the timeout is 750 msMake the gap longer than 750 ms in simulate_flight.cpp

Lessons From Our Build

Keep the frame stiff before saving weight. A lighter skeletal frame flexed enough to tilt the motors by nearly 3°, and the flight loop cannot tell that bend from a real tilt.

Trust config.h over the documents. The weekly logs, the README and the firmware each show a different motor pin plan, and the gate pull-down is written as 10kΩ in places where the schematic and board use 100kΩ. Wire to the firmware and the schematic.

Test the safety code as carefully as the flight code. The simulator's failsafe step and the mixer's limit both drifted out of step with config.h without any test failing, so check those two by hand after changing a limit.

Conclusion

ResQmesh shows that one ESP32-S3 can run a 500 Hz flight loop on one core while the other handles Wi-Fi and ESP-NOW, and that a ₹2,224 drone can hold itself level against a hand. There is still room for improvement, such as a battery divider so the low-battery cutoff actually works, a tethered hover to tune the PID in free air, more drones to test the ESP-NOW relay, and a VL53L1X distance sensor for altitude hold, which was the next sensor on our list. Further, one can add position hold with an optical flow sensor, just like this PMW3901 optical flow sensor with ESP32 on Circuit Digest.

GitHub Repository

The ResQmesh repository has the flight firmware, the handheld ESP-NOW transmitter firmware, the desktop and phone control pages, the host tests and flight simulator, and the links to the frame files. ResQmesh was built by Jayasurya Jayakumar and Nikhil S at Tinkerspace as part of the Builder in Residence programme, and the README states the MIT licence.

ESP32 Quadcopter Drone GitHub RepoESP32 Quadcopter Drone Zip File

Frequently Asked Questions About the ESP32 Quadcopter Drone 

⇥ 1. Why not use Betaflight or ArduPilot on this drone?
Both expect an STM32 board and a separate RC receiver, and neither runs ESP-NOW messaging between drones. Writing our own flight loop let us keep the radio and the flight control on the same ESP32-S3, one core each.

⇥ 2. Can ResQmesh fly as a swarm now?
Not yet. The relay, heartbeat and peer table are in the firmware and pass the host tests, but they have not been tried with more than one drone in the air.

⇥ 3. Can I use a different frame?
Yes, if it takes 7mm motors and stays stiff under full throttle. A frame that flexes makes the IMU read the bend as a tilt, and every extra gram cuts into a 380mAh battery's hover time.

Drone and ESP32 Sensor Projects

Explore more ESP32 drone builds and the sensors that help small drones hold their position.

PMW3901 Optical Flow Sensor With ESP32

PMW3901 Optical Flow Sensor With ESP32

The PMW3901 is a small, low-power optical flow sensor that measures movement by analysing surface patterns. It is widely used in robotics, drones, and automation to estimate position changes without GPS. This makes it an excellent choice for applications requiring precise motion tracking.

MPU6050 Gyro Sensor Interfacing with ESP32 Board

MPU6050 Gyro Sensor Interfacing with ESP32 Board

In today’s article, we are going to interface the MPU6050 Accelerometer and Gyroscope with ESP32 and show the values over the Webserver. The MPU-6050 sensor module is used in many applications like drones, robots, and motion sensors. This sensor is also called the Gyroscope or triple-axis accelerometer.

Low Cost Drone using ESP32

Low Cost Drone using ESP32

In this project, we are going to build complete ESP32 drone code that can be easily controlled using our smartphones. Building a DIY ESP32 drone project is an affordable entry point into drone technology, with costs ranging from pocket change to commercial-grade systems.

Have any question related to this Article?

Add a comment

No account needed. Your comment appears once a moderator has reviewed it.

Never shown publicly.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.