analogWrite(PWM, 0);
//wait 1 second
delay(1000);
}
Code to Note
language:cpp
digitalWrite(DIR_A, HIGH);
digitalWrite(DIR_B, LOW);
analogWrite(PWM, 255);
The Motor Driver uses a control logic that works by pulling certain pins
HIGH or LOW (pins 4 and 5 in this case) to change the direction of the
motor’s rotation and then send a PWM signal to pin 6 to control the speed.
This chunk of code runs to motor in one direction at full speed.
digitalWrite(DIR_A, LOW);
digitalWrite(DIR_B, HIGH);
analogWrite(PWM, 150);
This chunk of code is similar, but changes the direction by flipping the
direction pin’s state and setting the PWM pin at a slower speed.
digitalWrite(DIR_A, LOW);
digitalWrite(DIR_B, LOW);
analogWrite(PWM, 0);
This final chunk of code demonstrates the logic for stopping or “braking” the
motor by pulling both direction pins to the same state. In this case we used
LOW, but both set to HIGH would produce the same results. In a brake, the
PWM level doesn’t matter. We set it to 0 as more of a formality than
anything. If not, see the Troubleshooting section below.
What You Should See
You should see the motor spin in one direction at full speed for one second,
then brake (stop) for one second, and run at a slower speed for a second in
the opposite direction and and then repeat.
Troubleshooting
Motor Not Spinning
Make sure that you have the enable pin as well as the logic and PWM pins
wired correctly. It’s easy to make a wiring error, as the names of the pins of
the board are on the bottom.
Double check that you have wired the standby pin to 3.3V! Without it, the IC
is in standby mode.
Page 53 of 63