Eksempel på opsætning og programmering 28BYJ-48 stepper motor med ULN2003 stepper driver board

Arduino_Stepper_ULN2003A_28BYJ-48-1.jpg

Farvekode:

Rød:5V
Sort:GND
Orange (IN1):8
Orange (IN2):9
Orange (IN3):10
Orange (IN4):11

Tilslut stepper og stepper driver board som vist herover.

Du kan finde stepper motor her

Du kan finde ULN2003 driver board her

Eksempel kode:

/* Trab.dk Example Software Sketch
ULN2003 with 28BYJ-48 stepper motor
kundeservice@trab.dk */

/*-----( Import needed libraries )-----*/
#include <Stepper.h> // Comes with Arduino IDE

// Number of steps per revolution of INTERNAL motor in 4-step mode
#define STEPS_PER_MOTOR_REVOLUTION 32  

// Number of steps per revolution of OUTPUT SHAFT (= gear reduction; 2048 steps)
#define STEPS_PER_OUTPUT_REVOLUTION 32 * 64

// Declare 'small_stepper' variable
Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11);

// Declare 'Steps2Take' variable
int  Steps2Take;

void setup()
{
// Nothing  (Stepper Library sets pins as outputs)
}

void loop()
{
  Steps2Take  =  STEPS_PER_OUTPUT_REVOLUTION / 2;  // Rotate CW 1/2 turn
  small_stepper.setSpeed(1000);  
  small_stepper.step(Steps2Take);
  delay(100);
 
  Steps2Take  =  - STEPS_PER_OUTPUT_REVOLUTION / 2;  // Rotate CCW 1/2 turn 
  small_stepper.setSpeed(1000);  // 2000 a good max speed??
  small_stepper.step(Steps2Take);
  delay(100);
}

/* (THE END) */