Hi. I tried to code in a way that when the potentiometer was turned, the NEMA 17 stepper motor will also turn together. When I did that, it works. However, when let say I turn the potentiometer and release, the motor does stop but jitters (chacha dance). Is there any way that I could stop the motor from jittering?
// This is the code that I use//
const int direction_pin = 25;
const int step_pin = 26;
const int pot_pin = 34; //analog input 1
int readvalue=0;
int current_position=0;
void setup()
{
Serial.begin(115200);
pinMode(direction_pin, OUTPUT);
pinMode(step_pin, OUTPUT);
pinMode(pot_pin, INPUT);
}
void loop()
{
int readvalue = analogRead(pot_pin);
Serial.println(readvalue);
if (readvalue > current_position)
{step_motor_forward();
current_position += 1;
}
else if (readvalue < current_position)
{
step_motor_back();
current_position -= 1;
}
}//end of loop
void step_motor_forward()
{
digitalWrite(direction_pin, LOW);
delay(2);
digitalWrite(step_pin, HIGH);
delay(2);
digitalWrite(step_pin, LOW);
}
void step_motor_back()
{
digitalWrite(direction_pin, HIGH);
delay(2);
digitalWrite(step_pin, HIGH);
delay(2);
digitalWrite(step_pin, LOW);
}
If You would post the schematics things might show up.
So far it looks okey.
What does the serial print tell? Any wobbling numbers there?
Aha. General mistake to run motor current through a breadboard. They are designed for signals, not motor power.
so how does the connection supposed to be then? because I am using the A4988 motor driver though.
Aha. I saw it and I get it. When performing an analog read You always face "the last bit uncertainty", a wobbling last bit.
Divide the reading by, lets say 4, and then multiply by 4. That filters out the least 2 significant bits of the analog read.
const int direction_pin = 25;
const int step_pin = 26;
const int pot_pin = 34;
int readvalue=0;
int current_position=0;
void setup()
{
Serial.begin(115200);
pinMode(direction_pin, OUTPUT);
pinMode(step_pin, OUTPUT);
pinMode(pot_pin, INPUT);
}
void loop()
{
int readvalue = analogRead(pot_pin);
readvalue = ((readvalue/4)*4);
Serial.println(readvalue);
Serial.plotln
if (readvalue > current_position)
{step_motor_forward();
current_position += 1;
}
else if (readvalue < current_position)
{
step_motor_back();
current_position -= 1;
}
}//end of loop
void step_motor_forward()
{
digitalWrite(direction_pin, LOW);
delay(2);
digitalWrite(step_pin, HIGH);
delay(2);
digitalWrite(step_pin, LOW);
}
void step_motor_back()
{
digitalWrite(direction_pin, HIGH);
delay(2);
digitalWrite(step_pin, HIGH);
delay(2);
digitalWrite(step_pin, LOW);
}
is it something like this?
Exactly! Did You try it?
yes, I did try it. the values do not wobble very much. thank you. just that the motor still jitters.
Running stepper power through a breadboard is no, no to me. They are designed for signals, now motor power. Batteries increase the hazard. They mostly have trouble delivering stepper currents.
meaning to say I need to have an external power supply, rather than the battery, connected straight to the A4988 Motor Driver's pin? do mean this?
Yes. That would give a much better situation.
But... Check the current setting in that unknown driver You use.
You have not told what driver You use. I hope not any ULN....
noted with thanks. the driver I use is A4988.
The same as I use, I think. Keep an eye on its temperature. I use heatsinks and a cooling fan.... 12 volt driver supply....
thanks for the help. much appreciated.
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

