Controlling Servo Motor Using IR Remote Control

78,799

450

52

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!

Recommendations

  • Battery Powered Contest

    Battery Powered Contest
  • Plywood Challenge

    Plywood Challenge
  • Plastic Contest

    Plastic Contest

52 Discussions

0
akshay.d21
akshay.d21

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

0
mohamed soliman
mohamed soliman

Reply 5 years ago on Introduction

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.

0
giantpair
giantpair

Reply 4 years ago

Can I make it run continuously while pushing the button?

0
elhadi30
elhadi30

5 years ago on Introduction

nice .work ....but Is it possible to increase the speed of rotation

0
mohamed soliman
mohamed soliman

Reply 5 years ago on Introduction

yes it's possible, by decreasing the delay time, it's the time of rotation of 1 degree.

0
nilesh2690
nilesh2690

5 years ago on Introduction

Hello I want to control Servo motor using count from webpage?

How can i do that?

0
mohamed soliman
mohamed soliman

Reply 5 years ago on Introduction

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

Tip 1 year ago on Step 4

Remote HEX codes


ESP8266Basic variables


IR_CHminus
= "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
0
matias2018
matias2018

1 year 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!!!!!

0
Saksham2
Saksham2

Question 1 year 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

0
HB9
HB9

Question 2 years 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

0
Saksham2
Saksham2

Answer 1 year ago

Just put 0x in front of your hex code.

For example.....0xffe056

0
Kalfonz
Kalfonz

Question 1 year ago on Step 2

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

0
MennaM10
MennaM10

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

0
VicenteS22
VicenteS22

Reply 2 years 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
FrankE51
FrankE51

2 years 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