Simple DC Motor with an Arduino – Part 1

Motor On and Motor Off

Small DC MotorThis article shows how to use an Arduino to power a small dc motor.   Fundamentally we will use the Arduino to alternate between turning the motor on and then off.

A transistor will be use to switch in a ground to the motor and will thus cause it to spin.  This fundamental means of using a micro-controller to control a higher power device is one that you will use over and over.


Parts List

  • P2N2222A Transistor –  You could use a 2N2222 or a PN2222, but you will need to pay attention to the pins. They’re pretty cheap in quantity.
  • 5V DC Motor –  The 5V motor I used is common in toys and hobbies.   You can buy one here
  • Arduino Uno R3 – I generally use the real thing, but the clones can cost you as little as 10 bucks.
  • 2.2K Resistor – Buying a single resistor is silly.  Get a resistor assortment.  One like this will do.
  • Small Diode – I used a 1N4001.  They’re so cheap that getting them in quantity makes sense. Try Here

The Connections

The drawing below shows how to connect it all up.

Simple DC Motor

The Arduino Motor Sketch (or Program)

Just copy this text and run it.

 // Henry's Bench Small DC Motor

int motorDrive = 3;  // The output to the transistor that drives the motor
int onTime = 2500;  //amount of time motor is on
int offTime = 1000; //amount of time motor is off

void setup()
 pinMode(motorDrive, OUTPUT); 

void loop()                     // run over and over again
  digitalWrite(motorDrive, HIGH); // Motor On
  delay(onTime);                // number of milliseconds to keep on
  digitalWrite(motorDrive, LOW);  // Motor oFF
  delay(offTime);               // number of milliseconds to keep off

Leave a Reply

Your email address will not be published. Required fields are marked *