[Project 17] – Stepper Motor Direction Control Using 2 Buttons with the Arduino

In this project we will control direction of stepper motor using 2 buttons with the Arduino.  I will use arduino uno in the circuit design program. I use usually arduino mega 2560. You can use the other arduino cards. Good Luck.

Circuit:


[Project 17] - Stepper Motor Direction Control Using 2 Buttons with the Arduino 232

Materials:


Arduino Uno/Mega   x1
Breadboard   x1
Stepper Motor (28BYJ-48)   x1
ULN2003A   x1
Button   x2
10 Kohm Resistor   x2
Jumper Cable
 

ULN2003A Pins:


uln2003a pins

28BYJ-48 Stepper Motor Datasheet:


[Project 17] - Stepper Motor Direction Control Using 2 Buttons with the Arduino 212

28BYJ-48 Stepper Motor Details:

28BYJ-48 STEPPER MOTOR FEATURESProgram:


//  letsarduino.com
//  [Project 17] - Stepper Motor Direction Control Using 2 Buttons with the Arduino

int button_1 = 2;
int button_2 = 3;
int motorPin1 = 8;          
int motorPin2 = 9;
int motorPin3 = 10;
int motorPin4 = 11;

int motor_Speed = 4;
int motor_Step; 
int val1 = 0;
int val2 = 0;

  void setup() {
  pinMode(button_1, INPUT);
  pinMode(button_2, INPUT);
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
}

void loop() {
  
  val1 = digitalRead(button_1);
  if (val1 == HIGH)
  {
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
  delay(motor_Speed);
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
  delay(motor_Speed);
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, LOW);
  delay(motor_Speed);
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, HIGH);
  delay(motor_Speed);
  
    } 

   val2 = digitalRead(button_2);
   if (val2 == HIGH)

  {
  digitalWrite(motorPin4, HIGH);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin1, LOW);
  delay(motor_Speed);
  digitalWrite(motorPin4, LOW);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin1, LOW);
  delay(motor_Speed);
  digitalWrite(motorPin4, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin1, LOW);
  delay(motor_Speed);
  digitalWrite(motorPin4, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin1, HIGH);
  delay(motor_Speed);
  }
}

 

Project Related Images:

[Project 17] - Stepper Motor Direction Control Using 2 Buttons with the Arduino 74



 

You may also like...