ESP32 DIY Drone for Beginners

Created At: 2025-05-07 06:53:48 Updated At: 2025-05-19 11:49:15

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.

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! 🚀

Comment

Add Reviews

Latest Posts

Subscribe our newsletter