Book Image

Raspberry Pi Zero Cookbook

Book Image

Raspberry Pi Zero Cookbook

Overview of this book

The Raspberry Pi Zero, one of the most inexpensive, fully-functional computers available, is a powerful and revolutionary product developed by the Raspberry Pi Foundation. The Raspberry Pi Zero opens up a new world for the makers out there. This book will give you expertise with the Raspberry Pi Zero, providing all the necessary recipes that will get you up and running. In this book, you will learn how to prepare your own circuits rather than buying the expensive add–ons available in the market. We start by showing you how to set up and manage the Pi Zero and then move on to configuring the hardware, running it with Linux, and programming it with Python scripts. Later, we integrate the Raspberry Pi Zero with sensors, motors, and other hardware. You will also get hands-on with interesting projects in media centers, IoT, and more.
Table of Contents (17 chapters)
Raspberry Pi Zero Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

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 previous recipe.

How to do it...

This recipe's schematic is a bit simpler than the previous one, as there is less you have to control with a DC motor.

  1. You'll also add in the AA battery pack:

  2. Controlling the DC motor is similar to controlling LED brightness...