Thursday, September 13, 2007

Computer Controlled Stepper Motor



A few months ago, I bought a stepper motor for only Rs.75 (about USD $1.50). I had almost forgotten about that motor until I found it lying in a secluded corner of my bedroom, collecting dust the other day. I searched the internet for information on controlling stepper motors with a computer and I was surprised at how easy it was! My stepper motor has five wires, and it is a unipolar stepper motor with a step angle of 7.5 degrees.


Here's the simple circuit I had used for controlling it:

(Note: If you can't find ULN2003, you can simply use use a single transistor for each winding as shown here.)

As you can see in the diagram, each successive coil in the motor is connected to successive data pins on the parallel port. If the coils are not connected in the correct sequence, the motor will not rotate, but will only wiggle from side to side. Identifying the wires on the stepper motor was probably the only time consuming step. Click here for information on how to do this.

Now, since each coil can be programatically controlled, you can experiment with different types of stepping modes. The simplest stepping mode is called Single-Stepping. In this mode, each successive coil is energized and the motor moves one full step at a time. For example, my motor will make a full step of 7.5 degrees whenever the coils are energized in the following sequence (D0 - D3 represent parallel port data pins):

Step No.D0D1D2D3
11000
20100
30010
40001

Another interesting stepping mode is Half-Stepping. The difference between single-stepping and half-stepping is that for the same step rate, half-stepping gives you half the speed but twice the resolution of a single step. Since my motor has a step angle of 7.5 degrees, half-stepping it would result in approximately 3.75 degrees of rotation. Here's the sequence in which coils are energized for half-stepping:

Step No.D0D1D2D3
11000
21100
30100
40110
50010
60011
70001
81001

You can achieve other types of steps by energizing the coils in different ways. For example, here's how high torque stepping works:

Step No.D0D1D2D3
11100
20110
30011
41001

For more information on these stepping modes, read this article.

My program allows me to control the motor with the scroll wheel on my mouse and I can press the right mouse button to switch between different stepping modes. Watch the video above to see it working. I'm still thinking of ways to use this stepper motor with my projects. I guess I could use it as a camera panner. It would be better, efficient and more compact than my floppy drive camera panner. My floppy drive camera panner could only rotate through an angle of 45 degrees because of mechanical limitations. This stepper motor can rotate a camera through 360+ degrees!

Here's something interesting I found while googling - Neil Fraser's "Computerized Etch A Sketch". Neil has used two computer controlled stepper motors for turning the horizontal and vertical knobs on an Etch A Sketch. His work is just amazing! I just wish he posted some videos of the device in action.

41 comments:

Vodka2001 said...

Muy Buena PAGINA, saludos desde argentina.

Very Good PAGE, greetings from argentina.

Scott Hanselman said...

Dude, that kicks butt.

Charith Jayasinghe said...

Hi dude,

ur work is brilliant. I am a student as well as a web programmer from Colombo, Sri Lanka and seeking ur advice for my degree project. I am not much in to hardware interfacing. I want to control a panel of LEDs using either COM or USB port. simply i need to blink the LED which i select from my SW. Will u be able to help me out on this ? Feddback is highly appreciate. Write me to charithj@teamwork.lk or charith@charith.net

Thanks!

OptimusTronic said...

Thanks

this proyects is wonderful

Saludos desde GUatemala!

Anonymous said...

Brilliant!!!!!!!!!!!!!!!!!!!

ris8_allo_zen0 said...

Hello,
I'd like to let you know that some time ago I made a little program to drive unipolar stepper motors in exactly the same way you did; maybe you find it useful. Here is its page: http://freshmeat.net/projects/stepm

Cheers from Italy!
Enrico

Anonymous said...

EXCELLENT! Once in a while you see something that is really cool, and this is one of those! Thanks!

Todd S.

Anonymous said...

I've looked for something like this for ages!

Is it posible to download your software? I can't find a place to download it :(

Ashish Derhgawen said...

Yes, you will find a download link on my article - http://blogs.msdn.com/coding4fun/archive/2007/11/02/5848155.aspx

Happy Stepping! :)

ANKUR said...

Really good info . To the point !

Anonymous said...

Dude...that really rocks..first time i know that stepper motor can be run by computer.. http://stepper-motor.blogspot.com

Ankur said...

hey ! i was wondering how do u power up the stepper motors? i am using 3 stepper motors to design a robotic arm.
Could u suggest me how i power up my 3 motors ?
i need to find a cheap alternative to using standard adaptors .
plz revert back to me soon on this forum or at my mail-id : iamtheone.ankur@gmail.com

Thnx....


ALso , could u gimme which motors i shall buy or d specs for using motors for a robotic arm.
I need low speed high precision stepper motors.
What should be the voltage ratings, step angle and torque ?

Anonymous said...

Hi Ashish,
I'm from Slovakia and I'm really into your work. I wanna ask you how you're programming that motor to control it by mouse wheel and what program do you use for it. Thank's.
PS: Sorry for my english, I'm just learning.

Ashish Derhgawen said...

Hey there,

Read this article on Coding4Fun for information on how to do it - http://blogs.msdn.com/coding4fun/archive/2007/11/02/5848155.aspx

Ashish

Gian said...

hi Ashish,

thanks for this idea, do i still need zener diode for the power of the uln?
i'm using a 2.3v stepper motor and the uln2003 is heating, will this be good or bad for the uln2003?

thanks,,

Ashish Derhgawen said...

Hey Gian,

Could you tell me how much your supply voltage is?

Ashish

Wahala said...

can u send me part numbers and circuit schematic thanks? also need a schematic for a ceilling fan

hazlanbh said...

Dude,
Just for your information, a stepper motor is wound in such a way that the rotation has a certain number of discrete "steps". I only know of stepper motors being DC motors. These steps are where the magnetic fields cause the motor to want to settle in one of these positions. The number of steps per revolution is rather high, around two hundred or so, and varies by model and manufacturer. What this means is that the motor has effectively a resolution (smallest controlled movement) equal to the number of steps for that motor. Everything seems to have exceptions, and that applies to steppers also - there are some called micro step, with a higher resolution, but I don’t know much about them. Stepper motors may or may not have position feedback.

For more information on stepper motor you go this one website that gathers information about stepper motor from around the web :

http://stepper-motor.blogspot.com

shreesh said...

hi ashish,
good works.Hey i needed the tool to know that you are using efficiently in processing the images or motion video captured from webcam,in one of your other projects.And i was trying to use parallel port and glow LEDs.I used assembly language TASM and i tried in C.But i am not ablt to get high at any of the data pins.What may be my problem?

rumi said...

hey
ashish u have done a good job. about ur programing which language do u use. and y didnt u published the programing code for the steprt motor? an u please post the code and can give me ur email add mine is rumieee@gmail.com

Joel M. Pinto said...

Hi,

I'm coming to Delhi on 9th May to visit my relatives and also to buy some components for my experiments. Can you tell me from where can I buy the ULN2003 & NE555 timer ICs in Delhi? I'm going to stay in my aunt's house in Connaught Place. If you agree then I can come to visit you at your home (just give me your address and phone no. in case I need it).I'll be going back on the 13th.

Bye,
Joel Pinto
joel_m_pinto@yahoo.co.in
Navsari, Gujarat, India

Anonymous said...

hi dude.....
im from NU-FAST univ. pakistan....read ur work and found it very interesting ....could u tell me what is the black(usb looking) wire comming from ????it is in one of ur proj. pics.hope ull reply back...thnks..

Ashish Derhgawen said...

The black wire is the 12V power supply for powering the motor.

Chris said...

interesting project! I have one or two motors left over from various bits and pieces, I think I might try to build a computer-controlled stepper motor as well.

Jishnu Dave said...

Hi, don't we have to use pull-up resistors at the ourput of ULN2003? I remember reading somewhere that it's outputs are open collector.. What do you say?

Anonymous said...

Awesome! Amazing work!xw

wanfazlinz said...

hai, im student from UNIMAP malaysia,
i need ur help, i not know much about vb..
can you show me the interface and code of vb that can controlled stepper motor without using mouse..
please help me..

wanfazlinz@gmail.com

blue said...

hey ashish how u doing?
m a student of BCA final yr working on ur stepper motor project. i need ur help regarding the code for controlling its rotation via parallel ports in visual basic. i wud be thankful if u e-mail me. my id-bluephilnature@yahoo.co.in.
c ya!

Anonymous said...

hey!!!!!!!!!!!!!

can u help me providing a circuit to control thrree stepper motors????
the motors will work one by one....
its urgent

spartan said...

hey sup. Listen I want to make a motor controller on my computer so i can controll just a motor not a stepper motor just a nice 5-12 volt motor. I was wondering if you could send me some codes for it or if theres a chip or curcuitry involved you could send me a scematic. It would be much apreciated for feed back and an email back. spartan3.0@hotmail.com tnks.

Silver Phoenix said...

Hello, I am from argentina

I have tried to change your program to use 2 stepping motors with a single mouse ... but I can not make it work to achieve the second.
I used the MouseMove rather than MouseWheel to control x, but it does not work e.Y
Besides I can not do work with the 8 digits instead of 4 ...
You could help with the program in VB?
I Connect 2 uln2803 each with a Stepper. The first to move in X and Y. for the second

The entire project is to make a DV camera with pan and tilt with a single mouse, also in the future I would like to incorporate a webcam and connected to a PC follow the movement of an object and control the whole.


My email: rmzornoza@hotmail.com

Your work is incredible ... I really appreciate your help.

Rodrigo Martín Zornoza

Anonymous said...

wow excellent im from colombia i have 13 years olds

thanks this project is helping
wiht this project i make a blimp

Anonymous said...

hi all,

here is my tiny assembly program which can control stepper motor with / from parallel port of your pc.

Hope it'LL help you guys

http://samet.kilictas.com/2008/12/06/assembly-tutorials-program-controlling-dc-motor-and-stepper-motor-from-parallel-port/

Rahman said...

hey ...i wanted to know using roborealm how do u switch on the data pins of the parallel port do u use the setVariable"outputport1" 1 type statements....

faustine said...

hi t hr asish .... im a doing a project with stepper motor . but i dont hav much idea abt vb.... i need the code to run steppr motor using vb ... so could u send me the code in vb.... my email id is faustine40@gmail.com

birni said...

hey there,

you've accidentally forward-biased the zener/avalance diode in the schematic.

i'm currently using a very similar circuit for my CNC gantry router and it works well.

Prateek said...

ashish that was great yaar but i have a doubt with my stepper motor as i dnt knw which winding is first n which is second & 3,4 so how do i interface it with ULN which wire to which O/P of ULN as microcontroller gives ground only to 1 at a tym can i find the coil number 1,2,34 by any means need help asap or can i get ur cell number

Anonymous said...

Mr ashish. may i know ur email? i'm very like this project. i want to learn about that. this project can be use in my last study. thank's.
this is my email. achienz_88@hotmail.com

Anonymous said...

hi asish .... im a doing a project with stepper motor . but i dont hav much idea abt vb.... i need the code to run steppr motor using vb via parallel port... so could you send me the code in vb.... my email id is gracehskuo@gmail.com

thanks for help!

mohan said...

hiiiiiiiii Ashish,
this is mohan im n engg student ....

in nit karnataka..
im doin project on candy cannon for my mechatronics sub...

i wud like u to help me out ...


wat ever help u cn give ...most welcome..


my id is mohan3001@gmail.com

Rian said...

How do you save this program:
10 REM Stepper Motor Controller
20 PORT = &H3BC
30 STATE = STATE + DIRECTION
40 IF STATE > 4 THEN STATE = 1
50 IF STATE < 1 THEN STATE = 4
60 PRINT STATE,
70 IF STATE = 1 THEN OUT PORT, 3: REM 1100
80 IF STATE = 2 THEN OUT PORT, 6: REM 0110
90 IF STATE = 3 THEN OUT PORT, 12: REM 0011
100 IF STATE = 4 THEN OUT PORT, 9: REM 1001
110 FOR W = 1 TO DELAY: NEXT W
120 X$ = INKEY$
130 IF X$ = "<" THEN DIRECTION = -1: REM Backwards
140 IF X$ = ">" THEN DIRECTION = 1: REM Forwards
150 IF X$ = "?" THEN DIRECTION = 0: REM Stop-locked
160 IF X$ = "-" THEN DELAY = DELAY + 100: REM Slow down
170 IF X$ = "+" THEN DELAY = DELAY - 100: REM Speed up
180 IF X$ <> CHR$(27) THEN GOTO 30
190 OUT PORT, 0: REM 0000 (Stop-free)?
I've tried: .exe, but it closed immediately.