Controlling Servo Motor Using IR Remote Control




About: Mechatronics engineer. I'm a Fab Lab Egypt team member.

If you are looking for comfort and controlling your electronic devices remotely, you will find your need in this instructable.

In this instructable we will learn how to control a servo motor with remote control, this will give you a general concept on how to control remotely. You should know that the remote control sends Infrared(IR) signals, so we will learn how to receive and read these signals using Arduino.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Required Components

  • Arduino UNO
  • Servo motor
  • Remote control
  • IR receiver
  • Breadboard
  • Jumper wires

Step 2: Wiring

We use arduino UNO to control the servo motor to make the functionality we want.

We use IR receiver to read IR signals from remote control.

Wiring IR receiver and servo motor is shown in pictures.

Follow the steps of wiring in the pictures.

Step 3: The Programming

First, download IRremote library for arduino from this link.

Copy the library to Local Disk(C:) > Program Files(x86) > Arduino > libraries

Open IRremote demo example from Arduino IDE as picture 1 then upload to arduino board.

Then open serial monitor and try to click on any button of remote control to send a signal to IR receiver, the HEX code of each button must appear in serial monitor as picture 2

Then detect the HEX code of the buttons using to control the servo motor, assume you will use two buttons of your choice, one for clockwise rotation and another for counter clockwise rotation.

for example, use (+) for clockwise and (-) for counterclockwise, so you have to get their HEX codes.

(+) ---> A3C8EDDB

(-) ---> F076C13B

In the final code, the functionality is when clicking at any of two buttons the motor is toggling between the rotation in main direction and stop so when first click at any of two buttons the motor will rotate in button's direction, and when second click at same button the motor will stop as shown in the video.

The code is:

// Written by: Mohamed Soliman
// This code is for controlling servo motor with IR remote control // When clicking at any of two buttons the motor is toggling between the rotation and stop

#include <IRremote.h> //must copy IRremote library to arduino libraries #include <Servo.h> #define plus 0xA3C8EDDB //clockwise rotation button #define minus 0xF076C13B //counter clockwise rotation button

int RECV_PIN = 2; //IR receiver pin Servo servo; int val; //rotation angle bool cwRotation, ccwRotation; //the states of rotation

IRrecv irrecv(RECV_PIN);

decode_results results;

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

void loop() { if (irrecv.decode(&results)) { Serial.println(results.value, HEX); irrecv.resume(); // Receive the next value

if (results.value == plus) { cwRotation = !cwRotation; //toggle the rotation value ccwRotation = false; //no rotation in this direction }

if (results.value == minus) { ccwRotation = !ccwRotation; //toggle the rotation value cwRotation = false; //no rotation in this direction } } if (cwRotation && (val != 175)) { val++; //for colockwise button } if (ccwRotation && (val != 0)) { val--; //for counter colockwise button } servo.write(val); delay(20); //General speed }

Step 4: Let Your Circuit Working

Have fun with your remotely controlled servo motor.

With the same concept you can remotely control everything you need from a single LED to any device in your room.

2 People Made This Project!


  • Made with Math Contest

    Made with Math Contest
  • Multi-Discipline Contest

    Multi-Discipline Contest
  • Robotics Contest

    Robotics Contest

52 Discussions


4 years ago on Introduction

Very nice instructable mohamed ! :)
One doubt i have is, the servo runs continuously for as long as the button is pressed or what ?

2 replies

No, it runs continuously for first click and stops for second click.

that's because the remote doesn't send continuous signal for one click.

check that you copied IRremote library to arduino libraries, and try to remove RobotIRremote library which is mainly existed in arduino libraries so that the code work correctly.


Tip 3 months ago on Step 4

Remote HEX codes

ESP8266Basic variables

= "e318261b:UNKNOWN:32"

IR_CH = "511dbb:UNKNOWN:32"

IR_CHplus = "ee886d7f:UNKNOWN:32"

IR_PREV = "52a3d41f:UNKNOWN:32"

IR_NEXT = "d7e84b1b:UNKNOWN:32"

IR_PLAY = "20fe4dbb:UNKNOWN:32"

IR_VOLminus= "f076c13b:UNKNOWN:32"

IR_VOLplus = "a3c8eddb:UNKNOWN:32"

IR_EQ = "e5cfbd7f:UNKNOWN:32"

IR_0 = "c101e57b:UNKNOWN:32"

IR_100plus = "97483bfb:UNKNOWN:32"

IR_200plus = "f0c41643:UNKNOWN:32"

IR_1 = "9716be3f:UNKNOWN:32"

IR_2 = "3d9ae3f7:UNKNOWN:32"

IR_3 = "6182021b:UNKNOWN:32"

IR_4 = "8c22657b:UNKNOWN:32"

IR_5 = "488f3cbb:UNKNOWN:32"

IR_6 = "449e79f:UNKNOWN:32"

IR_7 = "32c6fdf7:UNKNOWN:32"

IR_8 = "1bc0157b:UNKNOWN:32"

IR_9 = "3ec3fc1b:UNKNOWN:32"

For the Remote in the image (Cheap Chinese model with "Car MP3" logo along bottom edge

remote CarMP3.jpg

9 months ago

Hola, soy nuevo en esto y me larga un error diciéndome

Tarjeta:"Arduino/Genuino Uno"
C:\Users\usuario\AppData\Local\Temp\arduino_modified_sketch_256790\IRrecvDemo.ino:36:10: warning: ISO C99 requires whitespace after the macro name
#define más 0xA3C8EDDB // botón de rotación en el sentido de las agujas del reloj
IRrecvDemo:48: error: stray '\363' in program
configuración del vacío ()
IRrecvDemo:48: error: stray '\355' in program
IRrecvDemo:55: error: stray '\355' in program
bucle de vacío ()
IRrecvDemo:61: error: stray '\341' in program
if (results.value == más)
IRrecvDemo:61: error: stray '\341' in program
IRrecvDemo:39: error: redefinition of 'int RECV_PIN'
int RECV_PIN = 2; // pin del receptor IR
C:\Users\usuario\AppData\Local\Temp\arduino_modified_sketch_256790\IRrecvDemo.ino:11:5: note: 'int RECV_PIN' previously defined here
int RECV_PIN = 11;
IRrecvDemo:41: error: expected initializer before 'int'
int val; //Ángulo de rotación
IRrecvDemo:44: error: redefinition of 'IRrecv irrecv'
IRrecv irrecv (RECV_PIN);
C:\Users\usuario\AppData\Local\Temp\arduino_modified_sketch_256790\IRrecvDemo.ino:13:8: note: 'IRrecv irrecv' previously declared here
IRrecv irrecv(RECV_PIN);
IRrecvDemo:46: error: 'resultados' does not name a type
resultados decode_results;
IRrecvDemo:48: error: 'configuraci' does not name a type
configuración del vacío ()
IRrecvDemo:55: error: 'bucle' does not name a type
bucle de vacío ()
exit status 1
stray '\363' in program
Este reporte podría tener más información con
"Mostrar salida detallada durante la compilación"
opción habilitada en Archivo -> Preferencias.
!!!!!Si me podrías ayudar te lo agradecería!!!!!


Question 10 months ago

I want a code to control 2 servos with ir remote.please give me the code for that,your project was great and I was successful in controlling one servo


Question 1 year ago on Step 4

Hey this is brilliant. Only issue is I replace the existing hex codes with my hex codes but it then says that they aren't defined. I'm new to this stuff. Help would be greatly appreciated

1 answer

Answer 10 months ago

Just put 0x in front of your hex code.

For example.....0xffe056


Question 10 months ago on Step 2

the wiring in your last picture is confusing from the diagram. ??


1 year ago

I've been repeating this over and over again but the codes are not showing in the serial monitor... What on earth did I miss ???

1 reply

Reply 1 year ago

1.único que tienes que cambiar es la sección de pin digital, ya que está en el numero 11 (creo que era ese), tu lo tienes que poner en el 9.


1 year ago

mohamed i love you thank u so much you absolutley made my day

Iam copied the ir remote library in the arduino library but I didnt see the irremote demo on the examples plz help me