Book Image

Arduino Development Cookbook

By : Cornel M Amariei
Book Image

Arduino Development Cookbook

By: Cornel M Amariei

Overview of this book

Table of Contents (16 chapters)
Arduino Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Spinning motors both ways


It's very simple to control a motor with a transistor. However, spinning the motor in just one direction is not always that useful. It's just half of what is possible. Most DC motors can spin both ways. When we apply the voltage in one direction, the motor will spin on one side. If we reverse the voltage on the terminals, the motor will spin the opposite way. But how can we do that with the Arduino? We need to use an H-Bridge.

Getting ready

Following are the ingredients required for this recipe:

  • An Arduino board connected to a computer via USB

  • An Arduino-compatible motor shield; there is an official Arduino motor shield and a few other options from different companies such as Sparkfun, Pololu, or Adafruit

  • A DC motor

How to do it…

Arduino shields are very useful because they can simply be plugged into the Arduino and everything is already made. We don't need to spend a lot of time routing wires to breadboards and testing. Everything just works.

The following are the steps...