Control 28BYJ-48 Stepper Motor with ULN2003 Driver &ESP8266

Duy Thuc 3/26/2024
0 likes
iot esp


code google drive : https://drive.google.com/file/d/17CbPzqDfx0koizjICfj7brelyAO-cy_H/view?usp=sharing

code ESP8266


// Include the AccelStepper Library

#include <AccelStepper.h>

// Define step constant. fullstep mode :4, haflt step mode :8

#define FULLSTEP 4

// ULN2003 Motor Driver Pins<=>Pins( Node Mcu 8266)

#define IN1 5

#define IN2 4

#define IN3 14

#define IN4 12


const int numberstepsperrev = 2038;//number of steps per revolution


// Creates an instance

// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence


AccelStepper myStepper(FULLSTEP, 5, 14, 4, 12);


void setup()

{

  myStepper.setMaxSpeed(1000.0);// set the maximum speed

  myStepper.setAcceleration(50.0);//acceleration factor

  myStepper.setSpeed(200);// initial speed and the target position

  myStepper.moveTo(numberstepsperrev);// set target position

}

void loop() {

  // Change direction once the motor reaches target position

  if (myStepper.distanceToGo() == 0)

    myStepper.moveTo(-myStepper.currentPosition());

  // Move the motor one step

  myStepper.run();

}



Powered by Froala Editor

;
Comments