/*This software is provided in “AS IS” condition,NO WARRANTIES in any form apply to this software. picmicrolab.com 10.24.2017 *************************************************************************************************************** //Stepper Motor Controller with Arduino */ //******************************************** void setup() { // initialize Stepper Motor coil I/O pins. pinMode(2, OUTPUT); // pinMode(3, OUTPUT); // pinMode(4, OUTPUT); // pinMode(5, OUTPUT); // pinMode(A0, INPUT); // } void loop() { int analog_input = ( analogRead(A0) * 4.9 ); //-------------------------------------------------- if(analog_input > 2100 && analog_input < 2400 ) delay(1); //-------------------------------------------------- if(analog_input > 800 && analog_input < 2100 ) RotateMotorCW(25); //-------------------------------------------------- if(analog_input > 400 && analog_input < 800 ) RotateMotorCW(10); //-------------------------------------------------- if(analog_input < 400 ) RotateMotorCW(5); //---------------------------------------------------- //---------------------------------------------------- if(analog_input > 2600 && analog_input < 2900 ) RotateMotorCCW(25); //-------------------------------------------------- if(analog_input > 2900 && analog_input < 3200 ) RotateMotorCCW(10); //-------------------------------------------------- if(analog_input > 3200 ) RotateMotorCCW(5); else delay(1); } void RotateMotorCW(int MotorDelay) { //----------------------------------- digitalWrite(2,HIGH); delay(MotorDelay); digitalWrite(2,LOW); //---------------------------------- digitalWrite(3,HIGH); delay(MotorDelay); digitalWrite(3,LOW); //---------------------------------- digitalWrite(4,HIGH); delay(MotorDelay); digitalWrite(4,LOW); //--------------------------------- digitalWrite(5,HIGH); delay(MotorDelay); digitalWrite(5,LOW); } void RotateMotorCCW(int MotorDelay) { //----------------------------------- digitalWrite(5,HIGH); delay(MotorDelay); digitalWrite(5,LOW); //---------------------------------- digitalWrite(4,HIGH); delay(MotorDelay); digitalWrite(4,LOW); //---------------------------------- digitalWrite(3,HIGH); delay(MotorDelay); digitalWrite(3,LOW); //--------------------------------- digitalWrite(2,HIGH); delay(MotorDelay); digitalWrite(2,LOW); }