Controlling Servo Motor Using IR Remote Control

59,354

442

49

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

Intro: Controlling Servo Motor Using IR Remote Control

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!

Recommendations

  • Furniture Contest 2018

    Furniture Contest 2018
  • Fix It! Contest

    Fix It! Contest
  • Audio Contest 2018

    Audio Contest 2018

49 Discussions

0
None
akshay.d21

3 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.

0
None
MennaM10

9 months 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
0
None
VicenteS22MennaM10

Reply 12 days 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.

0
None
FrankE51

2 months ago

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

0
None
HB9

Question 5 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

0
None
Abhijith Assariparambil

Question 7 months ago on Introduction

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

0
None
MuhdR6

8 months ago

where to put the remote code

0
None
AlanC230

8 months ago

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

0
None
1/104

10 months ago

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

0
None
bilagaana

10 months ago

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