Hi, I have difficulty in gradually increasing and decreasing the speed of the stepper motor using Arduino Mega2560. I need some help in programming.
This is how my code looks so far :
#include <Stepper.h>
// change this to the number of steps per revolution for your motor
#define STEPS 7200
#define pulse 10
#define dir 9
#define enable 11
//opto is connected to 5V pin of Arduino (range of opto is between 4.5 - 6VDC)
// create an instance of the stepper class, specifying
// the number of steps per revolution for the motor and
// the pins it's attached to
Stepper stepper(STEPS, 9,10);
int steps = 0;
void setup()
{
// set the speed of the motor to 30 RPM
stepper.setSpeed(30);
Serial.begin(9600);
}
void loop(){
digitalWrite(enable, HIGH);
digitalWrite(dir, HIGH);
digitalWrite(pulse, HIGH);
digitalWrite(pulse, LOW);
digitalWrite(dir, LOW);
digitalWrite(pulse, HIGH);
digitalWrite(pulse, LOW);
if (Serial.available()>0){
steps = Serial.parseInt();
}
if( steps != 0){
stepper.step(steps);
}
steps=0;
}