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

Get Arduino Development 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.