When using the Arduino, there are many projects and things that you can do with it and one of them includes driving a motor! Today, through this tutorial, we will be focusing on the 3 basic motors that you can drive with the Arduino which are the DC motor, Servo motor, and Stepper motor.

Today’s guide will cover:

  • Introduction to DC, Servo and Stepper Motor
  • When to use each motor?
  • Getting Started with Seeed’s Arduino Motor Pack
  • Arduino DC Motor Tutorial
  • Arduino Servo Motor Tutorial
  • Arduino Stepper Motor Tutorial

Introduction to DC, Servo and Stepper Motor

DC Motor

  • Also known as Direct Current, the DC motor converts electrical energy into mechanical energy in order to run.
  • When current is passed through, opposite polarity between the two magnetic fields inside the motor causes it to spin continuously in one direction until the current stops.
    • DC motors have no polarity (Unless marked with + or -), which means you can reverse the direction of the motor by swapping the two wires.
  • Basically, when a DC motor two leads (positive and negative) are connected directly to a power source, the motor will rotate and in a direction. When the leads are switched, the motor will rotate in the opposite direction
  • They consist of:
    • Stator
    • Armature
    • Rotor
    • Commutator with Brushes
  • DC motors are used widely in many places. Some of them are your vacuum cleaner, hair dryer, elevators, electric windows in cars, etc.
  • DC motors are still used commonly due to its high starting torque (Able to deal with high resistive torques and absorb sudden rises in load effortlessly), simplicity and also efficiency compared to other motors.

Servo Motor

  • The Servo motor is a rotary actuator that allows for precise control of angular position which makes them suitable for use in closed-loop systems where precise position control is needed and is commonly used in electronics.
  • Servo motors are part of a closed-loop system and they are a self-contained electrical device that rotate parts of a machine with high efficiency with great precision.
  • Servo Motors are made up of:
    • Control Circuit
    • Small DC Motor
    • Potentiometer
  • They are attached by gears to the control wheel where when the motor rotates, the potentiometer resistance changes so the control circuit can precisely regulate how much movement there is and in which direction.
  • The motor is controlled with an electric signal, either analog or digital, which determines the amount of movement which represents the final command position for the shaft.
    • With its closed-loop mechanism, it incorporates positional feedback to control the rotational or linear speed and position. A variety of angles are set upon, and there is a notation for an angle of operation of 120 degrees.
  • As Servo Motors are high in efficiency and power, they are used in many applications like robots, airplanes and also in industrial and commercial applications where precise position control is needed.

Stepper Motor

  • Stepper motor is a brushless, synchronous electric motor that converts digital pulses into mechanical shaft rotation. They are basically DC motors that move in discrete steps.
    • Every revolution of the stepper motor is divided into discrete angular movements and steps where the motor must be sent a separate pulse for each movement.
    • The stepper motor can only take one step at a time and each step is the same.
    • With a computer-controlled stepping, you can easily achieve precise positioning and/or speed control.
    • This feature makes stepper motors very suitable for precision motion control applications
  • They consist of multiple coils that are organized in groups called “phases”.
  • The stepper motor is a digital input-output device and they are suitable for projects and applications where control signals appear as digital pulses rather than analog voltages.
  • One digital pulse to a stepper motor drive or translator causes the motor to increment one precise angle of motion. When digital pulses increase in frequency, the step movement changes into continuous rotation.
  • One application of the stepper motor will be in robots where if you want a robot arm or leg to move to an exact angle so it can grab something like a bottle, a stepper motor would be perfect! Compared to other motors, you cannot control the angle of the arm or leg but instead, it will depend on the power of the motor and the amount of electric current passing through it.
  • Stepper motors are also used in machines (eg.pick and place machine), robotics, automated wire cutting, wire bonding machines, precise fluid control devices, etc.

When to use each motor?

When using different motors in your Arduino projects, you must pick the most suitable motor that meets your needs. Each motor has its own uses, advantages, and disadvantages which we are going to cover.

DC Motor

Advantages of DC motor

  • Speed control over a wide range both above and below the rated speed.
    • With the DC motor, you can achieve speed control over a wide range both above and below the rated speed through methods like armature control method and field control method. This allows DC motors to be suitable for fine speed applications such as rolling mills.
  • High starting torque
    • With DC motors high starting torque, they are very suitable for driving heavy loads in starting conditions. An example of DC motors application would be in electric trains and cranes.
  • Do not have harmonics
    • Compared to other motors with harmonics, DC motor are more efficient and have a longer lifespan.

Disadvantages of DC motor

  • Speed control and regulation of DC motors are not as good compared to servo and stepper motors.
  • Not suitable for use in explosive or hazardous conditions as there may be sparking occurring at the brush which results in a risk of commutation failure.
  • Increased operation and maintenance cost due to presences of commutator and brush gear.

Servo Motor

Advantages of Servo motor

  • High output power relative to motor size and weight
  • High efficiency
    • Can approach 90% at light loads
  • Feedback for controlling the speed and torque.
  • Encoder determines accuracy and resolution.
    • Encoder Utilization provides higher accuracy and resolution with closed-loop control.
  • High Torque to inertia ratio
    • Servo Motors can rapidly accelerate loads.
  • Resonance and vibration-free operation
  • High-speed operation is possible
    • Servo motors can achieve high speed at high torque values

Disadvantages of Servo motor

  • Requires tuning to stabilize feedback loop.
  • Servo motors are unpredictable when something is broken
    • Thus, safety circuits are required.
  • Complex controller requires encoder and electronic support.
  • Servo Motor can be damaged by sustained overload
    • Peak torque is limited to a 1% duty cycle
  • Cost can be higher than that of stepper motor
    • The requirement for feedback components can increase the overall system cost and installation cost which may be higher compared to stepper motors.
  • Gearboxes are often required to deliver power at higher speeds.

Stepper Motors

Advantages of Stepper motor

  • Excellent low speed torque
    • Stepper motors offer excellent low speed torque. This allows the motor to drive many loads without having to utilize any additional gearing or gearbox mechanisms.
  • Safer
    • Compared to Servo motors, if the stepper motor breaks, it will stop automatically
  • Longer life
    • Many moving parts of the stepper motor are frictionless. With this, stepper motors are considered to have a longer life as the bearings of the stepper motor will be the only part suffering from wear and tear.
    • They are also very reliable as there are no contact brushes in the motor.
  • Lower cost compared to Servo Motors
    • Stepper motors are used in an open-loop system that does not require positional or torque feedback which makes it simpler and less costly to control.
    • They are also easier to set up and use. Compared to servo motors, they are better suited for low acceleration and high holding application.
  • Low speed with High precision
    • Compared to DC motors who do not have much torque at lower speeds, a stepper motor offers maximum torque at low speeds.

Disadvantages of Stepper motor

  • Low Efficiency
    • Unlike DC motors, stepper motor current consumption is independent of load. They draw substantial power regardless of load.
    • When stepper motors are idle, they draw the most current which causes them to run hot.
  • No feedback
    • Compared to servo motors, stepper motors have no integral feedback for the position.
    • Even though you can achieve precision through running open loop, limit switches or ‘home’ detectors are normally required for safety and/or to establish a reference position.
    • Without feedback, you cannot indicate potential missed steps.
  • Torque drops rapidly with speed / Limited High Speed Torque
    • Stepper motors have less torque at high speeds than low speeds.
    • Even though some stepper motors are optimized for better high-speed performance, they have to be paired with an appropriate driver to achieve that performance.
  • Low torque to inertia ratio
    • This means that stepper motors are unable to accelerate loads very rapidly.
    • In high-performance configurations, the motor can also get very hot.

Getting Started with Seeed’s Arduino Motor Pack

Before we move on to the tutorials, you will need the motors! Here at Seeed, we offer our very own Arduino Motor Pack!

  • This pack is a perfect kit for motor learning with Arduino.  Whether your project requires a DC motor, a stepper motor, or a steering gear, it can be found in this kit!
  • This kit consists of
    • 6V DC motor(13000 rpm ±14%)  x2
    • Small stepper motor x1
    • Standard servo  x1(Speed: 0.17/60°@4.8V; 0.14/60°@6.0V)/(Torque: 3.5kg.cm@4.8V;  4.8kg.cm@6.0V)
    • Micro servo  x1(Speed: 0.12/60°@4.8V; 0.10/60°@6.0V)/(Torque: 1.5kg.cm@4.8V;  1.8kg.cm@6.0V)
  • Feel that the kit is too expensive? No worries!

Currently, we are having a big sale on this Arduino Motor Pack for a limited time only!!!

Use code: MOTOR40 to get 40 percent off our Arduino motor pack now!

Without further ado, let us jump right into how to run the individual motors with the Arduino!

Arduino Motor Tutorial

Before we start, do note that you shouldn’t drive any motor directly from Arduino board pins as this may damage the board! You should use a driver circuit or motor driver to drive them!

Arduino DC Motor Tutorial

In this tutorial, we will be using an Arduino motor shield to drive the DC motor:

  • The Motor Shield is a driver module for motors that allows you to use Arduino to control the working speed and direction of the motor.
  • It is Based on the Dual Full-Bridge Drive Chip L298, it is able to drive two DC motors or a step motor. If you do not know what is L298, you can check out our other blog on L298 motor driver here!
  • So how do you drive a DC motor with an Arduino motor shield?

What do you need?

Step by step instructions on how to drive DC motor with Motor Shield

  • Step 1
    • Set SEN_A and SEN_B and connect the left 2 pins together with a jumper.
  • Step 2
    • Connect MB_EN together with a jumper, as we are not going use an external power.
  • Step 3
    • Connect DC motor to Chanel 0 (OUT1 and OUT2) and plug Motor Shield into Arduino.
    • Connect Arduino to PC via a USB cable.
    • Your connection should look like this:
  • Step 4
  • Step 5
    • Upload the following code to Seeeduino:
//  Demo function:The application method to drive the DC motor.
//  Author:Loovee (luweicong@seeed.cc)
//  2016-3-11

#include "MotorDriver.h"

MotorDriver motor;

void setup()
{
    // initialize
    motor.begin();
}

void loop()
{
    motor.speed(0, 100);            // set motor0 to speed 100
    delay(1000);
    motor.brake(0);                 // brake
    delay(1000);
    motor.speed(0, -100);           // set motor0 to speed -100
    delay(1000);
    motor.stop(0);                  // stop
    delay(1000);
}
// END FILE

Your motor should move for 1 second, stop for another second, move back for 1 second, stop for a second and loop. If nothing happens, please make sure:

  • The code has been uploaded successfully
  • The motor is connected properly
  • The LED indicators blink right

That’s all! You have managed to run a DC motor with an Arduino Motor shield in 5 steps!

Arduino Servo Motor Tutorial

Through this tutorial, you will learn how to control a Servo Motor with your Arduino in 3 simple steps.

What do you need?

Step by step instructions on how to drive a Servo Motor with the Arduino

  • Step 1: Connect Servo to the Seeeduino
    • The Servo has three wires: power, ground, and signal.
    • The power wire is typically red, and should be connected to the 5V pin on the Arduino/Seeeduino board.
    • The ground wire is typically black or brown and should be connected to a ground pin on the Arduino board.
    • The signal pin is typically yellow, orange or white and should be connected to D5 on the Arduino board.
    • You can change to the digital port as you like, but don’t forget to change the port number in the definition of the demo code!
  • Step 2: Connect the Module to the PC
    • Connect the module to D5 port of Base Shield
    • Plug Grove-Base Shield into Arduino
    • Connect Arduino to PC via a USB cable.
  • Step 3: Software
    • We will be sweeping the shaft of a servo back and forth across 180 degrees by using the Arduino Servo Library.
    • Open the code directly by the path: File -> Examples ->Servo->Sweep.
/* Sweep
 by BARRAGAN <http://barraganstudio.com>
 This example code is in the public domain.

 modified 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Sweep
*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(5);  // attaches the servo on pin 5 to the servo object
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

And you are done! After uploading the sketch, you should see the Servo sweep.

Arduino Stepper Motor Tutorial

In this tutorial, we will be using the Gear Stepper Motor Driver Pack which includes a stepper motor and a motor driver board. It’s a four-phase eight-stepping stepper motor, and you can easily control this stepper motor via the drive board. You can also use this pack for position control.

What do you need?

Step by step instructions on how to drive a Stepper Motor with the Arduino

  • Step 1
    • Connect the Gear Stepper Motor Driver Board to your Seeeduino via the jumper cables
Seeeduino V4.2Gear Stepper Motor Driver board
Digital Pin 8
IN1
Digital Pin 9IN2
Digital Pin 10 IN3
Digital Pin 11IN4
GNDGND
VCC_5VVCC
VCC_5VVM

You can connect the VM pin to VCC_5V or you can just do not use it as long as you choose the VCC in the switch.

  • Step 2
    • Plug the stepper motor into the Gear Stepper Motor Driver Board.
  • Step 3
    • Connect Seeeduino to PC via a USB cable.
    • Your connection should look like this now:
  • Step 4
    • Copy the following code into a new sketch in the Arduino IDE.
int pwm1=9;
int pwm2=10;
int ctr_a =9;
int ctr_b =8;
int ctr_c =11;
int ctr_d =10;
int sd =6;
int i=0;
int t=1500;

void setup()
{
    //pinMode(sd,OUTPUT);
    //pinMode(pwm1,OUTPUT);
    //pinMode(pwm2,OUTPUT);
    pinMode(ctr_a,OUTPUT);
    pinMode(ctr_b,OUTPUT);
    pinMode(ctr_c,OUTPUT);
    pinMode(ctr_d,OUTPUT); 
    delay(1);
    //digitalWrite(sd,HIGH);
    //digitalWrite(pwm1,HIGH);
    //digitalWrite(pwm2,HIGH);
//    digitalWrite(ctr_a,LOW);
//    digitalWrite(ctr_b,LOW);
//    digitalWrite(ctr_c,LOW);
//    digitalWrite(ctr_d,LOW);

}


void loop ()
{
//   for(i=1500;i>=1;i--)
//   {
//       digitalWrite(ctr_a,HIGH);//A
//       digitalWrite(ctr_b,LOW);
//       digitalWrite(ctr_c,LOW);
//       digitalWrite(ctr_d,LOW);
//       delay(t);
//       digitalWrite(ctr_a,HIGH);
//       digitalWrite(ctr_b,HIGH);//AB
//       digitalWrite(ctr_c,LOW);
//       digitalWrite(ctr_d,LOW);
//       delay(t);
//       digitalWrite(ctr_a,LOW);
//       digitalWrite(ctr_b,HIGH);//B
//       digitalWrite(ctr_c,LOW);
//       digitalWrite(ctr_d,LOW);
//       delay(t);
//       digitalWrite(ctr_a,LOW);
//       digitalWrite(ctr_b,HIGH);
//       digitalWrite(ctr_c,HIGH);//BC
//        digitalWrite(ctr_d,LOW);
//       delay(t);
//       digitalWrite(ctr_a,LOW);
//       digitalWrite(ctr_b,LOW);
//       digitalWrite(ctr_c,HIGH);//C
//       digitalWrite(ctr_d,LOW);
//       delay(t);
//       digitalWrite(ctr_a,LOW);
//       digitalWrite(ctr_b,LOW);
//       digitalWrite(ctr_c,HIGH);//CD
//       digitalWrite(ctr_d,HIGH);
//       delay(t);
//        digitalWrite(ctr_a,LOW);
//       digitalWrite(ctr_b,LOW);
//       digitalWrite(ctr_c,LOW);//D
//       digitalWrite(ctr_d,HIGH);
//       delay(t);
//        digitalWrite(ctr_a,HIGH);
//       digitalWrite(ctr_b,LOW);
//       digitalWrite(ctr_c,LOW);//DA
//       digitalWrite(ctr_d,HIGH);
//       delay(t);
//       
//   }
//       digitalWrite(ctr_a,LOW);
//       digitalWrite(ctr_b,LOW);
//       digitalWrite(ctr_c,LOW);
//       digitalWrite(ctr_d,LOW);
//   
//   
//   
//     for(i=1500;i>=1;i--)
//   {
//     
//       digitalWrite(ctr_d,HIGH);//D
//       delay(t);
//       digitalWrite(ctr_c,HIGH);//DC
//       delay(t);
//       digitalWrite(ctr_d,LOW);//C
//       delay(t);
//       digitalWrite(ctr_b,HIGH);//CB
//       delay(t);
//       digitalWrite(ctr_c,LOW);//B
//       delay(t);
//       digitalWrite(ctr_a,HIGH);//BA
//       delay(t);
//       digitalWrite(ctr_b,LOW);//A
//       delay(t);
//       digitalWrite(ctr_d,HIGH);//AD
//       delay(t);
//       digitalWrite(ctr_a,LOW);
//       digitalWrite(ctr_d,LOW);
//   }

   for(i=1500;i>=1;i--)
   {
       digitalWrite(ctr_a,LOW);//A
       digitalWrite(ctr_b,HIGH);
       digitalWrite(ctr_c,HIGH);
       digitalWrite(ctr_d,HIGH);
       delayMicroseconds(t);
       digitalWrite(ctr_a,LOW);
       digitalWrite(ctr_b,LOW);//AB
       digitalWrite(ctr_c,HIGH);
       digitalWrite(ctr_d,HIGH);
       delayMicroseconds(t);
       digitalWrite(ctr_a,HIGH);
       digitalWrite(ctr_b,LOW);//B
       digitalWrite(ctr_c,HIGH);
       digitalWrite(ctr_d,HIGH);
       delayMicroseconds(t);
       digitalWrite(ctr_a,HIGH);
       digitalWrite(ctr_b,LOW);
       digitalWrite(ctr_c,LOW);//BC
        digitalWrite(ctr_d,HIGH);
       delayMicroseconds(t);
       digitalWrite(ctr_a,HIGH);
       digitalWrite(ctr_b,HIGH);
       digitalWrite(ctr_c,LOW);//C
       digitalWrite(ctr_d,HIGH);
       delayMicroseconds(t);
       digitalWrite(ctr_a,HIGH);
       digitalWrite(ctr_b,HIGH);
       digitalWrite(ctr_c,LOW);//CD
       digitalWrite(ctr_d,LOW);
       delayMicroseconds(t);
        digitalWrite(ctr_a,HIGH);
       digitalWrite(ctr_b,HIGH);
       digitalWrite(ctr_c,HIGH);//D
       digitalWrite(ctr_d,LOW);
       delayMicroseconds(t);
       digitalWrite(ctr_a,LOW);
       digitalWrite(ctr_b,HIGH);
       digitalWrite(ctr_c,HIGH);//DA
       digitalWrite(ctr_d,LOW);
       delayMicroseconds(t);

   }
//       digitalWrite(ctr_a,HIGH);
//       digitalWrite(ctr_b,HIGH);
//       digitalWrite(ctr_c,HIGH);
//       digitalWrite(ctr_d,HIGH);
//   


//     for(i=1500;i>=1;i--)
//   {
//     
//       digitalWrite(ctr_d,HIGH);//D
//       delay(t);
//       digitalWrite(ctr_c,HIGH);//DC
//       delay(t);
//       digitalWrite(ctr_d,LOW);//C
//       delay(t);
//       digitalWrite(ctr_b,HIGH);//CB
//       delay(t);
//       digitalWrite(ctr_c,LOW);//B
//       delay(t);
//       digitalWrite(ctr_a,HIGH);//BA
//       delay(t);
//       digitalWrite(ctr_b,LOW);//A
//       delay(t);
//       digitalWrite(ctr_d,HIGH);//AD
//       delay(t);
//       digitalWrite(ctr_a,LOW);
//       digitalWrite(ctr_d,LOW);
//   }


}
  • Step 5
    • Upload the demo. If you do not know how to upload the code, please check our tutorial here on How to upload code.
    • If everything is uploaded properly, the motor should run like this:

Summary

That’s all on how to get started with Arduino motors – DC, Stepper, Servo Motor! The Arduino has always been popular when it comes to running motors and today we have just covered 3 of them! If you have any questions on how to drive a DC, Servo or stepper motor using the Arduino, please feel free to leave them down in the comments below!

Interested in our actuators and motor products? You can check out all of our motor products here!

Please follow and like us:
error