Sub topic 3
Current ratings, voltage drop, and heat
This chapter assumes you know Ohm's law, can read a wiring diagram, and have used pinMode, digitalWrite, and analogWrite on an Arduino.
Current ratings, voltage drop, and heat
A stalled motor draws much more current than a free-running one. Compare the driver's continuous rating with the motor's running current, and its peak rating with the stall current. The driver also drops some voltage across its switches, so the motor receives less than the supply voltage. That lost power becomes heat, roughly P = I × V_drop.
Wiring and programming the driver from an Arduino
Connect IN1, IN2, and EN to three Arduino pins. EN must be a PWM pin. Connect the Arduino GND to the driver ground and the motor supply ground.
const uint8_t IN1 = 7;
const uint8_t IN2 = 8;
const uint8_t EN = 9;
void setup() {
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(EN, OUTPUT);
}
// speed: -255 (full reverse) to 255 (full forward)
void setMotor(int speed) {
speed = constrain(speed, -255, 255);
digitalWrite(IN1, speed > 0);
digitalWrite(IN2, speed < 0);
analogWrite(EN, abs(speed));
}
void loop() {
setMotor(200);
delay(2000);
setMotor(0);
delay(1000);
}Reversing direction and ramping speed safely
Do not switch from full forward to full reverse in one step. The sudden current reversal stresses the driver and the gearbox. Step the speed toward zero, then step it up in the new direction.
Choosing a PWM frequency
On an Arduino Uno, EN pins 9 and 10 run at about 490 Hz by default. That rate can whine audibly and make the motor stutter at low speed. Frequencies near 20 kHz are above hearing, but the driver switches more often and loses more power as heat.
Sensing current and detecting stalls
Some drivers, such as the L298N, provide a current sense output. Read it with analogRead. If the reading stays above a limit for a set time, stop the motor.
Troubleshooting overheating, resets, and weak torque
- Overheating: The driver may be undersized, or the motor may be stalling. Compare the stall current with the driver rating.
- Resets when the motor starts: The supply sags. Add a bulk capacitor near the motor supply and decoupling capacitors near the driver.
- Weak torque: Voltage drop may be too high, or the PWM duty cycle may be too low.
- Motor does not start: Check the EN wiring and confirm the duty cycle is high enough to overcome friction.
Exercise
A driver has a 1.5 A continuous rating and a motor draws 1.2 A running and 4 A stalled. Is the driver suitable, and what is the risk?
Show answer
It is suitable for running current, but the stall current of 4 A exceeds the continuous rating. A stall can overheat or damage it, so use a driver with higher peak tolerance, limit stall time with current sensing, or choose a larger driver.