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.
Robust Power System for ESP32 + DC Motors
Introduction
Powering an ESP32 microcontroller alongside DC motors requires a solid and reliable power design. Motors are notorious for generating noise, voltage dips, and spikes that can crash or reset your ESP32. This guide walks you through the steps to create a bulletproof power system by covering:
• Power Distribution from a LiPo Battery
• Noise Suppression for Motors
• Voltage Boosting for the ESP32
• Protection Circuits (Fuses, Diodes, TVS)
• Capacitor Selection for Stability
By the end, your ESP32-based robotics or IoT project will have a stable and resilient power supply.
1. Power Distribution from a LiPo Battery
A single-cell LiPo (3.7V) powers:
• 2x TB6612F motor drivers (for 4 motors)
• 1x MT3608 boost converter (for ESP32 at 5V)
Why Separate Power Lines?
• Motors draw high current, causing voltage drops.
• ESP32 needs clean, stable 5V (or 3.3V internally).
• Separate lines prevent noise coupling from motors to the microcontroller.
Wiring:
LiPo 3.7V
├── Motor Line 1 → TB6612F (VM) → Motors
├── Motor Line 2 → TB6612F (VM) → Motors
└── Logic Line → PPTC → SS34 → MT3608 → ESP32
2. Noise Suppression for Motors
Motors generate electrical noise (inductive spikes) that can reset the ESP32.
Solution: Capacitors on Motor Drivers
• 100µF electrolytic: Absorbs large current surges.
• 10µF ceramic: Filters high-frequency noise.
Placement:
Solder directly across VM (motor voltage) and GND on each TB6612F.
Why Not 1000µF?
• Too slow to suppress fast spikes.
• Can cause inrush current issues.
3. Voltage Boosting for the ESP32
The MT3608 boosts 3.7V → 5V for the ESP32’s VIN pin.
Why 5V?
• ESP32’s onboard regulator needs ≥4.8V for stable 3.3V output.
• Prevents brownouts during WiFi/Bluetooth use.
Key Settings:
• Feedback resistors: Set output to 5.0V (check datasheet).
• Input capacitor (10µF): Stabilizes LiPo voltage.
4. Protection Circuits
A) PPTC Fuse (Resettable Fuse)
• Purpose: Protects against overcurrent (e.g., motor stall).
• Rating: 3A for motors, 1A for logic.
B) SS34 Schottky Diode
• Purpose: Prevents reverse-polarity damage.
• Direction: Anode → Battery (+), Cathode → MT3608.
C) SMBJ5.0CA TVS Diode (Bidirectional)
• Purpose: Clamps voltage spikes (>5.8V) from motors or boost converter.
• Placement: Between MT3608 VOUT+ and GND.
Why Bidirectional?
• Protects against both positive and negative spikes (though negative is rare in DC systems).
5. Capacitor Selection for ESP32 VIN
The ESP32 needs clean 5V power to avoid crashes.
Recommended Capacitors:
• 100µF electrolytic: Bulk storage for sudden load changes (WiFi/BT).
• 10µF ceramic: Mid-frequency noise filtering.
• 0.1µF ceramic: High-frequency noise suppression.
Placement:
Solder as close as possible to ESP32’s VIN pin.
Common Pitfalls & Fixes
Problem 1: ESP32 Resets When Motors Start
Cause: Ground noise from motors.
Fix:
• Use star grounding (separate motor/logic grounds).
• Add a ferrite bead on motor power lines.
Problem 2: Motor Runs Briefly at Power-Up
Cause: Floating TB6612F input pins.
Fix:
• Add 10kΩ pull-down resistors to IN1/IN2/PWM pins.
• Initialize pins to LOW in setup().
Problem 3: Voltage Drops Under Load
Cause: Insufficient capacitance.
Fix:
• Increase input capacitor on MT3608 (e.g., 22µF).
• Check LiPo battery health (weak batteries sag under load).
Final Schematic
LiPo 3.7V
├── [PPTC 3A] → [TB6612F] → Motors (100µF + 10µF)
├── [PPTC 3A] → [TB6612F] → Motors (100µF + 10µF)
└── [PPTC 1A] → [SS34] → [MT3608] → [SMBJ5.0CA] → [100µF+10µF+0.1µF] → ESP32
Conclusion
A well-designed power system prevents:
✅ ESP32 resets
✅ Motor noise interference
✅ Voltage spikes/drops
By combining:
• Separate power lines
• Noise-suppressing capacitors
• Protection circuits (PPTC, Schottky, TVS)
You’ll have a reliable system for motor control + WiFi/Bluetooth!
Share this guide to help others build stable projects! 🚀