Go Down

Topic: [Help] Stepper motor, arduino mega 2560, easy driver. (Read 1 time) previous topic - next topic

tony_tran

May 15, 2014, 12:25 pm Last Edit: May 15, 2014, 12:42 pm by tony_tran Reason: 1
Hi everybody,
I have stepper motor type: 42GBY023-20, 12V, 0.4A, 200 steps, 6 wires  and i use arduino mega 2560 with Easy driver, my power for stepper motor is 12V, 0.5A and use laptop for arduino mega.
When i use this code:
------------------------------------------------------
#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
                                    // for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8,9);            

void setup() {
 // set the speed at 60 rpm:
 myStepper.setSpeed(60);
 // initialize the serial port:
 Serial.begin(9600);
}

void loop() {
 // step one revolution  in one direction:
  Serial.println("clockwise");
 myStepper.step(stepsPerRevolution);
 delay(500);
 
  // step one revolution in the other direction:
 Serial.println("counterclockwise");
 myStepper.step(-stepsPerRevolution);
 delay(500);
}
-------------------------------------------
my stepper motor not working like this : "// set the speed at 60 rpm:"  it's only turning left and turning right at the same position. I try to change other code and change the way to connect wire from motor to easy driver but not working, only vibrate.
I don't know why, please help me !
Thank you all,
Tony.

Robin2

This simple code should make it work - just to prove that it does.

Code: [Select]
// testing a stepper motor with a Pololu A4988 driver board or equivalent
// on an Uno the onboard led will flash with each step
// as posted on Arduino Forum at http://forum.arduino.cc/index.php?topic=208905.0

byte directionPin = 9;
byte stepPin = 8;
int numberOfSteps = 100;
byte ledPin = 13;
int pulseWidthMicros = 20;  // microseconds
int millisbetweenSteps = 25; // milliseconds


void setup()
{

  Serial.begin(9600);
  Serial.println("Starting StepperTest");
  digitalWrite(ledPin, LOW);
 
  delay(2000);

  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
 

  digitalWrite(directionPin, HIGH);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros);
    digitalWrite(stepPin, LOW);
   
    delay(millisbetweenSteps);
   
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
 
  delay(3000);
 

  digitalWrite(directionPin, LOW);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros);
    digitalWrite(stepPin, LOW);
   
    delay(millisbetweenSteps);
   
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
 
}

void loop()
{

}


...R
Two or three hours spent thinking and reading documentation solves most programming problems.

tony_tran

Thank you, Robin2. After i check, it's still not working. Nothing move...

Robin2

Then please draw a clear diagram showing how everything is connected and post a photo of the drawing.

Also give details of what power supply you are using for the motor.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up