ESP32 DIY Drone for Beginners

Created At: 2025-05-07 06:53:48 Updated At: 2025-05-09 02:55:35

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:

  • Motor A (Front-Left Motor):
    • Direction Pins: AIN1 (GPIO 27), AIN2 (GPIO 26)
    • PWM Pin: PWMA (GPIO 25)
  • Motor B (Front-Right Motor):
    • Direction Pins: BIN1 (GPIO 33), BIN2 (GPIO 32)
    • PWM Pin: PWMB (GPIO 14)
  • Motor C (Rear-Left Motor):
    • Direction Pins: CIN1 (GPIO 12), CIN2 (GPIO 13)
    • PWM Pin: PWMC (GPIO 18)
  • Motor D (Rear-Right Motor):
    • Direction Pins: DIN1 (GPIO 19), DIN2 (GPIO 23)
    • PWM Pin: PWMD (GPIO 4)
  • STBY Pin (Standby Control):
    • GPIO 5

PWM Control

We control motor speeds using PWM (Pulse Width Modulation) signals. Here are the settings:

  • PWM Frequency: 1000 Hz (ideal for motor speed control)
  • PWM Resolution: 10 bits (gives us 1024 steps from 0 to 1023)
  • Speed Range: 0 (stopped) to 1023 (full speed)
  • Default Speed: 600 (around 60% duty cycle)

PWM channels are mapped individually for each motor:

  • PWM Channel A: Channel 0
  • PWM Channel B: Channel 1
  • PWM Channel C: Channel 2
  • PWM Channel D: Channel 3

Selecting and Controlling Motors

We’ve implemented a system where a character command selects which motor to control:

  • '1' selects Motor A
  • '2' selects Motor B
  • '3' selects Motor C
  • '4' selects Motor D
  • 'a' selects All motors together

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:

  • Use a fully charged LiPo battery (4.2V per cell).
  • Avoid voltage drops by minimizing diode losses in the power supply line.
  • Ensure stable 3.3V logic for the ESP32 to maintain Wi-Fi connectivity.

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:

  • Two lines powering the four motors through the TB6612F motor drivers.
  • One line powering the ESP32 (which already includes the SS34 SMA diode and capacitors).

By positioning the PPTC at the very beginning of the power distribution, it guards the entire system:

  • If the motors stall and draw excessive current, the PPTC heats up and limits the current, preventing damage.
  • If there’s a wiring short or an unexpected surge, the PPTC trips, cutting off dangerous current flow.
  • Once the fault is cleared and the PPTC cools down, it automatically resets, ready to protect again.

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:

  • Overcharge Protection: Prevents the LiPo cells from charging beyond safe voltage limits (usually 4.2V per cell), which could otherwise cause swelling or even combustion.
  • Over-discharge Protection: Stops the battery from being drained below critical voltage (typically 3.0V per cell), which would lead to permanent capacity loss or failure.
  • Overcurrent and Short-circuit Protection: Automatically disconnects the battery output in case of sudden high current spikes, wiring shorts, or motor stalls that could otherwise damage the battery or other components.
  • Cell Balancing: For multi-cell packs, the BMS ensures that all cells charge and discharge evenly, avoiding imbalance that can reduce capacity or cause instability.

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:

  • Preventing dangerous undervoltage conditions that could crash the ESP32 mid-operation.
  • Avoiding battery damage during high current events.
  • Extending the overall life and safety of the LiPo pack in repeated usage cycles.

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

  • Battery + → PPTC → BMS B+
  • Battery – → BMS B–

Then:

  • BMS P+ → splits into:
    • VM of motor drivers (with capacitors)
    • MT3608 VIN+
  • BMS P– → common ground for:
    • Motor drivers' GND
    • MT3608 VIN–
    • ESP32 GND
    • Anything else needing GND

Comment

Add Reviews

Latest Posts

Subscribe our newsletter