Controlling stepper motor

Hello everyone!

To begin with, I am fairly new to electronics, so you might want to prepare for a little dose of ignorance.

Anyway, I’ve bought a stepper motor for a project, and currently I’m trying to learn how it works. So what I’m trying to do is making the motor turn continuously by applying a sequence of signals to the motor’s four wires.

When I run the program, however, the motor just goes back and forth in a very small angular interval.

The motor I am using is a 42BYGHM809 (bipolar, 4 wires)
Data sheet: http://www.electrokit.com/productFile/download/2610

My code and circuit are attached as files!

code.ino (579 Bytes)

Never supply current to a motor directly from the Arduino pins. They're too weak for that and something will probably get damaged beyond repair.

Use an appropriate motor driver.

Thanks for the reply!

When you say the arduino's too weak, what is it you are referring to then?
In the data sheet it says the motor requires 3v, and I've made sure, using a multimeter, that the voltages over the motor coils are 3v. Given the resistances of the motor coils are 1.8 ohm, the currents through the motor coils ought to be 3/1.8 = 1,7 A, right?

Doesn't this mean that the voltage and current supplied to the motor are enough, according to the data sheet? Or am I missing something?

The Arduino pins indeed work at 5V (or 3.3V with some rare models), but the current they are able to handle (source/sink) is very limited, up to 40mA at best - and not many pins at the same time, too.

So if you have, say, a motor that takes 1A for free rotation, that's 25 times what the Arduino can give - and the board doesn't have any protections so the microcontroller will probably burn.

Take a look at eBay or maker sites, there are hundreds of "stepper motor drivers" to choose from. These take their "commands" from the Arduino pins but transfer the actual power to the motor(s) from a different source, e.g. a strong battery.

Have a look at the Thread stepper motor basics

...R

Never ever connect Arduino pins directly to a motor because its a highly inductive load - you
risk burning out all the pins from inductive kick-back, let alone over-current.

I would expect that some or all of those pins are now degraded in performance or dead. You should go and check them out with a resistor and LED, check each pin can both
source and sink current to the LED under command and switches off as expected.

A 4-wire stepper motor needs a stepper driver circuit to drive it, set to the appropriate
current level (here 1.7A). Something like a DRV8825 board would be able to go upto
perhaps 1.5A, which is good enough. To spin fast you'll need a high voltage supply, 24 or 36V, but for slower speeds a 12V supply will suffice.

Bipolar stepper motors are not very easy to drive, for that there are unipolar motors.
Bipolar motors can be high performers though, driven correctly.

It is with great relief I can inform you that my Arduino Uno still seems to work as usual! For a while there I feared I’d have to go for an Arduino Dos!

Thanks for scaring the sh*t out of me, though. I’ll definitely try to be more careful with what I do in the future.

I looked at some drivers for the motor I possess, and in the store I buy my components, the BigEasyDriver v. 1.2 seemed, to me, to be the best alternative. Do you think this one would work? (Unfortunately I don’t have a data sheet, and the product page is in Swedish, so… yeah.)

skaldjurskompass:
the BigEasyDriver v. 1.2 seemed, to me, to be the best alternative. Do you think this one would work? (Unfortunately I don't have a data sheet, and the product page is in Swedish, so... yeah.)

Did you read stepper motor basics? It is intended to enable you to answer that question.

The BigEasydriver can handle up to 1.4 amps. What does your motor need?

...R

Yes, Robin, I did read it through, and thank you for it. I really wish I'd found that thread earlier!

I suspect we've looked at different versions of the BigEasyDriver, because it says the one I've looked at can run motors that require up to 2A (link: http://www.electrokit.com/big-easy-driver-2a-stegmotorstyrning.49152)

I found this schematics-pdf-thingy too, where it also states it can handle 0-2A, so I don't think it's a typo on the store's website. (schematics: http://www.electrokit.com/productFile/download/2981)

I think there will be a bit of "suck-it-and-see" if you want to drive a 2 amp motor. I have seen opinions saying you can and you can't. I'm pretty sure you will need a heatsink, and maybe a cooling fan. The Pololu DRV8825 has a little more headroom.

Of course your application might work fine with the current set below the motor's maximum.

...R

skaldjurskompass:
Thanks for scaring the sh*t out of me, though. I’ll definitely try to be more careful with what I do in the future.

I’m glad its still working, but its a classic error - unless you know to treat inductive loads
differently you don’t realise the danger. Basically an inductor will generate whatever voltage
is necessary to prevent current changing suddenly, which can be hundreds, even thousands
of volts - and thus death to semiconductors.

Fortunately the Arduino pins are relatively rugged, but you have probably degraded the
protection diodes on the pins, since they will have born the brunt of the switching transients,
but they aren’t essential to the functioning of the pins.

Everywhere you look in electronics where motors are concerned you’ll see specialist
motor drivers and controllers which are protected with free-wheel diodes or other
protection circuitry and which are designed for the current levels involved (always much
higher than signals).