loading
Picture of How-To: Motors
motors.jpg
Servos and Steppers and Gears! Oh my!

Some of our favorite hobbyist electronics utilize motors to mobilize, making them fun and awesome! Including a motor in your project could be challenging, especially if you have never worked with them before.

The following Instructable will explain how motors work, and break down some of the most commonly used kinds of motors.
 
Remove these adsRemove these ads by Signing Up

Step 1: The Fundamentals

Picture of The Fundamentals
Before we can really begin addressing how a motor works, lets focus on what a motor does. A motor uses electromagnetism to create motion, converting electrical energy into mechanical energy.

Magnetic fields produce physical force that can move things. Every magnet has a magnetic field with a north pole and a south pole. If you try to push the north poles of two magnets together, they will repel each other. The same thing happens if you try to push two south poles together. If two poles are the same, they will repel each other. If, however, you play with two magnets and bring the north pole of one close to the south pole of another, they will attract each other and stick strongly together, opposite magnetic poles attract each-other.

An electric motor uses the attraction and repelling properties of magnets to create motion. There are two magnets in a standard electric motor: a permanent magnet, and a temporary magnet. The temporary magnet is a special kind of magnet, called an electromagnet. An electromagnet is created by passing an electric current through a wire. The permanent magnet has a magnetic field (a north pole and a south pole) all the time, but the electromagnet only has a magnetic field when there is a current flowing through the wire. The strength of the wire's electromagnetic magnetic field can be intensified by increasing the current through the wire, or by forming the wire into multiple loops.

In an electric motor, the electromagnet is placed on an axle so it can spin freely inside the magnetic field of a permanent magnet. When an electric current is passed through the wire, the resulting temporary electromagnetic field interacts with the static permanent magnet, and attractive and repelling forces are created. This excitation of the wire, or electromagnet, propel it to spin on its axle, and an electric motor is born.




Motors are classified by having the following properties:
  • There's a permanent magnet (or magnets) around the edge of the motor case that remains static, so it's called the stator of a motor.
  • Inside the stator, there is a wire coil, mounted on an axle that spinsaround at high speed -  this is called the rotor. 

Step 2: DC Motors

Picture of DC Motors
DC motors are in many ways the simplest electric motors. Most DC "brushed" motors operate in the same way. There is a stator and a rotor. The magnets on the stator and a coil on the rotor which is magnetically charged by supplying current to it. The presence of brushes (static, permanent mechanisms) within the motor, which propel the electromagnetic rotor forward.

Utilizing a DC power source, very few controls are needed. Speed of the motor can be controlled by the amount of current reaching the coils from the battery to the commutator.

If you reverse the leads, or wires, coming off of the motor - the motor will spin the opposite direction as it was previously.

Step 3: Stepper Motors

Picture of Stepper Motors
StepperMotor_web.gif
Like the other motors we have previously discussed, a stepper motor consists of a rotor and a stator. Unlike the other motors, the stepper motor's rotor is a permanent magnet that rotates inside a cage of electromagnets. The stator is made up of multiple coils that which are mounted in the motor's case. When current passes through these coils, the rotary shaft of the motor (which is a permanent magnet) aligns itself according to pole of energized electromagnetic coil. When motor coils are energized in a particular sequence, the motor shaft aligns itself according to pole of coils, and rotates.

The rotor is propelled by sequentially applying a pulsed voltage to these coils. The coils in the stator-casing drive the permanent magnet rotor by alternating which coil has an electromagnetic current running through it. The stepper motor steps at a specific resolution for each pulse.


Stepper motors are an excellent choice for your hobbyist needs for many reasons. They are often an inexpensive way to mobilize your project, they rarely have any kind of mechanical failure, and they are ideal for open loop positioning control. When you terminate the current running through the electromagnetic coils, stepper motors will hold their position firmly when they are not spinning.


These motors are designed to spin continuously, forwards or backwards. If you hook the battery leads of a stepper motor up to a battery, the axle will spin. If you reverse the leads, it will spin in the opposite direction. There are some stepper motors that are wired to prohibit this from happening, so just verify what kind of motor you have before you try omni-directional rotation.

Step 4: Servo Motors

Picture of Servo Motors
The typical servo motor is designed to sweep, and hold, at any position beteween 0-180 degrees of rotation. This makes them ideal for robotics and projects that complete simple motions, or gestures. (think of the deer that people mount in their front yards during winter that look like they are looking around) Industrially, servos are used to provide actuation for various mechanical systems such as the steering of a car, the control surfaces on a plane, or the rudder of a boat, and even focusing mechanisms in most modern cameras.

Servo motors will most often have three wires: power, ground, and signal. The power wire is typically red, the ground wire is typically black or brown. The signal wire is typically yellow, orange or white. 

In radio controlled servos, like steering systems on RC cars, an electric motor is mechanically linked to a potentiometer. A standard RC receiver sends pulse-width modulation (PWM) signals to the servo, through the signal wire. The electronics inside the servo translate the width of the pulse into a position. When the servo is commanded to rotate, the motor is powered until the potentiometer reaches the value corresponding to the commanded position.

The control signal is a digital PWM signal with a 50 Hz frame rate. Within each 20 millisecond(ms) timeframe, an active-high digital pulse controls the position. The pulse nominally ranges from 1.0 ms to 2.0 ms with 1.5 ms always being center of range. Pulse widths outside this range can be used for "overtravel" -moving the servo beyond its normal range. This PWM signal is sometimes (incorrectly) called Pulse Position Modulation (PPM).

A servo pulse of 1.5 ms width will typically set the servo to its "neutral" position or 90°, a pulse of 1.25 ms could set it to 0° and a pulse of 1.75 ms to 180°. The physical limits and timings of the servo hardware varies between brands and models, but the neutral position is almost always at 1.5 ms. 

Step 5: Vibrating Motors

Picture of Vibrating Motors
Vibrating motors are commonly found in mobile devices, and are frequently used as means to covertly signal the occurrence of an action.

Vibrating motors are constructed in the same way many as DC and stepper motors, except at the end of their rotors, they have a counter weight extending off of the edge. As the rotor spins, the counter weight is 'thrown' in a circular motion causing the entire mechanism to to shake.

The intensity of vibration depends on the size of the motor, as well as the counterweight.



Above we see a motor that is fixed to a piece of sheet metal. Notice how the sheet metal undulates at the vibrating motor spins.

Step 6: Where to start?

Picture of Where to start?
Selecting which kind of motor you will need for your project will be based how you are hoping to automate your piece. If you are seeking to attach a camera to a motor to pan left to right, a servo motor will be ideal. If you are trying to drive gears forwards or backwards, you will need a stepper motor.

A really excellent intermediate control device to use, is an Arduino, or a like-style microprocessing board. The wonderful thing about these boards is that they are variable input/output devices and can be programed to complete multitude of tasks, including motor automation.

The following steps will outline how you can combine the motors we have already talked about with an interface like the Arduino.

Step 7: Using a Stepper Motor with an Arduino

Picture of Using a Stepper Motor with an Arduino
wireconnect.jpg
stepper arduino_guide.jpg
stepper_oneRevolution.tiff
Working with the Arduino coding platform, there is a wide range of example libraries to get you started. Connecting a stepper motor to an Arduino is a different than connecting a DC motor to the board. Because stepper motors have to pulse in a specific way for the rotor to spin, there is a special Stepper library and function built into the Arduino code platform. You can read more about it here.


Opening the Arduino software, browse to "File>Examples>Stepper>stepper_oneRevolution"

This program drives a unipolar or bipolar stepper motor, by attaching the motor to digital pins 8 - 11 of the Arduino. After the sketch is loaded on to the Arduino board, the motor should revolve one revolution clockwise, then one revolution moving counter-clockwise.

The example code is an excellent point to start from, you can certainly make edits to the sketch to suit your needs. The delay is listed in microseconds, so if you want there to be no break between it's revolutions, you can set delay to delay(10). Or if you want it to spin for a long time you can change stepsPerRevolution to equal = (1000000) 

How you modify the sketch will depend on what you are trying to accomplish with the motor. Playing with some of the other sketches in the example sketch library will help you develop a greater understanding of how stepper motors are able to communicate with Arduino Boards.

Step 8: Using a DC Motor/Vibrating Motors

Picture of Using a DC Motor/Vibrating Motors
dcmotorcircuit.jpg
Using a DC motor/Vibrating motor without an arduino:

Some of your project needs will not require you to use a microprocessor like an Arduino. If you are making a plushy toy for a kid(or adult), and want to embed a vibrating motor within it, its probably best to just have a simple push-button circuit to activate the motor.

In that instance the motor would be wired directly to your power source - with a momentary switch wired to your positive lead from the motor. 


Step 9: Using a Servo Motor with an Arduino

Picture of Using a Servo Motor with an Arduino
breadboard.jpg
duino.jpg
knob code.tiff
Just like the stepper motors, servo motors have a dedicated code library within the Arduino Platform.

Opening the Arduino software, browse to "File>Examples>Servo>Knob"

This program drives a servo motor, by connecting the motor to PWM pin 9 of the Arduino, and a the potentiometer to analog 0. The potentiometer will determine the position of the servo by sending a variable resistance current to the A0 port on the Arduino, which the Arduino code then interprets to a pulsed signal to the servo. After the sketch is loaded on to the Arduino board, the motor will rotate based on the position that the potentiometer is turned to. 
 



1-40 of 67Next »

do servos have noise issues like motors do? and are there low limits on current that the arduino can supply to drive them i.e. what servos suit?

iamakidilam made it!2 months ago

thanks! i did it with a 1m pot., before uploading the code, the servo swept. some cracking sound were there. its okay i guess

WIN_20150520_202522.JPG
coldneutron3 months ago

You're an inspiration with excellent support. Something else that may be of interest is the control of the steppers on V2 shields though a sensor. I needed such a program and I have attached a compiled sketch below:

#include <Wire.h>#include
<Adafruit_MotorShield.h>#include
"utility/Adafruit_PWMServoDriver.h"

#Define PotIn = 0

// Create the motor shield object with
the default I2C addressAdafruit_MotorShield
AFMS = Adafruit_MotorShield(); //
Or, create it with a different I2C address (say for stacking)//
Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x60);

//
Connect a stepper motor with 200 steps per revolution (1.8 degree)//
to motor port #1 (M1 and M2)

// Connect a stepper motor with 200 steps
per revolution (1.8 degree)//
to motor port #2 (M3 and M4)Adafruit_StepperMotor
*myMotor1 = AFMS.getStepper(200, 1);Adafruit_StepperMotor
*myMotor2 = AFMS.getStepper(200, 2);

int potinPin = (A0); //assigns pin
for potentiometer readingsint
stepsPin = 2;//assigns pin for stepper motor steps

int previous = 0;//to store initial potentiometer values

int Val = 0;//to store new potentiometer values

int stepsValue = 0;

int potinValue = 0;

void setup() { Serial.begin(9600);

//
set up Serial library at 9600 bps

AFMS.begin(); // create with the default
frequency 1.6KHz
//AFMS.begin(1000); // OR with a
different frequency, say 1KHz
myMotor1->setSpeed(10); // 10 rpm

myMotor2->setSpeed(10);// 10
rpm }void
loop() {potinValue = analogRead(potinPin); //Reads sensor
stores first value

previous = map(potinValue, 0, 1023, 0, 544); //Turns ohms into steps

delay (500);

potinValue
= analogRead(potinPin); //Reads new sensor stores value

val = map(potinValue, 0, 1023, 0, 544); //Turns ohms into steps

//
conditional statements determining movement and direction

if(val
== previous){// if potentiometer didn’t
register movement

stepsValue
= 0; // steps equal zero

}

else
if( val > previous){//if potentiometer moves clockwise

stepsValue
=(val – previous); //steps move motor forward microsteps

myMotor1->step((stepsValue),FORWARD,MICROSTEPS);

myMotor2->step((stepsValue),FORWARD,MICROSTEPS);

}

else(val
< previous){ //if potentiometer
moves counterclockwise

stepsValue
=(previous – val); // steps move motor backward microsteps

myMotor1->step(stepsValue),BACKWARD,MICROSTEPS);

myMotor2->step(stepsValue),BACKWARD,MICROSTEPS);

}

}

coldneutron3 months ago

You're and inspiration. Something else that may be of interest is the control of the stepper motors on the V2 motor shields by a sensor. I needed such a program and wrote the sketch below:

#include <Wire.h>#include
<Adafruit_MotorShield.h>#include
"utility/Adafruit_PWMServoDriver.h"

#Define PotIn = 0

// Create the motor shield object with
the default I2C addressAdafruit_MotorShield
AFMS = Adafruit_MotorShield(); //
Or, create it with a different I2C address (say for stacking)//
Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x60);

//
Connect a stepper motor with 200 steps per revolution (1.8 degree)//
to motor port #1 (M1 and M2)

// Connect a stepper motor with 200 steps
per revolution (1.8 degree)//
to motor port #2 (M3 and M4)Adafruit_StepperMotor
*myMotor1 = AFMS.getStepper(200, 1);Adafruit_StepperMotor
*myMotor2 = AFMS.getStepper(200, 2);

int potinPin = (A0); //assigns pin
for potentiometer readingsint
stepsPin = 2;//assigns pin for stepper motor steps

int previous = 0;//to store initial potentiometer values

int Val = 0;//to store new potentiometer values

int stepsValue = 0;

int potinValue = 0;

void setup() { Serial.begin(9600);

//
set up Serial library at 9600 bps

AFMS.begin(); // create with the default
frequency 1.6KHz
//AFMS.begin(1000); // OR with a
different frequency, say 1KHz
myMotor1->setSpeed(10); // 10 rpm

myMotor2->setSpeed(10);// 10
rpm }void
loop() {potinValue = analogRead(potinPin); //Reads sensor
stores first value

previous = map(potinValue, 0, 1023, 0, 544); //Turns ohms into steps

delay (500);

potinValue
= analogRead(potinPin); //Reads new sensor stores value

val = map(potinValue, 0, 1023, 0, 544); //Turns ohms into steps

//
conditional statements determining movement and direction

if(val
== previous){// if potentiometer didn’t
register movement

stepsValue
= 0; // steps equal zero

}

else
if( val > previous){//if potentiometer moves clockwise

stepsValue
=(val – previous); //steps move motor forward microsteps

myMotor1->step((stepsValue),FORWARD,MICROSTEPS);

myMotor2->step((stepsValue),FORWARD,MICROSTEPS);

}

else(val
< previous){ //if potentiometer
moves counterclockwise

stepsValue
=(previous – val); // steps move motor backward microsteps

myMotor1->step(stepsValue),BACKWARD,MICROSTEPS);

myMotor2->step(stepsValue),BACKWARD,MICROSTEPS);

}

}

BabluP8 months ago

does there is no need of driving ic like ULN etc. required with the uno Board to drive the stepper motor??

Jamesx9 months ago

Hi, this tutorial is awesome. I've been looking for the stepper motor depicted in step 6 and 7. Can you please tell me the model number and (if you remember) where you bought it?

audreyobscura (author)  Jamesx9 months ago

I ripped it out of an old printer - sorry.

judemo19641 year ago

Thanks a lot for your time dedicated to this short and clean tutorial

Now motors like this are not a mistery for me

nbtgoat431 year ago

Thank you for your interesting post. I am new to Arduino. bought a starter kit recently. Not even know how to start with yet.

Have bought a .

Stepper Motor Drive Controller Board Module L298N Dual H Bridge DC For
Arduino from
http://www.ebay.com/itm/Stepper-Motor-Drive-Controller-Board-Module-L298N-Dual-H-Bridge-DC-For-Arduino-/181029044810?pt=LH_DefaultDomain_0&hash=item2a262c024a.

The supplier advised me that I can use this as stand alone to drive my

STEP MOTOR 28BYJ-48 5V DC

But failed.

please advise.

Regards

I just want to make a device that runs a motor that will pull a string at a constant rate. It has to be a smooth pull, not a jerky one, and it needs to pull at a variable rate from like one inch per 3 seconds to maybe 2 inches per second. What kind of motor would you recommend? Would I really need to have an Aurduino board or could I hook up a battery directly to it somehow?
mars_crash1 year ago
Thx for the great instruction!
but how come my arduino restarts when I turn the knob to fast? can this be solved or is something broken? it seems like when the servo moves to fast it restarts I'm not sure what's going on, hope to hear from you.
audreyobscura (author)  mars_crash1 year ago
Huh. That's strage! I wonder why.... I imagine that it is incapable of processing analog data that quickly.
qame1 year ago
I built the "world's simplest motor" for my kids. They loved it. Thank you for the idea and the excellent read on motor theory. Good job!
nuwud2 years ago
This worked great for me.
this is one of the most comprehensive tutorial about how to use a stepper motor with arduino board
Awesome illustration for a stepper motor!
This is a great 'able, Audrey. Thanks!
lemaxnut2 years ago
Thank you for your very clear explanation of the various motor types and the videos. I have saved it in my grandsons' "favourites" for the time when they will study this subject. I have already made them many toys using all these motor types - I favour PICAXE as I think BASIC is easier to learn for kids.
ssgsteiner2 years ago
very nice, great info and put together well.
jolizo2 years ago
Hello.
I would be very happy if someone could help me where I can find servo motor.
I mean, I usually enjoy myself dismounting printers and scanners. And I have never seen a motor like that.

att,

Jolizo
Hobbyking is a good source.
Alderin2 years ago
While this is a good rig to experiment with and learn about stepper motors, be careful about the load you put on your Arduino. Steppers and DC Motors can send spikes of current back to the controlling circuitry when switching from on to off due to inductance, as well as possibly drawing more current than your Arduino is designed to supply. For more permanent projects you should get or build a motor control board to isolate the more delicate logic circuits.
dlemke2 years ago
A stepper motor seems to be a regular motor, except it's segments are separated, unlike a regular motor where the segments are wired in a series to make the motor run at a constant speed and no controller is needed other than the volts/amps. Now this may be very simplified, but would this be accurate?
WelderGirl2 years ago
DavAnt- thanks for that interjection, I was specifically looking to see if the TD62003AP was an acceptable Darlington substitute for the ULN2003. Appreciated!
coolnits3 years ago
I new to complex circuits and arduino. Wat is arduino?.
And do u program arduino with a computer?
if yes - Which language ?

Plzz answer.

----- curious beginner
Coolnits,
Arduino is a microcontroller (like a mini, programmable computer)
You program it using the Arduino IDE (the arduino program-writing software)
You can go to Arduinio.cc for a LOT of good information about the Arduino.
It is programmed in C / C++

-Ryan
Coolnits, Arduino is a very powerful microcontroller which is based on an opensource platform. The website www.hackaday.com can fill you in. Seems to be ONE of the up and coming nextgen controllers. Free software downloads, free manuals and tutorials too! I have it on my wish list but have yet to actually try one or do any work with one, so I can't tell you much more other than it is based on Object Oriented Code. What's that? Dunno. Yet. I do get the Idea that it is quite popular with techies who dive deep. Good luck.
Nirgal383 years ago
I got the link to this the day after I'd finally figured out how to get a stepper working with my Arduino.

Timing is everything. :)
Arkyro Nirgal383 years ago
You should use a ULN2003 IC to drive stepper motors using the arduino! If i am not wrong it is a darlington array..
DavAnt Arkyro3 years ago
Yes, I got a stepper out of an old UMAX scanner, and it is controlled through a Toshiba TD62003AP, which is a Darlington array. There are also some smd capacitors to smooth it out I guess
airborne823 years ago
If you don't want to pay for a Arduino board and you know a little about electronics, you can build a stepper motor controller from a 555 timer IC, a 4017 decade counter IC and a ULN 2003 Darlington transistor array. To adjust the speed simply put a potentiometer ( the higher the resistance, the slower it goes) between pins 7 and 8 of the 555 timer IC. The direction can be changed using a DPDT switch from the output of the ULN2003. This works simplest when running 3 phase stepper motors which are commonly used in aviation. There isn't much information on the net about 3 phase stepper motors and how to run them, but I combined knowledge about the 3 ICs and many schematics.
I have to correct myself. To adjust the speed, put a potentiometer between pins 2 and 7 of the 555 timer IC.
Where can you get the small axle?
This is a great starters tutorial for motors! It would be a perfect entry for the teachers-contest!
I Agree
Are you the Jeff Yates from (Paravet-Computers are here Co)
The inventor of Mr Salty water chlorinator and the Originater of the First Usuable Chineses Computer Keyboard. In which case please take credit for realising my basic theory with Barry to take the stepper motor to its 1,000 degree. If I remember right that took 6 months and $30,000 to realise, congradulations, Student 6 of 20 pass
nice presentation,because you have done so well and like experimenting.
History back in the eighties they wanted stepper motors to go beyond 1.5-3 degrees I offered a solution . by oscillating the fields with different wave lengths and forms,1,000 th of one degree was achievable using the same motors..Keep up the good work.
skrubol3 years ago
The brushes are just part of the commutator. They're the switch that keeps the coil at the right polarity to keep spinning. They don't propel anything.

Also I agree with Clemtasm. A constant voltage across an 'ideal' motor will give constant speed with varying load. In real motors the speed drops with higher load due mostly to the resistance of the windings.
Arkyro skrubol3 years ago
When the load on the motor increases the current consumed by the armature will also increase hence the flux will increase. Speed in inversely proportional to flux. So the speed of the motor has to decrease with increase in load over a constant load. Even in case of an ideal DC motor. Please let me know if I am wrong.
1-40 of 67Next »