Thursday, June 6, 2013

Week 13: Experiment on New Mechanic System: STEPPER MOTOR

As the mechanic system of our prototype does not work properly due to the limitation control on the DC motor. As at the early stage we were all agree on using DC motor as it save on cost and I do have a bit of knowledge of how to use DC motor however Russell advice us to use STEPPER motor for to drive to car on the top rail.

After discussing with the rest of the group we decided to create a new mechanic system using stepper motor. According to Russell advice email, he provided us a link to a tutorial as followed; http://garagelab.com/profiles/blogs/tutorial-controlling-the-displacement-of-a-stepper-motor-with-the and we realized that to control a stepper we need to have an "EASY DRIVER" which is needed to control the motor.

Russell has ordered the easy driver for us and predicted to be delivered by this Friday.

Meanwhile I have attempted tried to control the stepper motor with the L293D that I have as I found on this tutorial, http://itp.nyu.edu/~gg964/blog/archives/1369. As I have no idea how to control stepper motor I then search for a tutorial, I found the forum that contain the code that I need from this forum (http://forum.arduino.cc/index.php/topic,152747.0.html)


I then tried to wire up stepper motor to Arduino board and used the code in the forum as a guide but it did not seem to work properly.

This is the diagram of Arduino circuit that I made.



And this is the video of stepper motor that is control by the two push buttons. What it is meant to do is rotate in two opposite direction when the different button is pressed. But at the moment it is still going into the same direction.


And this is the code that I used:

// 4 wire bipolar stepper motor driver code for L293D which controlls the direction of the motor with two push buttons for each clockwise and counter clockwise direction. After completing the predefined steps in 'motorstep' waits for the new direction command will come from one of the push buttons

const int CW = 2;
const int CCW = 3;
const int ENA = 8;
const int ENB = 13;
const int black = 9;  // IN1 pin of L293D
const int brown = 10;  // IN2 pin of L293D
const int orange = 11;  // IN3 pin of L293D
const int yellow = 12;  // IN4 pin of L293D
int valA = 0; // counter clockwise button vallue
int stateA =0; // state of the counter clockwise button
int valB = 0;  // clockwise button value
int stateB = 0; //state of the clockwise button
int pause = 10; //delay between each step for slow rotation
int motorstep = 48; // number of steps when the buttons are once pressed

void setup(){
  pinMode(black, OUTPUT);
  pinMode(brown, OUTPUT);
  pinMode(orange, OUTPUT);
  pinMode(yellow, OUTPUT);
  pinMode(CW, INPUT);
  pinMode(CCW, INPUT);
}

void loop(){
  valA = digitalRead(CW); //reads the CW button value and writes to 'valA'
  if(valA ==HIGH){
    stateA = 1- stateA;
    delay(1000); // to get rid of button bouncing (arduino reads the buttons really fast!!)
    stateB = 0;
    reverse(motorstep); 
  }
 
  valB = digitalRead(CCW); //reads the CCW button value and writes to 'valB'
  if (valB == HIGH){
    stateB = 1- stateB;
    delay(1000); // to get rid of button bouncing (arduino reads the buttons really fast!!)
    stateA = 0;
    forward(motorstep);   
  }
} // end loop

void reverse(int i){
  // Pin 8 Enable A Pin 13 Enable B on
  digitalWrite(ENA, HIGH);
  digitalWrite(ENB, HIGH);
 
  while (1)   {
    digitalWrite(black, 0);
    digitalWrite(brown, 1);
    digitalWrite(orange, 1);
    digitalWrite(yellow, 0);
    delay(pause); 
    i--; // reduces the remaining 'motorstep' value as "motorstep-1" for each step
    if (i < 1) break;

    digitalWrite(black, 0);
    digitalWrite(brown, 1);
    digitalWrite(orange, 0);
    digitalWrite(yellow, 1);
    delay(pause);
    i--; // reduces the remaining 'motorstep' value as "motorstep-1" for each step
    if (i < 1) break;

    digitalWrite(black, 1);
    digitalWrite(brown, 0);
    digitalWrite(orange, 0);
    digitalWrite(yellow, 1);
    delay(pause); 
    i--; // reduces the remaining 'motorstep' value as "motorstep-1" for each step
    if (i < 1) break;

    digitalWrite(black, 1);
    digitalWrite(brown, 0);
    digitalWrite(orange, 1);
    digitalWrite(yellow, 0);
    delay(pause);
    i--; // reduces the remaining 'motorstep' value as "motorstep-1" for each step
    if (i < 1) break;
  }

  // all outputs to stepper off
  digitalWrite(ENA, LOW);
  digitalWrite(ENB, LOW);

}  // end reverse()



void forward(int i){

  // Pin 8 Enable A Pin 13 Enable B on
  digitalWrite(ENA, HIGH);
  digitalWrite(ENB, HIGH);

  while (1){

    digitalWrite(black, 1);
    digitalWrite(brown, 0);
    digitalWrite(orange, 1);
    digitalWrite(yellow, 0);
    delay(pause);
    i--; // reduces the remaining 'motorstep' value as "motorstep-1" for each step
    if (i < 1) break;

    digitalWrite(black, 1);
    digitalWrite(brown, 0);
    digitalWrite(orange, 0);
    digitalWrite(yellow, 1);
    delay(pause); 
    i--; // reduces the remaining 'motorstep' value as "motorstep-1" for each step
    if (i < 1) break;

    digitalWrite(black, 0);
    digitalWrite(brown, 1);
    digitalWrite(orange, 0);
    digitalWrite(yellow, 1);
    delay(pause);
    i--; // reduces the remaining 'motorstep' value as "motorstep-1" for each step
    if (i < 1) break;

    digitalWrite(black, 0);
    digitalWrite(brown, 1);
    digitalWrite(orange, 1);
    digitalWrite(yellow, 0);
    delay(pause); 
    i--; // reduces the remaining 'motorstep' value as "motorstep-1" for each step
    if (i < 1) break;
  }

  // all outputs to stepper off
  digitalWrite(ENA, LOW);
  digitalWrite(ENB, LOW);

}  // end forward()

At the moment I think the part that is control the direction of the motor is the number 0 and 1 which is disable and enable the pin output from L293D. It is somehow need to be set correctly to find the right direction for the motor.


I still cannot find the right value for the motor to go forward and reserve but I think this could be the right track to go as when I change these value the motor seem to do different movement.

No comments:

Post a Comment