NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Basic Electronics » Controlling Stepper Motors

June 16, 2012
by mcguinnessdr
mcguinnessdr's Avatar

I was looking around, and it sounds like I could just hook up a stepper motor to a microcontroller with a ULN2803 and it would work without any other components. Is this correct? How would I go about programming it to control the speed and position? Thank you for any help!

June 16, 2012
by missle3944
missle3944's Avatar

mcguinnessdr,

I did this about a year ago, Yes you could do that. Fairly simple, as long as you know what wires go were! The code I used was fairly simple. Turn off a pin, turn on next. just repeat that for a full rotation. To determine the speed just alter the delay_ms between each step. A bigger delay between each step means slower rotation, smaller delay between steps means faster rotation

-Dan

June 16, 2012
by mcguinnessdr
mcguinnessdr's Avatar

Since I have a 12v stepper that I salvaged out of a printer, can I just hook the com port on the ULN2803 to the positive of a 12v wall transformer? What do I connect the ground of the ULN2803 to? Since the ULN2803 has 8 control pins, I should be able to hook 2 4-wire steppers up to it fine? Also, if I connect the wires of the stepper in the wrong order will it have any adverse effects, or can I just guess and check the configuration until the motor turns? Sorry for all the questions, and thank you for all the answers, I just want to make sure it will work and I don't break anything!

June 16, 2012
by missle3944
missle3944's Avatar

Mcguinnessdr,

The common pin (aka com) goes to ground. Can you show us the stepper motor you are using. Because I pulled mine out of an old dot matrix printer and it might be similar. I had a good schematic of it online but I'll look for it and try to post it.

-Dan

June 16, 2012
by mcguinnessdr
mcguinnessdr's Avatar

It's a Mitsumi M42SP-6TG. I can't find a datasheet for it, but it should be similar to this. I have some other kinds lying around too. So how would I hook the ULN2803 to us 12v? Thanks!

June 16, 2012
by Ralphxyz
Ralphxyz's Avatar

Well first what type of Stepper motor do you have?

The reference link has Com as being positive not ground!

I have a upcoming project where I was going to use stepper motors so I got these steppers off ebay and I got these Stepper Motor Drive controllers L298N

Now I know Rick likes the L298N.

I am kinda pressed for time so figured using a controller would save some time.

The seller gave this truth table for operations for the stepper motor.

Which of course leads to more questions.

The stepper motor I have is a Bipolar 2phase four wire stepper.

So what do you have?

Ralph

June 16, 2012
by mcguinnessdr
mcguinnessdr's Avatar

It's 4 wire, and I think it is a bipolar 2 phase since that's what the similar motor I could find on the internet is. What would be the easiest way to control this motor? I'm pretty new to electronics, so please take that into account. Thanks for the help.

June 17, 2012
by Ralphxyz
Ralphxyz's Avatar

Because I am pressed for time I went with the stepper motor controllers I listed above.

I am having an off day from my outside work so I should be able to put some working code together today, or at least that is my plan.

I'll post my code, and questions I am sure, later today.

4 wire bipolar 2phase is what I have so we should be good to go!

Ralph

June 17, 2012
by mcguinnessdr
mcguinnessdr's Avatar

Your links aren't working (they are pointing back to this same page), so I can't tell whether you are talking about the L298N by it's self, or the L298N Driver board. It seems like the ULN2803 is cheaper, so what is the advantage of using the L298N? You said you were pressed for time, so how is the L298N quicker to use than the ULN2803?

June 17, 2012
by Ralphxyz
Ralphxyz's Avatar

Stepper Controller

There I even tested the link so it is working for me.

So for $5.56 I get a complete stepper controller which uses the L298N.

If I bought the individual pieces it "might" cost less but I would have to make up a PCB and assemble it. This way as soon as I get my code assembled I will be running.

Ralph

June 17, 2012
by mcguinnessdr
mcguinnessdr's Avatar

But can't you control the stepper with just a ULN2803? Then in the code you just switch the 4 pins on and off in sequence, right? What advantage does the L298N Controller have over just the ULN2803 alone?

June 17, 2012
by Ralphxyz
Ralphxyz's Avatar

Just that the circuit is all made up!

Are you thinking of just using a breadboard?

The controller I am going to use also has 7805 voltage regulator so I can power my Nerdkit from it also.

I didn't even look at the ULN2803 so I do not know if other components are required.

I have the first run at some code for the four wire 2phase bipolar stepper motor.

Would you like me to post it here or start a new thread (maybe both).

I certainly have more questions now.

Ralph

June 17, 2012
by mcguinnessdr
mcguinnessdr's Avatar

I will probably be just running it off a breadboard for now, and if it works I will move it to a pcb. According to this page, it sounds like I just hook up 4 pins on the mcu to 4 input pins on the ULN2803, then the corresponding output pins of the ULN2803 to the stepper motor. If I do this, I then hook up the common pin on ULN2803 to the positive of my power supply and the ground pin to the negative of my power supply. To control the motor I then just switch the pins of the mcu on and off in the right sequence. With my very basic understanding of electronics, this sounds like it should work, but I would appreciate of someone could confirm this. If it does, I will order a ULN2803 or two and start working on my project.

June 18, 2012
by Rick_S
Rick_S's Avatar

While you can defininately drive a stepper easily with a ULN2803, the advantage to the L297/L298 combo of chips is that the stepping is built into the controller and all you do is send a direction signal and pulse. The L297/L298 combo also get feedback from the motors current draw allowing you to give the motor more strength given the proper power supply to feed it. This gives it advantages when using the stepper for something like feed drives for machines or drives for motion on heavier objects.

Building with the ULN2803 is great for seeing the motor spin and learning how to do that. You can also use 4 transistors to drive the motor w/o using a ULN2803.

Rick

June 18, 2012
by Ralphxyz
Ralphxyz's Avatar

What is the ampacity of the ULN2803?

The controller, with the L298 I have has a 3 amp surge start and 2 amp running amps.

Ralph

June 18, 2012
by mcguinnessdr
mcguinnessdr's Avatar

So how would I wire up the L298 Driver with the mcu and stepper? What would my code look like?

June 18, 2012
by Ralphxyz
Ralphxyz's Avatar

mcguinnessdr, search the Nerdkit forum for L298.

I will post my code in a new thread, I am just about to test it for the first time.

Everything leads to more questions so it seems appropriate to start a new thread.

Besides my threads tend to go on for a couple of months as I tend to ask project questions so it is a ongoing conversation/help.

Also you can start developing your code with four LEDs, you do not need a controller or even a stepper motor. So you can start coding today.

Start by laying out some pseudo code.

You can use the led blink project and expand that.

I got a lot of questions but I'll see if my code actually works or even tries to work.

Ralph

June 18, 2012
by mcguinnessdr
mcguinnessdr's Avatar

You said I can start coding by setting 4 leds to blink, but isn't the point of the L298 Driver to control the stepper without using 4 outputs from the mcu? If I still need to switch each of the four outputs from the mcu, what is the advantage over the ULN2803? PS, I can't view your thread at the moment since the device I'm on wont let me use the search function.

June 18, 2012
by mcguinnessdr
mcguinnessdr's Avatar

There is a page or the reprap wiki about what appears to be a similar board, and I think I understand now. I can set the direction pin to tell it forward or reverse, then send a pulse to the step pin to move it one step. Is this correct? If so, I think I will order one of the L298 boards when I get back from work.

June 18, 2012
by Rick_S
Rick_S's Avatar

If you want to use transistors Here's a link for an old floppy drive stepper being controlled.

Rick

June 18, 2012
by mcguinnessdr
mcguinnessdr's Avatar

@Rick_s: What would you suggest I buy? What would you use if it was for your project? I would really like to get something ordered soon so I can start trying to get it set up.

June 19, 2012
by mcguinnessdr
mcguinnessdr's Avatar

I'm just going to order some ULN2803's for now. The project I'm working on is only a prototype, so if the basic design works, I might try some other methods for the finished version.

June 19, 2012
by sask55
sask55's Avatar

One of the major advantages of using stepper motor controller chips to drive a stepper is the current limiting feature built into the controller chips. In many applications where stepper motors are used the maximum available speed and/or turning torque that the motor can safely produce are desired.

The level of toque produced by the motor is directly proportional to the current thru the windings, and the current thru the windings is determined by the voltage used to drive the stepper. The nature of the winding is that they are an inductive load, and as such there is an impendence value to consider. That is to say that any change to the level of current flow thru the coils will be slowed by the induction as well as a limited by the resistance of the coils.

It is very common practice to over drive the stepper coils with a much higher voltage then ohms law I=V/R would allow to attain the maximum current the coil will handle. The issue is that the internal windings of the motor will overheat if the current level thru them is too high, but at the same time it is very desirable to achieve that level of current as quickly as possible to get maximum speed and torque from the motor. When the driver voltage is first applied to the coil the induction within that coil will limit or slow the rate of change of the current. The higher the voltage used to drive the coil the faster the current will reach the maximum current value the coil will handle. Without any additional circuitry to limit the current the coil will quickly overheat as the current rises above the maximum level . This is one of the most valuable functions of the stepper motor controller chips. The Toshiba TB6560AHQ (that I am most familiar with) and the L298N both appear to use external current sensing resistor to allow the chip to sense and then control the current thru the coils.

In short using a current limiting stepper controller chip allows the uses of much higher motor diving voltages and much better motor performance. There are a number of other advantages that may be available with a stepper controller chip depending on the chip. Over heat and over load protection, user selectable torque level control, user selectable micro stepping, a level of fly back current protection to name a few. These features may or may not be of value to the user depending on the application.

Darryl

June 19, 2012
by mcguinnessdr
mcguinnessdr's Avatar

Thank you for all the information! My motor will be running at slow speeds with little torque, so the controller sounds like it might be a little over kill. It definitely sounds useful for other projects, and I will keep it in mind if I ever need that kind of performance and control of the motor.

June 20, 2012
by sask55
sask55's Avatar

You’re welcome.

Keep in mind it may be possible to burn out your motor even if you are using the same power supply voltage as was used in the original printer. I have actually managed to do just that when controlling a stepper from the Nerdkit thru transistors. The original printer circuitry likely incorporated a level of current limiting on the motor drive in order to allow overdriving of the motor and better performance.

If your application will involve the motor being active for extended periods of time (ie many seconds or even minutes the motor may still over heat) regardless of the speed. In fact a motor that is stalled or stopped but with current running in one or more coils will be at the most risk of overheating.

If you are interested in what would be he highest “safe” driver voltage you can use for long periods of time you can work it out using the motor data sheet info. I have found that many salvaged steppers have enough information printed on them to locate a data sheet on line, especially if they originated from an older piece of hardware. You will find that the motor will have a stated coil resistance value, max voltage value and max coil current value. If you do the math using ohms law (I=V/R) you may find that the max voltage will drive far more current then the coil is rated to handle. The motor would over heat and burn out if you actually maintained that max voltage for anything longer then a few seconds.

I have found that motors will often run even if I am overdriving them for extended periods of time, sometimes very warm. I just thought that I would point out these considerations in cases you are interested in making a durable long term motor drive.

Darryl

June 20, 2012
by mcguinnessdr
mcguinnessdr's Avatar

I found another motor that says 5.1v and 1.0amp, so I am thinking this would be a better choice since I should be able to run it off the USB, right? This motor shouldn't overheat, should it?I was in Radioshack today, hoping to get some transistors so I could get my project running without having to wait for parts to ship. Sadly they didn't have enough in stock though. So I'll order a ULN2803 and will have to wait a week to get it going since I will be gone next week.

June 20, 2012
by sask55
sask55's Avatar

I think that this link will answer many of your original questions stepper control

You will have to consider that you do not intend to control the stepper from a parallel port but from your Nerdkit micro pins. Just substitute the output pins from the Nerdkit in where the output pins from the parallel port are on this link. Most if not all of your other questions are covered in this web link. With regards to the two motors you have mentioned, it is difficult to find information about the M42SP-6TG but it seams it may have a coil resistance of 10 OHMS. If you have access to a VOM meter you could test this coil resistance to verify this value. I have no way of knowing what the coil resistance of the 5.1 V motor is. It is possible that you will be able to run either of these motors as you have described. You will need to do some calculations to determine how much current your motor will draw and if the other components can handle that current.

First of all I would be very careful about how much current I was trying to draw from the USB port. I am unfamiliar with what the current supply capability of a typical USB port is or what the consciousness of over loading would be. Wikipedia specifies USB output at 500-100 mA I would certainly not push it past that level. Personaly I would not use the USB power as a power source for a stepper for fear that the current draw may damage the USB. This may be over cautious, but wall wart type power supplies are inexpensive and widely available. I would not risk damaging anything in a computer no mater how unlikely the chances are that it may happen.

Going thru an example of the type of consideration you may wish to do, using the Mitsumi motor.

If the motor coils do have a resistance of 10 ohms and you apply a 12 volt power source to it, using I=V/R or 12V / 10 Ohms. = 1.2 amps.

A ULN2803 is rated at 500 mA Continues current, I can not varifiy the current rating of the motor but I suspect it will be considerable smaller then1200mA. Based on this information I do not believe that either the ULN2803 Darlington array or the motor coils will last long with a 12 Volt supply voltage to the coils. All this assumes that your power supply is capable of actually producing 1.2 amps. Most small wall wart type supplies will not produce anything near that much current and therefore the power supply itself may be at risk of over heating rather then the motor. Or the entire system may just work well as the supply voltage drops do to the fact that the supply is not capable of producing sufficient current to damage any of the other components. You could consider protecting the ULN2803 chip by using two of the outputs pins on the ULN2803 in parallel for each coil to handle twice the current this does noting to protect the motor coils or the power supply.

I imagine this may be getting to be more then you where hoping for, but there are a number of factor that come into play. I have often ignored all the calculations and just wired up a small stepper motor to a 2803 using a small wall wart power supply. The results do vary. You would be risking the stepper motor coils, possibly the ULN2803 chip, even the power supply. My guess that is it will work for at least short intervals maybe for long runs as well, it usually does. Depending on your personal tolerance to risk and your acceptance of the possibilities of trial and error you could just follow the general ideas covered in the link above. I think it will likley work, there are to many unknowen factors to consider,especially concerning the characteristics of the power supply. There are no guaranties there is also a posibliy that you will just get some smoke and be looking for more parts.

Darryl

June 20, 2012
by sask55
sask55's Avatar

I think I may have misled you in the last post. I see now that the Mitsumi motor is most likely a Bipolar motor (ie it has only four wires). All of the motors that I have used a ULN2803 to drive have bean unipolar motors (having 5 or 6 wires). You will require an H-bridge circuit to control a bipolar motor, as you will require the ability to change the polarity of the power applied to both ends of both windings. This is not as simple as I have lead you to believe. I have controlled a couple of bipolar motors in the past but always using a motor controller chip to handle the H-bridge function.

If this is the case and you do have a bipolar motor then, I believe that you will have to do one of these thinks, locate a unipolar motor (they are very common) or a bipolar motor controller chip (many are available for these small current motors) or build a H-bridge circuit from discrete components (may be interesting but not to practical)

Sorry about my assumption about the motor you have. It kind of got me off track.

Darryl

June 20, 2012
by mcguinnessdr
mcguinnessdr's Avatar

Thank you once again! I will look over that link when I have some time. I didn't even think of overheating being a problem, so I'm glad you pointed that out. I have a hard time getting my head around how electricity actually work. I understand that it's electrons flowing, with the current basically being the amount and the voltage the speed (I don't think that's quite accurate, but it's the best way I can think of it). But I don't understand how everything plays together when designing a circuit. I guess I just need to do more reading and experimenting until I finally get it.

June 21, 2012
by Rick_S
Rick_S's Avatar

Just a note, I wouldn't drive a stepper motor off the USB port of your computer. Only specific devices that communicate with the computer telling it they need more than the 100ma default current output get more than 100ma. Your stepper is likely to draw more and could cause problems. An independant power supply is ALWAYS recommended when driving motors or any high current device.

Rick

June 21, 2012
by mcguinnessdr
mcguinnessdr's Avatar

@sask55: You posted while I was posting, so I didn't see your last message. I guess I'll have to go research h-bridges now.

@Rick_s: I will probably use a wall adapter instead, or maybe a 9v battery if that would work?

June 21, 2012
by mcguinnessdr
mcguinnessdr's Avatar

So what would you guys suggest I use to control this? would this controller that Ralphxyz work, or do I need something else?

June 21, 2012
by Ralphxyz
Ralphxyz's Avatar

mcguinnessdr, I have compiled code as outlined in my Stepper Motor Programming thread but so far can not get the motor to step/run using the controller that I have.

I believe Rick made up a controller using the L298N with a L297N so he should have the circuit he used.

I will let you know when I get my motor running.

In looking at the L297N specsheet it looks like a good way to go( the l297N/L298N combination). I will probable make up this circuit next.

Actually I am wondering if I need to add a L297N to the controller I have.

Ralph

June 21, 2012
by sask55
sask55's Avatar

That controller should work very well.

A nine volt battery will not last very long powering a stepper motor.

I would find a wall wart type power supply. DC, low voltage power supplies are very common. In fact I have about 15 of them in a drawer that I have collected over the years when some small electric device was discarded. You can buy them for just a few dollars at surplus and discount sellers. It would be best to use one with a max current supply rated high enough to handle the motor load.

Just a comment about voltage, resistance and current

Voltage is better described a pressure not speed. Voltage can be thought of as the difference in electromagnet pressure between two points. The higher the voltage the larger the pressure difference is. Given a pathway (conductor) a current will flow from the high pressure point to the lower pressure point ie from the higher voltage point to the lower voltage point. The current is a reference to how much electricity is move thru a point in the circuit. Therefore there is often a voltage without any current. A battery sitting not connected to anything will still have a voltage between the terminals but no current will be flowing anywhere. Connect a resistor between the terminals and the voltage will push, or pull if you like, a current thru the resistor. The smaller the value of the resistor the more current is able to flow because resistance is a reference to the restriction of flow of electricity. I have seen many analogies made describing the flow of electricity to that of a liquid like water, there are a lot of web pages that take that approach.

Darryl

June 21, 2012
by mcguinnessdr
mcguinnessdr's Avatar

Thank you for your explanation! I think I'll get that controller and try it out, hopefully I can get it to work.

Post a Reply

Please log in to post a reply.

Did you know that multiple microcontrollers can communicate with each other? Learn more...