# Stepper motor controlled by remote

**URL:** <https://forum.arduino.cc/t/stepper-motor-controlled-by-remote/1191608>\
**Category:** Motors, Mechanics, Power and CNC\
**Created:** [November 21, 2023, 3:42am UTC](https://forum.arduino.cc/t/stepper-motor-controlled-by-remote/1191608 "2023-11-21T03:42:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![twoowls](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@twoowls](https://forum.arduino.cc/u/twoowls)\
**Post date:** [November 21, 2023, 3:42am UTC](https://forum.arduino.cc/t/stepper-motor-controlled-by-remote/1191608/1 "2023-11-21T03:42:28Z")

</div>

IH all  
I am starting to pull my hair out I cannot get this to work

#include "Stepper.h"  
#include "IRremote.h"

/_----- Variables, Pins -----_/  
#define STEPS 32 // Number of steps per revolution of Internal shaft  
int Steps2Take; // 2048 = 1 Revolution  
int receiver = 4 ; // Signal Pin of IR receiver to Arduino Digital Pin 6

/_-----( Declare objects )-----_/  
// Setup of proper sequencing for Motor Driver Pins  
// In1, In2, In3, In4 in the sequence 1-3-2-4

Stepper small\_stepper(STEPS, 8, 10, 9, 11);  
IRrecv irrecv(receiver); // create instance of 'irrecv'  
decode\_results results; // create instance of 'decode\_results'

void setup()  
{  
irrecv.enableIRIn(); // Start the receiver  
}

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

{  
switch(results.value)

```
{

  case 0xFFA857: // 1 button pressed
                  small_stepper.setSpeed(500); //Max seems to be 500
                  Steps2Take = 256 ; // Rotate CW
                  small_stepper.step(Steps2Take);
                  delay(2000); 
                  break;

 
  case 0xFF229D: // 3 button pressed
                  small_stepper.setSpeed(500);
                  Steps2Take = 768 ; // Rotate CCW
                  small_stepper.step(Steps2Take);
                  delay(2000); 
                  break;

```

}  
}  
}

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [November 21, 2023, 4:42am UTC](https://forum.arduino.cc/t/stepper-motor-controlled-by-remote/1191608/2 "2023-11-21T04:42:24Z")

</div>

Does it then compile for you?

If your library files are not in the local/sketch folder, change the double-quotes to greater-than/less-than. For example, `#include <Stepper.h>` and `#include <IRremote.h>`

---

<div class="post-metadata">

**Author:** ![twoowls](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@twoowls](https://forum.arduino.cc/u/twoowls)\
**Post date:** [November 21, 2023, 8:25am UTC](https://forum.arduino.cc/t/stepper-motor-controlled-by-remote/1191608/3 "2023-11-21T08:25:31Z")

</div>

Hi Mate  
yes it dose the board can see the remote signal but it dose nothing  
I've also tried this

#include "Stepper.h"  
#include "IRremote.h"

#define STEPS 32  
#define IR\_BUTTON\_1 12  
#define IR\_BUTTON\_3 94  
int Steps2Take;  
int receiver = 12;

Stepper small\_stepper(STEPS, 8, 10, 9, 11);  
IRrecv irrecv(receiver);  
decode\_results results;

void setup() {

irrecv.enableIRIn();  
const int stepsPerRevolution = 200;  
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

myStepper.setSpeed(50);

Serial.begin(9600);  
}

void loop() {

if (irrecv.decode(&results))  
{  
switch(results.value)  
{  
case 0xFF30CF:  
small\_stepper.setSpeed(500);  
Steps2Take = 2048;  
small\_stepper.step(Steps2Take);  
delay(2000);  
break;  
case 0xFF7A85:  
small\_stepper.setSpeed(500);  
Steps2Take = -2048;  
small\_stepper.step(Steps2Take);  
delay(2000);  
break;  
}  
irrecv.resume();  
digitalWrite(8, LOW);  
digitalWrite(9, LOW);  
digitalWrite(10, LOW);  
digitalWrite(11, LOW);  
}  
}

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [November 21, 2023, 10:16am UTC](https://forum.arduino.cc/t/stepper-motor-controlled-by-remote/1191608/4 "2023-11-21T10:16:41Z")

</div>

Add Serial.println( results.value); after reading IR, and see what You've got.

---

<div class="post-metadata">

**Author:** ![sseijo](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@sseijo](https://forum.arduino.cc/u/sseijo)\
**Post date:** [November 21, 2023, 10:48am UTC](https://forum.arduino.cc/t/stepper-motor-controlled-by-remote/1191608/5 "2023-11-21T10:48:51Z")

</div>

Which pin is the IRremote connected to? In the code it appears connected to pin 4, but the comment says otherwise.

What version of the library are you using? The syntax has changed. Check this out: [GitHub - Arduino-IRremote/Arduino-IRremote: Infrared remote library for Arduino: send and receive infrared signals with multiple protocols](https://github.com/Arduino-IRremote/Arduino-IRremote) (Converting your 2.x program to the 4.x version).

Don't use a switch-case with 3-byte values, as this structure only handles int (2 bytes) and char: [switch...case - Guía de Referencia de Arduino](https://www.arduino.cc/reference/es/language/structure/control-structure/switchcase/)

```arduino
#include "Stepper.h"
#include "IRremote.h"

/----- Variables, Pins -----/
#define STEPS 32 // Number of steps per revolution of Internal shaft
int Steps2Take; // 2048 = 1 Revolution
int receiver = 4; // Signal Pin of IR receiver to Arduino Digital Pin 6 //// -> Is it connected to pin 4 or 6??
/-----( Declare objects )-----/
// Setup of proper sequencing for Motor Driver Pins
// In1, In2, In3, In4 in the sequence 1-3-2-4

Stepper small_stepper(STEPS, 8, 10, 9, 11);
IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results; // create instance of 'decode_results'

void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  unsigned long irValue = 0;
  if (irrecv.decode( & results)) {
	  
    irValue = results.value;
    Serial.println(irValue, HEX);
	
    if (irValue == 0xFFA857) { // 1 button pressed
      small_stepper.setSpeed(500); //Max seems to be 500
      Steps2Take = 256; // Rotate CW
      small_stepper.step(Steps2Take);
      delay(2000);
    } else if (irValue == 0xFF229D) { // 3 button pressed
      small_stepper.setSpeed(500);
      Steps2Take = 768; // Rotate CCW
      small_stepper.step(Steps2Take);
      delay(2000);
    }
  }
  irrecv.resume(); //// -> You need it to receive the next value
}

```

---

<div class="post-metadata">

**Author:** ![twoowls](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@twoowls](https://forum.arduino.cc/u/twoowls)\
**Post date:** [November 21, 2023, 12:17pm UTC](https://forum.arduino.cc/t/stepper-motor-controlled-by-remote/1191608/6 "2023-11-21T12:17:18Z")

</div>

I have been switching between both pins to see if I can get a result. my library is up to date.  
thanks for the advice

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 19, 2024, 12:17pm UTC](https://forum.arduino.cc/t/stepper-motor-controlled-by-remote/1191608/7 "2024-05-19T12:17:31Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
