# Controlling Stepper Motor With Remote

### **Overview**

In this lesson, you will learn a fun and easy way to control a stepper motor from a distance using an IR remote control.

The stepper we are using comes with its own driver board making it easy to connect to our UNO R3.

The IR sensor is connected to the UNO R3 directly since it uses almost no power.

### **Component Required**

* 1 x Arduino UNO R3
* 1 x IR receiver module
* 1 x IR remote
* 1 x ULN2003 stepper motor driver module
* 1 x Stepper motor
* 7 x F-M wires (Female to Male DuPont wires)
* 2 x M-M wire (Male to Male jumper wire)

### **Connection Diagram**

![](/files/n2Iik7xCQZ6D0VALYpPC)

### **Wiring schematic**

![](/files/KvzUymApBJfnG3a67IGF)

### **Physical wiring diagram**

![](/files/Fzk4GSTjJDpu9OiKbtNl)

### **Library Files Required**

{% hint style="info" %}
Please include the **Stepper.zip** and **IRremote.zip** to your **Library**. Download the files below
{% endhint %}

{% file src="/files/jgMdw5KACzb13IBBPWQ4" %}

{% file src="/files/eoWeDDrGOyJ2Zxu4sGfp" %}

### Code

```
#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 = 12; // 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 0xFFE01F:  // “—”button pressed
        small_stepper.setSpeed(500); //Max seems to be 500
        Steps2Take  =  2048;  // Rotate CW
        small_stepper.step(Steps2Take);
        delay(2000);
        break;

      case 0xFFA857: // “+” button pressed
        small_stepper.setSpeed(500);
        Steps2Take  =  -2048;  // Rotate CCW
        small_stepper.step(Steps2Take);
        delay(2000);
        break;
    }
    irrecv.resume(); // receive the next value
    digitalWrite(8, LOW);
    digitalWrite(9, LOW);
    digitalWrite(10, LOW);
    digitalWrite(11, LOW);
  }


}/* --end main loop -- */
```

{% file src="/files/BGdXncgrhvFl3TVvH1qN" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learn.arduinosa.co.za/arduino-kits/basic-starter-kit/controlling-stepper-motor-with-remote.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
