How do I use infrared remote to controll multiple steppers at a time?

Hi,

Relatively new to Arduino and have reached some difficulty during a project. Spent a while looking for solutions or help with this case but couldn't find any.

I am aiming to use an infrared remote to control multiple steppers using the Accelstepper library.

I have been able to use the IR remote to control a single stepper motor using the Stepper library and also control multiple steppers at once using the Accelstepper library, however when I try a combination the steppers do not operate. the LEDs on stepper3's driver board (as an example) runs through the following sequence, AB, AD, CD, BC, when the UP button is pressed but never all four at once.

The code which I am using is as follows:

#include <AccelStepper.h>
#include <IRremote.h>

AccelStepper stepper1(AccelStepper::FULL4WIRE, 2, 3, 4, 5);
AccelStepper stepper2(AccelStepper::FULL4WIRE, 6, 7, 8, 9);
AccelStepper stepper3(AccelStepper::FULL4WIRE, 10, 11, 12, 13);

int receiver = A3; //IR reciever pin

IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results; // create instance of 'decode_results'

void setup()
{
Serial.begin(9600);

stepper1.setMaxSpeed(300.0);
stepper1.setAcceleration(100.0);
stepper1.moveTo(1000000);

stepper2.setMaxSpeed(300.0);
stepper2.setAcceleration(100.0);
stepper2.moveTo(-1000000);

stepper3.setMaxSpeed(300.0);
stepper3.setAcceleration(100.0);
stepper3.moveTo(1000000);

irrecv.enableIRIn(); // Start the receiver
}

void loop()
{
if (irrecv.decode(&results)) // have we received an IR signal?
{

switch(results.value)
{

case 0xFF629D: // UP button pressed
stepper1.run();
stepper3.run();

case 0xFFA857: // DOWN button pressed
stepper2.run();
stepper3.run();
}
irrecv.resume(); // receive the next value
}
}

Any solutions or help on what I'm doing wrong would be much appreciated,
Thanks.

You need break; after each case.

The run() method causes the stepper to take AT MOST one step. You'll wear your thumb out pressing the remote button 1000000 times, to get the stepper to move all the way.

It really isn't clear what you want to do, or why you think that code is even remotely close to doing that.

Your Title How do I use infrared remote to controll multiple steppers at a time? encompasses two quite separate questions.

{A} how to get data from an IR remote
{B} how to use data to control multiple stepper motors.

Which part are you having trouble with?

What data do you wish to get from the IR remote? Give some examples.

...R
Stepper Motor Basics
Simple Stepper Code

Thanks for the replies,

I have added the breaks after each case

I have also now realized what my problem was, the steppers were operating but only one step at a time due to the run function so it wasn't noticeable.

I'm sorry if my problem was not clear previously I am looking to use the data received by the IR remote (which I understand) to cause the steppers to operate simultaneously for a large number of steps when a signal is received, but I don't know which Accelstepper function to use in order to make this happen instead of the run function.

Once again any pointers would be much appreciated.

I'm sorry if my problem was not clear previously I am looking to use the data received by the IR remote (which I understand) to cause the steppers to operate simultaneously for a large number of steps when a signal is received, but I don't know which Accelstepper function to use in order to make this happen instead of the run function.

You need to understand when and why to call run(), and what it does if you call it when it is not needed.

Here's a hint: run() does NOTHING if the stepper is at the last commanded position.

So, on EVERY pass through loop(), call run() for each stepper.

When you press a button on the remote, you MIGHT want to change the position where the stepper is trying to get to.

CR41G:
but I don't know which Accelstepper function to use in order to make this happen instead of the run function.

Have you not tried some of the examples that come with the AccelStepper library?

The move() or moveTo() functions tell the library how many steps you want the motor to move.

...R

Thanks again for the replies

I researched further example code and now also understand the run function more, ultimately helping me find the solution to my problem.