Arduino stepper motor only turning in one direction

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

Hi,
Can you please post your code, in code tags?
Can you please post a schematic of your project, not a Fritzy picture.
An image of a hand drawn circuit would be fine.
Please include ALL power supplies, component names and pin labels.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

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.
IMG-20220523-WA0000

Hi,
That's a Fritzy, but not too bad.
Have you go a DMM to see if you can see the voltage change on the DIR+ pin with respect to GND?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

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... :smiley: :+1: :coffee: :australia:

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... :smiley: :+1: :australia: :coffee:
PS, Can you post link to data/spec of your stepper motor please?

Hi,
Thanks for the info, but which stepper is yours, complete model number would be handy.

Have you set the current limit switches?
TB6600-driver-current-table

Tom... :smiley: :+1: :australia: :coffee:

it is the 2.5A model.

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... :smiley: :+1: :australia: :coffee:
PS, What country are you from, I'm in Australia.

I live in Belgium, it's 1pm here lol

This program works perfectly, thanks

My Schoolmate just broke something out of happyness haha :smile::smile::smile:

Good to hear, which code did you use, the one I posted in post #8.
If so, can you see what I have done?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

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... :smiley: :+1: :coffee: :australia:

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