Controlling Servo Motor Using IR Remote Control





Introduction: 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.

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!


  • Clocks Contest

    Clocks Contest
  • Creative Misuse Contest

    Creative Misuse Contest
  • Oil Contest

    Oil Contest

48 Discussions

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.

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


Question 3 months 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

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

I followed your instructions and downloaded the library and copy it in the arduino library but I didnt find irremote demo plz help me


6 months ago

where to put the remote code

how do i adjust the cw and ccw rotation angle? default seems to be 90 but i need 45. thanks

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 ???


8 months ago

Thanks for the tutorial. How do I make the servo turn more than 90 degrees?

Adding links to the parts list would be very useful, for those of us who are completely new to this type of project.

Guys If you have the same error code like the error code bellow well just delete the file called "robotIRremote" in the Arduino Libraries since it have the same program name inside the file

Arduino: 1.8.1 (Windows 10), Board: "Arduino Duemilanove or Diecimila, ATmega328"

Build options changed, rebuilding all

C:\Program Files (x86)\Arduino\libraries\RobotIRremote\src\IRremoteTools.cpp:5:16: error: 'TKD2' was not declared in this scope

int RECV_PIN = TKD2; // the pin the IR receiver is connected to


Multiple libraries were found for "IRremote.h"

Used: C:\Program Files (x86)\Arduino\libraries\RobotIRremote

Not used: C:\Program Files (x86)\Arduino\libraries\Arduino-IRremote-master

exit status 1

Error compiling for board Arduino Duemilanove or Diecimila.

This report would have more information with

"Show verbose output during compilation"

option enabled in File -> Preferences