Showing posts with label stepper motor. Show all posts
Showing posts with label stepper motor. Show all posts

Thursday, January 3, 2013

Stepper motor control using Arduino and L293


Components
IC1
L293D

B1
5v DC supply

SW1,SW2
N.O. Push Button

R1,R2,R3,R4
100 omhs   1/4W

R5.R6
10k ohms 1/4W

D1,D2,D3,D4
LED

CN1
To pin13 (digital pin)
ARDUINO
CN2
To pin12 (digital pin)
CN3
To pin11 (digital pin)
CN4
To pin10 (digital pin)
CN5
To Stepper motor(4 wire)
MOTOR
CN6
To pin2 (digital pin)
ARDUINO
CN7
To pin3 (digital pin)
CN8
To A0(analog pin)
CN9
To Ground pin
CN10
To 5v pin




























There are 2 push buttons, one is for CW rotation and the other is for reverse.
Potentiometer is used to control the speed of the motor. Minimum speed is 0 and 100 for the maximum. If the speed is 0 the motor will not rotate even the push button is pressed. If the two push buttons were pressed the motor will not rotate as well. 


Codes:


#include <Stepper.h>

int forward = 2;
int reverse = 3;

Stepper motor(200, 10,11,12,13);            

void setup() {
  pinMode(forward,INPUT);
  pinMode(reverse,INPUT);
    Serial.begin(9600);
}

void loop() {
  int Speed = analogRead(A0);
  int RPM = map(Speed, 0, 1023, 0, 100);
  int f = digitalRead(forward);
  int r = digitalRead(reverse);
  if(f == 1 && r == 0 && RPM > 1){
  motor.step(1);
    motor.setSpeed(RPM);
    delay(.01);
  }
  if(r == 1 && f== 0  && RPM > 1){
    motor.step(-1);
    motor.setSpeed(RPM);
        delay(.01);
  }
  delay(5);
    Serial.println(RPM);
}