One of my work colleagues has an Arduino kit, that includes amongst other things a stepper motor driver, an ULN2003APG board, and I convinced him to lend it to me.


This weekend I had some time, so I played a bit with it. After reading it’s data sheet, and comparing some examples I found online with other motors; finding those motors data sheets and comparing their coils connections with my motor, I got to this schematic:

And with the tutorial code for stepper motors I got it working. I’ve initially done a revolution test, to make sure I got the number of steps, wiring and direction right. Also I’ve connected 2 multimeters to make sure I have a safe voltage and current. I’ve tested this with several speeds, using the LEDs on the driver board to check the steps order.
Once this was a success, I’ve moved on to connecting this driver to the prototype pillar I’ve made for the 3D printer. I ran the same code with 3 motor revolutions, to have it move the carriage on a longer distance.
After this I’ve noticed a few problems:
- The motor is juddering
- How do I control how much to go up or down?
- The driver board was making it difficult for me to follow the wiring, so I removed the IC and placed it in the breadboard.
I went ahead to solve the second problem first.
I’ve hot glued 2 door switches at the top and bottom of the pillar, so the carriage pushes them when it gets to the top or the bottom. This would trigger a change of direction. I’ve done some tests with a couple of LEDs, to check if this would work. I’ve also added the option to stop the motor (both LEDs on) if both switches are pressed.
Of course I didn’t have the right value resistors (10k) so I used 2 *4 ,7k resistors for each button. Remember I’m building this from what ever scraps I find or can get my hand onto. Eventually, after some tests I got to this schematic:

I forgot to remove the LEDs after the test, so I left them there. No harm in that.
From the first run it was a success. I was thrilled.
Here’s the code I used:
#include
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 9,10,11,12);
const int led_up = 7;
const int led_down = 6;
const int btn_up = 3;
const int btn_down = 2;
int btn_up_state = 0;
int btn_down_state = 0;
enum State {
GOING_UP,
GOING_DOWN,
STOPPED
};
State currentState;
void stopMotor()
{
digitalWrite(led_up, HIGH);
digitalWrite(led_down, HIGH);
currentState = STOPPED;
}
void goUp()
{
digitalWrite(led_up, HIGH);
digitalWrite(led_down, LOW);
currentState = GOING_UP;
}
void goDown()
{
digitalWrite(led_up, LOW);
digitalWrite(led_down, HIGH);
currentState = GOING_DOWN;
}
void moveMotor()
{
switch(currentState){
case STOPPED:
break;
case GOING_UP:
myStepper.step(1);
break;
case GOING_DOWN:
myStepper.step(-1);
break;
}
}
void setup() {
myStepper.setSpeed(150);
pinMode(led_up, OUTPUT);
pinMode(led_down, OUTPUT);
pinMode(btn_up, INPUT);
pinMode(btn_down, INPUT);
stopMotor();
}
void loop() {
btn_up_state = digitalRead(btn_up);
btn_down_state = digitalRead(btn_down);
if (btn_up_state == HIGH && btn_down_state == HIGH)
{ // STOP the motor
stopMotor();
}
else {
if (btn_up_state == HIGH)
{ // Go down
goDown();
}
if (btn_down_state == HIGH)
{ // Go up
goUp();
}
}
moveMotor();
}
Now onto solving the juddering problem.
Since the motor also seems to judger even if it’s not geared to anything, there must be a problem with either how I’m using the Stepper library, or with the library itself. It might be a problem just with this specific motor. I don’t know. I’ve started reading the inner parts of the library, and do some more research.
’till next time!