Connecting stepper motor to power source causes mis-positioning

I'm using a Leonardo together with an EasyDriver to control a stepper motor.

I'm observing something interesting when connecting or disconnecting the stepper motor to a circuit: the motor will hop one step. This occurs, for example, when I connect the 12v power supply for the motor or when I connect the USB cable of the Leonardo to my computer. In either case this initial burst of current causes the motor to hop a step. If I hesitate when plugging in the USB cable, and keep the cable only partly connected, I can get the motor to hop several steps in succession.

This suggests that the motor is getting a charge and thereby pulling to the next magnet.

This is a big problem. The motor will be mounted within an enclosure to drive a pulley system and precisely rotate an object to one of 3 set positions. The object weighs very little and will therefore cause almost no load on the motor. This initial hop will throw out the alignment for the function of the machine. Over time (10 to 20 connections/disconnections of the USB cable) the initial hop could lead to a radical mis-positioning.

Is there some electronic component that I could integrate into this circuit that would prevent this initial hop? Or, do I just have a cheap motor? Or, should I be using a different controller?

I want the machine to be able to start at exactly the same point at which it was left.

All stepping motors work like that, it depends on what coil was energised when it was last connected and what coil the driver is energising now. When they don't match there is a step when you first power it up.

You need a function (probably called from setup()) that zeros the position of the motor - usually by driving it until the thing it moves triggers a microswitch or an optical detector.

This also deals with the situation where someone has manually disturbed the machine while the power was off.


A powered down stepper motor no longer has any positional control, so you always
have to calibrate/home a stepper-based positioning system at power-up.

Mike, Robin and Mark, thanks for the input!

I was resigned to resetting the motor on startup and had begun to work on coding the reset, when I came across something that greatly reduces the hop.

Up until now, my sketch never used the Sleep function of the Easy Driver and the Sleep pin had never been connected to my Arduino. In thinking about the reset, I was considering implementing a 'sleep' and so connected the Sleep pin. As I plugged the USB cable into the computer, I noticed that the hop was practically imperceptible. Previously, without the Sleep pin connected, I was able to produce hops in the range of several millimetres when plugging in the USB or 12v power cables.

This suggests that connecting the Sleep pin somehow dissipates the initial surge of electricity when first connected. Extrapolating this further, if position accuracy is vital to a project, one could make a case for physically connecting all pins of the Easy Driver even if they will not be used programatically.

When connecting the Sleep pin to the Arduino (without the intention of explicitly using Sleep in the sketch), I've found that it is necessary to programatically write the pin LOW in setup, or the Easy Driver will automatically set it to HIGH and keep the motor in sleep mode.

I've found that it is necessary to programatically write the pin LOW in setup

You could always physically wire that input pin to ground.