Motor drivers
A motor driver lets a microcontroller’s pins, good for about 20 mA, control a motor that draws amps: an H-bridge of four transistor switches sets the direction, and switching it with PWM sets the speed. At 50% duty on 12 V, the motor averages 6 V.
Vaverage = duty × Vsupply
where the duty is the share of each PWM cycle the bridge is on, so speed follows the duty.
The L298N, L293D and TB6612FNG drive DC motors; the DRV8825 drives steppers.
What is a motor driver?
A motor driver is a chip or module that lets a microcontroller’s pins, good for about 20 mA, control a motor’s much larger current, usually in both directions and at any speed.
A pin wired straight to a motor would be overloaded and could be destroyed by the motor’s switch-off spikes. A driver takes simple logic signals, direction and a PWM speed, and switches the motor’s own supply. For one motor that only turns one way, a single MOSFET or TIP120 and a diode can be enough.
What is an H-bridge, and how does it work?
An H-bridge is four switches arranged in an H round a motor: closing one diagonal pair drives current through the motor one way, and the other pair drives it the other way.
Figure 1 steps through its states, including braking and the short to avoid. Inside a driver the switches are transistors, with diodes to carry the motor’s current when they turn off.
Forward: S1 and S4 closed: current flows from + through S1, left to right through the motor, then through S4 to ground, so it turns forward.
How do you use an L298N motor driver?
To use an L298N module, connect the motor supply to its 12 V terminal and ground, each motor to an output pair, IN1 to IN4 to four pins for direction, and ENA and ENB to PWM pins for speed.
It drives two DC motors or one stepper at up to 2 A each, from up to 46 V. A jumper turns on its 5 V regulator for supplies up to 12 V. Its bipolar transistors drop 1.8 to 3.2 V at 1 A, about 2.5 V typically, hence its big heat sink.
What is the L293D?
The L293D is a 16-pin chip with four half-bridges, enough for two small DC motors in both directions at up to 600 mA each, with the flyback diodes built in, which is what its D stands for.
It runs motors from 4.5 to 36 V and fits a breadboard, which makes it a classic for small robots and the motor shields many kits use.
Why choose a TB6612FNG?
Choose a TB6612FNG when your motors run below about 13.5 V: its MOSFET bridges are about 0.5 Ω, so it wastes far less power than an L298N, driving two motors at 1.2 A each, 3.2 A in short peaks.
It takes 2.7 to 5.5 V logic, so it suits 3.3 V boards such as the ESP32, and comes on small breakout boards with pins for two direction inputs and a PWM input per motor.
How do you control a DC motor’s speed and direction?
To control a DC motor’s speed and direction, set the H-bridge’s direction with two pins and switch it on and off with PWM, so the share of time it is on sets the average voltage the motor sees.
Figure 2 drives the lab’s motor that way. Reversing just swaps which diagonal pair switches, so the motor turns the other way at the same speed. The DC motor page explains why its speed follows the voltage.
50% duty, forward: the driver switches its bridge on 50% of the time, so the motor averages 50% × 3 V = 1.5 V and turns forward at about 44% of full speed.
What is a DRV8825?
The DRV8825 is a stepper motor driver: two H-bridges with current control that move a bipolar stepper in full steps or microsteps down to 1/32, from a step pin and a direction pin.
It runs from 8.2 to 45 V. A small potentiometer sets its current limit, which protects the motor; set it before you connect the motor, as Example 2 works out. See servo and stepper motors for how a stepper moves.
Which motor driver should you choose?
Choose a driver whose current rating beats your motor’s stall current and whose voltage covers its supply: an L293D for small motors, a TB6612FNG for efficient 1 A motors, an L298N for bigger ones.
Power motors from their own supply, such as a 12 V adapter running from 120 V or 230 V mains, sharing only ground with the microcontroller. Leads carrying 1 to 2 A want 22 to 20 AWG, 0.33 to 0.52 mm².
How do you work out a driver’s heat and a stepper’s current?
Multiply the voltage a driver loses by the current for its heat, and for a DRV8825, double its reference voltage for the current limit.
Example 1: why an L298N runs hot
A motor draws 1 A from 12 V through a L298N. How much heat does the driver make, and what voltage reaches the motor?
- Given
- a L298N running a motor at 1 A from 12 V, its transistors dropping about 2.5 V together, 1.8 V at best
- Find
- the heat in the driver, and the voltage the motor gets
- Solution
- P = 2.5 V × 1 A = 2.5 WThe motor gets 12 V − 2.5 V = 9.5 V
- Answer
- 2.5 W of heat, 9.5 V to the motor
Example 2: setting a DRV8825’s current
A DRV8825 board’s current is set with its small potentiometer. With 0.75 V measured at its reference, what is the current limit?
- Given
- a DRV8825 stepper driver board with its reference turned to 0.75 V
- Find
- the current limit per coil
- Solution
- I = 2 × Vref = 2 × 0.75 V = 1.5 A
- Answer
- 1.5 A per coil
Summary
Key equations
- Vaverage = duty × Vsupply PWM speed control
- P = Vdrop × I a driver’s heat
- Ilimit = 2 × Vref a DRV8825 board
Key terms
- H-bridge
- Four switches that drive a motor either way.
- Duty
- The share of a cycle a switch is on.
- Shoot-through
- Both switches on one side on: a short.
- Microstepping
- Moving a stepper in fractions of a step.
Practice problems
-
Which H-bridge switches turn a motor forward?
A diagonal pair sends current through the motor one way; the other pair sends it the other way.
-
A motor runs on 12 V at 50% PWM duty. What voltage does it average?
0.5 × 12 V = 6 V.
-
Why does an L298N get hot?
2.5 V × 1 A = 2.5 W turned to heat, which is why it carries a large heat sink.
-
What does a DRV8825 drive?
It drives a bipolar stepper’s two coils, in full steps down to 1/32 microsteps.
-
A DRV8825 board’s reference reads 0.75 V. What is its current limit?
I = 2 × 0.75 V = 1.5 A per coil.
FAQ
What is the difference between the L298N and L293D?
Both are dual H-bridges; the L298N handles about 2 A per motor and needs external diodes, which modules include, while the L293D handles 600 mA with diodes built in.
Can I run a motor driver from an Arduino’s 5 V pin?
Its logic, yes, but not the motor: give motors their own supply and join only the grounds, or the motor’s current and noise can reset the Arduino.
Why does my motor driver get hot?
Its transistors waste the voltage they drop times the current. An L298N loses about 2.5 W at 1 A; a MOSFET driver such as the TB6612FNG loses much less.
How do you reverse a motor’s direction with a driver?
Swap the levels on its two direction pins, such as IN1 and IN2 on an L298N; the H-bridge then switches the other diagonal pair.
What is a motor speed controller?
A circuit that sets a motor’s speed, usually by PWM through a transistor or H-bridge. Brushless motors need an electronic speed controller, or ESC, that also times their coils.