How to use a Stepper Motor with Arduino

How to use a Stepper Motor with Arduino

Stepper Motor Arduino

INTRODUCTION

A stepper motor is a brushless DC electric motor that divides a full rotation into several equal steps hence the name motor with “steps”. Try turning the head of the motor and you will notice the notches or steps when turning the head.

APPLICATIONS

The stepper motor is commonly used in automatic belt in logistics and CNC Machines, printers, electric watches and also high tech wheelchairs.

WIRING DIAGRAM

GND – GND

VCC – 5V

Digital Pin 3, 4, 5 and 6

Stepper motor arduino connections

(Note: Download the required library and follow these steps.)

CODE

 

#include <AccelStepper.h>
#define HALFSTEP 8

// Motor pin definitions
#define motorPin1  3     // IN1 on the ULN2003 driver 1
#define motorPin2  4     // IN2 on the ULN2003 driver 1
#define motorPin3  5     // IN3 on the ULN2003 driver 1
#define motorPin4  6     // IN4 on the ULN2003 driver 1

// Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper with 28BYJ-48
AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);

void setup() {
  stepper1.setMaxSpeed(1000.0);
  stepper1.setAcceleration(100.0);
stepper1.setSpeed(200);
  stepper1.moveTo(20000);

}//--(end setup )---

void loop() {

  //Change direction when the stepper reaches the target position
  if (stepper1.distanceToGo() == 0) {
    stepper1.moveTo(-stepper1.currentPosition());
  }
  stepper1.run();
}

END RESULT

Observe the speed of the stepper motor, which you can change in the function setSpeed(n).

ADDITIONAL RESOURCES

https://circuitdigest.com/microcontroller-projects/arduino-stepper-motor-control-tutorial

https://www.arduino.cc/en/tutorial/stepperSpeedControl