You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
1.6 KiB
79 lines
1.6 KiB
5 years ago
|
|
||
|
/*
|
||
|
Stepper Motor Demonstration 1
|
||
|
Stepper-Demo1.ino
|
||
|
Demonstrates 28BYJ-48 Unipolar Stepper with ULN2003 Driver
|
||
|
Uses Arduino Stepper Library
|
||
|
|
||
|
DroneBot Workshop 2018
|
||
|
https://dronebotworkshop.com
|
||
|
*/
|
||
|
|
||
|
//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
|
||
|
|
||
5 years ago
|
const int stepper_motor_speed = 600;
|
||
5 years ago
|
int pos = 1;
|
||
|
const int StepsRequired = STEPS_PER_OUT_REV / 4;
|
||
|
// 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
|
||
|
|
||
5 years ago
|
Stepper steppermotor(STEPS_PER_REV, 6, 8, 12, 13);
|
||
5 years ago
|
|
||
|
void setup()
|
||
|
{
|
||
|
// Nothing (Stepper Library sets pins as outputs)
|
||
|
}
|
||
|
void next_step()
|
||
|
{
|
||
|
if(pos == 1)
|
||
|
{
|
||
|
steppermotor.setSpeed(stepper_motor_speed);
|
||
|
steppermotor.step(StepsRequired);
|
||
|
pos = 2;
|
||
|
}
|
||
|
else if(pos ==2)
|
||
|
{
|
||
|
steppermotor.setSpeed(stepper_motor_speed);
|
||
|
steppermotor.step(-1*StepsRequired);
|
||
|
pos = 3;
|
||
|
}
|
||
|
else if(pos == 3)
|
||
|
{
|
||
|
steppermotor.setSpeed(stepper_motor_speed);
|
||
|
steppermotor.step(-1*StepsRequired);
|
||
|
pos = 4;
|
||
|
}
|
||
|
else if(pos == 4)
|
||
|
{
|
||
|
steppermotor.setSpeed(stepper_motor_speed);
|
||
|
steppermotor.step(StepsRequired);
|
||
|
pos = 1;
|
||
|
}
|
||
|
}
|
||
|
void loop()
|
||
|
{
|
||
|
|
||
|
next_step();
|
||
|
delay(1000);
|
||
|
|
||
|
}
|