Hello everyone,
My classmate is currently working on a stepper motor, but we cant get the stepper motor tot turn in both directions, one direction works instant, other direction makes a sound but does not turn.
This is the video, and he has copied everything exactly as shown in the video
Thanks
const int stepPin = 5;
const int dirPin = 2;
const int enPin = 8;
void setup() {
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(enPin,OUTPUT);
digitalWrite(enPin,LOW);
}
void loop() {
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
for(int x = 0; x < 800; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1000); // One second delay
digitalWrite(dirPin,LOW); //Changes the direction of rotation
for(int x = 0; x < 800; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1000);
}
This is the exact schema of how we connected it.
That is the problem, it stays around 3.8V, it doesnt switch
Disconnect the stepper driver and measure pin 2.
I have your code running and an LED on pin 2 with a resistor and it is blinking ON and OFF.
I suspect using micro second delay has something to do with it.
I will post you a code to try in a minute.
Tom...
1 Like
Hi,
Try this code, I edited yours to slow everything down and added some serial prints.
When you upload to the UNO, open the monitor in the IDE, make sure it is set for 115200 baud.
See what happens.
const int stepPin = 5;
const int dirPin = 2;
const int enPin = 8;
void setup()
{
Serial.begin(115200);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(enPin, OUTPUT);
digitalWrite(enPin, LOW);
}
void loop()
{
digitalWrite(dirPin, HIGH); // Enables the motor to move in a particular direction
Serial.println("direction pin HIGH");
for (int x = 0; x < 100; x++)
{
digitalWrite(stepPin, HIGH);
delay(50);
digitalWrite(stepPin, LOW);
delay(50);
Serial.print("Step number ");
Serial.println(x);
}
delay(1000); // One second delay
digitalWrite(dirPin, LOW); //Changes the direction of rotation
Serial.println("direction pin LOW");
for (int x = 0; x < 100; x++)
{
digitalWrite(stepPin, HIGH);
delay(50);
digitalWrite(stepPin, LOW);
delay(50);
Serial.print("Step number ");
Serial.println(x);
}
delay(1000);
}
Tom...
PS, Can you post link to data/spec of your stepper motor please?
We tried a lot of different settings, but it doesnt make a difference, but i am not working on it right now since i have lessons now
Hi,
Okay, its 9:00pm here, but post your results, if I am not around, others will give you a hand.
An image of your project would help also.
Tom...
PS, What country are you from, I'm in Australia.
I live in Belgium, it's 1pm here lol
This program works perfectly, thanks
Yeah we used your program,but my classmate was working on it so i cant really tell,
Is it possible that the stepper motor has lost power du to the program?
Thanks
Hi,
I would say you were pulsing the stepper with too short a pulse, micro instead of milli seconds.
This would mean you weren't delivering the energy in each pulse for the stepper to turn.
Tom...
I will try this tomorrow and i will let you know
Sorry that i am replying just now but everything works fine, thanks a lot for all the help
1 Like