Skip to content
← Projects

DC Motor Control — STM32

Four buttons for a brushed motor, with a reversal sequence that protects the driver.

FIG. 1 — 35-second demonstration: speed steps, direction change, emergency stop

What it is

A NUCLEO-L432KC driving a GB37Y3530 gearmotor through a TB6612FNG H-bridge, powered from a 7.4 V 2000 mAh battery so the whole thing runs off the bench. Four push buttons: speed up, speed down, reverse, and an emergency stop. Speed is the PWM duty cycle, shown on four LEDs in 25 % steps, with an RGB LED showing the direction currently set.

The stop button is modelled on the emergency stop on industrial machinery: a separate control that does one thing, rather than holding speed-down until the motor happens to reach zero. What it does in this build is set the PWM duty to zero in firmware.

Reversing without damaging the driver

Reverse is a sequence, not a switch. Pressing it stops the motor, changes direction, and brings it back up to the speed it was running at. Driving a spinning motor straight into reverse puts its back-EMF across the H-bridge, which can take the driver with it. That sequencing was the part of this project that needed thinking about rather than wiring.

What I’d change

The emergency stop. It sets the PWM duty to zero in firmware, so it only works while the controller is still running — if the code hangs or the board resets, the button does nothing. A real emergency stop is a latching, hard-wired contact that cuts the motor supply on its own, independently of the controller, and stays cut until someone resets it. I would add that contact and keep the button in firmware as the ordinary stop.