11 / 20
Drive a wheel
An H-bridge controls both speed and direction of a DC motor.
Run this experiment →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
- Open this experiment
- 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.