Stepper motor speed change help!

Hi there

I have built some remote controlled self opening curtains for my college project, these are operated by a stepper motor that is connected to a pulley which drives a belt connected to the curtains.

I am using a code I have found online, so far I have only changed the number of rotations to fully open and close the curtains, the code is as followed:

/*
Infrared Stepper Motor Control - one revolution

This program drives a unipolar stepper motor by the Remote Controller.
The motor is attached to digital pins 8 - 11 of the Arduino. The output pin of the Infrared Receiver is attached to pin 2

The motor should revolve one revolution clockwise if you push the forward key of the Remote Controller, and revolve one revolution counterclockwise if you push the backward keythen
one revolution in the other direction.
*/
#include <IRremote.h>
int RECV_PIN = 2;
long clockwise_cmd = 0x00FF02FD;
long counterclockwise_cmd = 0x00FF22DD;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
// initialize the digital pin as an output.
pinMode(RECV_PIN, INPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
int i=0;
if (irrecv.decode(&results))
{
irrecv.resume(); // Receive the next value
if (results.value == clockwise_cmd )
{
for(i=0;i<2048;i++)
{
clockwiserotate();
}
}
if (results.value == counterclockwise_cmd )
{
for(i=0;i<2048;i++)
{
counterclockwiserotate();
}
}
}
}
void clockwiserotate() { //revolve clockwise
step1();
step2();
step3();
step4();
step5();
step6();
step7();
step8();
}
void counterclockwiserotate() { //revolve counterclockwise
step1();
step7();
step6();
step5();
step4();
step3();
step2();
step1();
}
void step1(){
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
delay(2);
}
void step2(){
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
delay(2);
}
void step3(){
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
delay(2);
}
void step4(){
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay(2);
}
void step5(){
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay(2);
}
void step6(){
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(2);
}
void step7(){
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
delay(2);
}
void step8(){
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
delay(2);
}
void stoprotate()
{
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
}

Is there any way to change the speed at which the stepper motor rotates? I am using a stepper motor driver also

Thanks

Laurence

Hi,
The "delay" statements are where the "time between steps" is determined.

If you change all the delay(2) to delay(1) it will be twice as fast.

If you want a value in between, see "delayMicroseconds" HERE

AND if you wanted to get into programming a little, changing all those hard-coded values to a variable would allow you change only 1 line to change speed!

I think maybe twice the speed was too fast for the motor to handle! Oh well, thank you for your help anyway :slight_smile:

I'd suggest looking at the AccelStepper library before rolling your own code.