Hi everyone,
I'm very new to Arduino but I want to build a pickup winder, here is my problem:
my project is using
- an A4988 stepper driver
- a NEMA17 stepper motor (model 17HS4023, 1,8 step angle, 12V, 0,7/phase, 4 wires); Vref screw is set to 0,48V
- a 10K potentiometer
- an Arduino uno
For this project I used the codes on this page https://miliohm.com/how-to-drive-a-stepper-motor-easily-using-a4988-and-arduino/, and my wiring follows the diagram shown in that page.
The first code works very well, I can modify the stepDelay time in microseconds and it effectively changes the speed of the stepper, I can go to 320 microseconds and that's about the speed I actually want for my pickup winder.
Here's the code:
// Define pin connections & motor's steps per revolution
const int dirPin = 2;
const int stepPin = 3;
const int stepsPerRevolution = 500;
int stepDelay=2000;void setup()
{
// Declare pins as Outputs
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
}
void loop()
{
//clockwise
digitalWrite(dirPin, HIGH);// Spin motor
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(stepDelay);
digitalWrite(stepPin, LOW);
delayMicroseconds(stepDelay);
}
delay(1000); // Wait a second//counterclockwise
digitalWrite(dirPin, LOW);// Spin motor
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(stepDelay);
digitalWrite(stepPin, LOW);
delayMicroseconds(stepDelay);
}
delay(1000); // Wait a second
}
Citation
My problem is that I want a potentiometer to control the speed of the stepper. To do that I hooked up a potentiometer as shown in the diagram, and put it on A0;
the monitor is reading the values between 0 and 1023 and effectively converts to 10000 to 0 in terms of microseconds stepDelay. I didn't change anything in the wiring except the presence of the potentiometer. And yet ... the stepper is very very slow, even at maximum speed: when the potentiometer is turned all the way down, monitor reads 0 and stepdelay is at 10000, and all the way up 1023 and 0, but the motor runs way way slower than that.
I tried to tweak the numbers to get close to what I would use in the real situation (2500 microseconds to 400), but the stepper still doesn't turn at the desired speed (and it also seems to rattle a lot).
Here is the second code:
// Define pin connections & motor's steps per revolution
const int dirPin = 2;
const int stepPin = 3;
const int stepsPerRevolution = 500;
int stepDelay = 700;void setup()
{
// Declare pins as Outputs
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
//clockwise
digitalWrite(dirPin, HIGH);
int pot = analogRead(A0);
stepDelay=map(pot, 0, 1023, 10000, 0);
Serial.println(stepDelay);
// Spin motor
digitalWrite(stepPin, HIGH);
delayMicroseconds(stepDelay);
digitalWrite(stepPin, LOW);
delayMicroseconds(stepDelay);
}
What am I doing wrong, or what am I missing?
At this stage I could probably start using this project as a winder, without a speed knob, but it's kind of frustrating to know that I'm only a few steps away from making it work!
Thanks everyone !