Building a 4-Motor Drone with ESP32 and TB6612F Motor Drivers
When designing and building drones, precise motor control is crucial. In this project, we're using the ESP32 microcontroller combined with TB6612FNG dual motor drivers to control four individual drone motors. Let’s dive into the motor pin configurations and the code logic that powers our drone's lift and maneuverability.
Motor Pin Configuration
Our drone uses four motors, each driven by specific pins on the ESP32. Below is the mapping:
PWM Control
We control motor speeds using PWM (Pulse Width Modulation) signals. Here are the settings:
PWM channels are mapped individually for each motor:
Selecting and Controlling Motors
We’ve implemented a system where a character command selects which motor to control:
This setup makes it easy to test individual motors during development or run synchronized control when flying the drone.
Power Management Tips
When building drones, remember to:
By using the TB6612F drivers and carefully assigning motor pins and PWM channels, you get precise speed and direction control, forming the foundation for drone stabilization and flight maneuvers.
In upcoming articles, we'll expand on integrating IMU sensors for stability, writing PID controllers, and adding remote control via Wi-Fi or Bluetooth. Stay tuned!
In my current power setup, a LiPo battery distributes power through three separate lines. Two of these lines are dedicated to driving four motors via a pair of TB6612F motor drivers. Each driver's VM (voltage motor input) is stabilized using a 100µF capacitor to handle voltage spikes and reduce noise.
The third line from the battery is responsible for supplying power to the ESP32 microcontroller. This line is protected by an SS34 SMA Schottky diode before connecting to the ESP32's VIN pin, ensuring reverse polarity protection and voltage drop management. To maintain stable voltage and filter out any high-frequency noise, I’ve added multiple capacitors at the VIN of ESP32: a combination of 0.1µF and 10µF in parallel, along with additional 4.7µF and 100µF capacitors for bulk decoupling.
🔥 Adding a 1000µF at ESP VIN
To further improve stability during heavy load conditions, I also added a 1000µF capacitor at the ESP32 VIN. This large bulk capacitor acts as a reservoir of charge, helping to absorb sudden voltage drops caused by transient current spikes — especially when the motors are activated. By buffering these drops, the 1000µF capacitor helps maintain a more consistent voltage level at the ESP32 input, reducing the chances of Wi-Fi brownouts or processor resets during high-load scenarios.
After thorough testing, I discovered that the SS34 SMA diode was partially responsible for the issue. The diode introduces a voltage drop, which prevents the ESP32's VIN from receiving sufficient power. As a result, the Wi-Fi connection fails — attempts to ping the ESP32 return "host is down" errors.
When I fully charged the Li-Po battery and immediately powered the ESP32, the server became active, and I was able to start the motors successfully. However, this setup operates right at the voltage threshold. While the motors can start, once they draw additional current, the voltage dips further, causing the ESP32’s Wi-Fi to disconnect and the server to go offline. This makes it impossible to stop the motors via Wi-Fi, as the connection drops during operation.
🔥 Adding a PPTC Resettable Fuse for System Protection
To further improve the reliability and safety of my power setup, I decided to add a PPTC (Polymeric Positive Temperature Coefficient) resettable fuse. This component acts as an automatic circuit breaker, protecting the system from dangerous overcurrent conditions such as motor stalls, shorts, or wiring faults.
The PPTC is placed immediately after the battery’s positive terminal (+) and before the three power distribution lines:
By positioning the PPTC at the very beginning of the power distribution, it guards the entire system:
This simple addition ensures that even if voltage dips or overcurrent events occur, my LiPo battery, motor drivers, and ESP32 remain protected from permanent damage.
🔋 Adding a BMS (Battery Management System) for Battery Safety and Stability
To further strengthen my power architecture, I have also integrated a Battery Management System (BMS) with the LiPo battery pack. The primary role of the BMS is to protect the battery itself from conditions that could degrade its lifespan or create safety hazards.
The BMS provides several crucial functions:
By adding the BMS, I’ve ensured that the battery voltage stays within safe operating ranges, even during heavy motor loads or partial discharges. This complements the PPTC fuse and protects the overall system by:
With the BMS now in place, the battery can safely deliver power to the motors and ESP32 without risking deep discharge or catastrophic failure — making the whole system safer, more robust, and reliable for wireless-controlled motor operations.
Next Step: Adding the MT3608 Boost Converter
To address the voltage drop issue and ensure stable Wi-Fi operation, the next step is to integrate an MT3608 boost converter into the power system. The MT3608 is a compact DC-DC step-up module that can boost the Li-Po battery voltage to a consistent level, ensuring that the ESP32 always receives adequate power even when the battery voltage drops under load.
By connecting the Li-Po battery to the input of the MT3608 and setting its output to around 5V, we can feed this stable voltage to the ESP32’s VIN pin. This will prevent the Wi-Fi from disconnecting when the motors start drawing power, as the ESP32 will no longer suffer from voltage sag caused by battery load or diode drop.
This upgrade not only stabilizes the server connection but also makes the entire drone system more reliable during motor operations. With the MT3608 in place, starting and stopping the motors over Wi-Fi will become seamless, even as the battery discharges over time.
âš¡ Summary Wiring Flow
Then: