cs131110
5 years ago
1 changed files with 78 additions and 0 deletions
@ -0,0 +1,78 @@ |
|||
|
|||
/*
|
|||
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
|
|||
|
|||
const int stepper_motor_speed = 700; |
|||
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
|
|||
|
|||
Stepper steppermotor(STEPS_PER_REV, 6, 10, 11, 13); |
|||
|
|||
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); |
|||
|
|||
} |
Loading…
Reference in new issue