Stepmotor 28BYJ-48 inkl. Driver Board ULN2003 med Arduino UNO

Materialer:

Kredsløbsopstilling:

Eksempler på programmer:

Program 1:

/*
Stepper Motor Demonstration 1
Stepper-Demo1.ino
Demonstrates 28BYJ-48 Unipolar Stepper with ULN2003 Driver
Uses Arduino Stepper Library

*/

//Include the Arduino Stepper Library
#include <Stepper.h>

// Define Constants

// Number of steps per internal motor revolution
const float STEPS_PER_REV = 32;

// Amount of Gear Reduction
const float GEAR_RED = 64;

// Number of steps per geared output rotation
const float STEPS_PER_OUT_REV = STEPS_PER_REV * GEAR_RED;

// Define Variables

// Number of Steps Required
int StepsRequired;

// Create Instance of Stepper Class
// Specify Pins used for motor coils
// The pins used are 8,9,10,11
// Connected to ULN2003 Motor Driver In1, In2, In3, In4
// Pins entered in sequence 1-3-2-4 for proper step sequencing

Stepper steppermotor(STEPS_PER_REV, 8, 10, 9, 11);

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

void loop()
{
// Slow – 4-step CW sequence to observe lights on driver board
steppermotor.setSpeed(1);
StepsRequired = 4;
steppermotor.step(StepsRequired);
delay(2000);

// Rotate CW 1/2 turn slowly
StepsRequired = STEPS_PER_OUT_REV / 2;
steppermotor.setSpeed(100);
steppermotor.step(StepsRequired);
delay(1000);

// Rotate CCW 1/2 turn quickly
StepsRequired = – STEPS_PER_OUT_REV / 2;
steppermotor.setSpeed(700);
steppermotor.step(StepsRequired);
delay(2000);

}

Program 2:

/* Example sketch to control a 28BYJ-48 stepper motor with ULN2003 driver board and Arduino UNO.
// Include the Arduino Stepper.h library:
#include <Stepper.h>
// Define number of steps per rotation:
const int stepsPerRevolution = 2048;
// Wiring:
// Pin 8 to IN1 on the ULN2003 driver
// Pin 9 to IN2 on the ULN2003 driver
// Pin 10 to IN3 on the ULN2003 driver
// Pin 11 to IN4 on the ULN2003 driver
// Create stepper object called ‘myStepper’, note the pin order:
Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);
void setup() {
// Set the speed to 5 rpm:
myStepper.setSpeed(5);

// Begin Serial communication at a baud rate of 9600:
Serial.begin(9600);
}
void loop() {
// Step one revolution in one direction:
Serial.println(“clockwise”);
myStepper.step(stepsPerRevolution);
delay(500);

// Step one revolution in the other direction:
Serial.println(“counterclockwise”);
myStepper.step(-stepsPerRevolution);
delay(500);
}