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

Controlling small motors


Controlling a small motor can be very simple. If the motor is small enough, it can be directly connected to the Arduino pin, and simply turning the pin to HIGH or LOW will control the motor.

This recipe will teach you the basic logic of how to control a motor; however, this is not a typical way of connecting a motor to the Arduino. It is recommended that you first understand this recipe and then apply the following one, Controlling motors with transistors.

Getting ready

Following are the ingredients required to execute this recipe:

  • An Arduino board connected to a computer via USB

  • A 220-ohm resistor

  • A very small DC motor—usually a vibration motor will work—that can be found in old (and new) mobile phones or can typically be brought from websites such as Sparkfun or Adafruit

How to do it…

The following are the steps to connect the motor:

  1. Just like other small motors, a vibration motor has two wires. Connect one wire to the Arduino GND pin. It doesn't matter which one, as a...