Submit

11 / 20

Drive a wheel

An H-bridge controls both speed and direction of a DC motor.

Run this experiment →
ESP32 teaching illustration with module, GPIO headers and lesson components

Why it’s here

Change the PWM command, then reverse the direction.

How it works

An H-bridge controls both speed and direction of a DC motor. No. Use a suitable H-bridge, separate motor supply and a common ground. This guided model targets the original ESP32 and Arduino-ESP32 3.x; radio, acoustics, loads and mechanics are simplified.

Try it

  1. Open this experiment
  2. Change the PWM command, then reverse the direction.

Connections

  • GPIO 25 / 26 / 27 — H-bridge enable / direction A / B
  • External supply / GND — Motor power / shared ground

Example sketch

// H-bridge: EN=25, IN1=26, IN2=27. Separate motor supply and common GND.

void setup() {
  pinMode(26, OUTPUT); pinMode(27, OUTPUT);
  ledcAttach(25, 20000, 8);
}

void loop() {
  digitalWrite(26, HIGH);
  digitalWrite(27, LOW);
  ledcWrite(25, 150);
}

Check your understanding

Can a GPIO supply motor power?

Show the answer

No. Use a suitable H-bridge, separate motor supply and a common ground.

Sources

Arduino-ESP32 ↗ · GPIO reference ↗

MAKE A THOUGHTFUL CHOICE

Your shortlist, side by side.

Pricing models are indicative. Check each official website for current plans and limits.