Connecting a DC motor and controlling its speed and direction

DC motors are not for precision movement like stepper motors are, but useful for things such as running fans or turning motors where you care more about the speed of the rotation than the accuracy. Using the same L293D chip and the same libraries as the previous chapter, we can control a DC motor's speed and direction.

Getting ready

Instead of a stepper motor, you will want a small DC motor. They are pretty easy to tell apart: a stepper motor has 4 or 5 wires (bipolar stepper motors only have 4, and lack the coil center-tap red wire), and a DC motor only has two. You'll also need an external power source for this one--a 4xAA battery pack is perfect. You can use the same L293D from the ...

Get Raspberry Pi Zero Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.