From 1ca06ae8879ae698196145e9693db8eda85356f2 Mon Sep 17 00:00:00 2001 From: cs131110 Date: Wed, 11 Dec 2019 20:55:17 +0200 Subject: [PATCH] update --- stepMotor/step_motor.ino | 78 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 stepMotor/step_motor.ino diff --git a/stepMotor/step_motor.ino b/stepMotor/step_motor.ino new file mode 100644 index 0000000..30f40d5 --- /dev/null +++ b/stepMotor/step_motor.ino @@ -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 + +// 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); + +}