Interfacing BYGH403 1.65A Stepper Motor with Arduino

1,508 views

Introduction

The realm of mechanics is vast and exciting, and the BYGH403 1.65A Stepper Motor is a powerful tool for those looking to bring their projects to life. Whether you’re building a robot, a CNC machine, or just a cool gadget, the BYGH403 stepper motor is a great option.

In this article, we will take you through interfacing the BYGH403 with an Arduino and show you how to control it with just a few lines of code. So, come with us as we explore the world of mechanics and bring your ideas to reality with the BYGH403 and Arduino.

What is Stepper Motor?

An electric motor that rotates in discrete step increments is known as a stepper motor. Because the motion of each step is precise, the motor’s position can be controlled accurately.

BYGH403 1.65A Stepper Motor

Hardware Components

You will require the following hardware for Interfacing BYGH403 1.65A Stepper Motor with Arduino.

S.noComponentValueQty
1.Arduino UNO1
2.1.65A Stepper MotorBYGH4031
3.EasyDriver Stepper Motor Driver Board1
4.Breadboard1
5.Jumper Wires1

BYGH403 1.65A Stepper Motor with Arduino

Now that you have understood the stepper motor, let’s interface it with Arduino. To do that, follow the given steps

Schematic

Make connections according to the circuit diagram given below.

BYGH403 1.65A Stepper Motor Arduino

Installing Arduino IDE

First, you need to install Arduino IDE Software from its official website Arduino. Here is a simple step-by-step guide on “How to install Arduino IDE“.

Code

Now copy the following code and upload it to Arduino IDE Software.


#define stp 2
#define dir 3
#define MS1 4
#define MS2 5

int x;

void setup() {
  pinMode(stp, OUTPUT);
  pinMode(dir, OUTPUT);
  pinMode(MS1, OUTPUT);
  pinMode(MS2, OUTPUT);
  
  digitalWrite(MS1,LOW);
  digitalWrite(MS2,LOW);
}

void loop() {
  digitalWrite(dir, HIGH); 
  for(x= 0; x<1000; x++)  
  {
    digitalWrite(stp,HIGH); 
    delay(1);
    digitalWrite(stp,LOW); 
    delay(1);
  }
  delay(1000);
  
  digitalWrite(dir, LOW); 
  for(x= 0; x<1000; x++)  
  {
    digitalWrite(stp,HIGH); 
    delay(1);
    digitalWrite(stp,LOW); 
    delay(1);
  }
  delay(1000);
}

Let’s Test It

Upload the program to Arduino. After the circuit is complete, the stepper motor will rotate clockwise for 1000 steps, pause for 1 second, reverse direction for 1000 steps, pause for another second, and repeat.

Working Explanation

The code will make the motor rotate clockwise for 1000 steps, wait for 1 sec, rotate anticlockwise for 1000 steps, and wait again for 1 sec. Then it will repeat the process. Here’s the code explanation:

  • First, we define four constants with the names “stp,” “dir,” “MS1”, and “MS2” and assign them the values 2, 3, 4, and 5, respectively. These values correspond to the pin numbers of the Arduino board connected to the stepper motor.
  • Then, in the setup function, we tell the Arduino board that these PINs will be used as outputs, meaning that we will send signals to the motor through these pins. 
  • In the loop function, we first set the value of the “dir” pin to HIGH. This means that the motor will rotate in one direction. Then, we use a for loop to repeat the following process 1000 times: We Set the value of the “stp” pin to HIGH, which tells the motor to take one step. The code then waits for one millisecond. Then Set the value of the “stop” pin to LOW. Again it Waits for one millisecond.
  • After the for loop, the code waits for 1 second before reversing the direction of the motor by setting the “dir” pin to LOW and repeating the same process of moving 1000 steps.

Applications

  • Slot machines
  • Compact disc drives
  • Intelligent lighting
  • CNC machines
  • 3D printers, etc

Conclusion.

We hope you have found this Interfacing BYGH403 1.65A Stepper Motor with Arduino Circuit very useful. If you feel any difficulty making it feel free to ask anything in the comment section.