Control Robot With a TV Remote

9,940

205

30

Posted

Introduction: Control Robot With a TV Remote

Raspberry Pi Contest

Runner Up in the
Raspberry Pi Contest

Since there was no space for breadboard and arduino, I built a small tower above the battery holder with cardboard. Click here for the VIDEO

Skill level: medium

Time taken to build: 1 hour

Step 1: Introduction

In this instructable, I will show how to control a robot with infrared TV remote. I'm sure you all are using remotes to operate electronics, but have you ever wonder how they work?

Infrared signals are beams of light that operate at a wavelength that cannot be seen with a naked eye. When you press a button from your remote, the LED on the remote will turnoff and on in an unique pattern sending the signal to the receiver in the TV. The received signals pluses are converted to electrical signals that are further converted into data in the receiver's electronics.

For this, we are only concerned on receiving the signals. For the best results use any Sony remote.

Step 2: Materials

This project is an update to my previous instructable.

1. IR Receiver Module 38 kHz TSOP4838 ( ebay- 0.99 cents)

2. Breadboard

3. LED

4. On/ Off switch

Step 3: Procedure

Before moving any further, download and install infrared library. so visit https://github.com/shirriff/Arduino-IRremote/

Steps on how to install a library can be found here. This project heavily relies on coding.

Now we need to select the HEX codes of the remote to use it to send directions to our robot. Connect the IR receiver to the arduino as shown in the schematics. Then, open the serial monitor and press four remote buttons you wanted to use to control the movements of the robot ( I used the up/down arrows, you could use numbers instead). Jot down the HEX code.

<p>int receiverpin= 11;<br>#include <IRremote.h></p><p><irremote.h><irremoteint.h><irremotetools.h>IRrecv irrecv(receiverpin); // create instance of irrecv
decode_results results;</irremotetools.h></irremoteint.h></irremote.h></p><p>void setup() 
{
Serial.begin(9600);
irrecv.enableIRIn();
}</p><p> void loop()
  {
   if (irrecv.decode(&results)) // have we received an IR signal?
    {
        Serial.print(results.value, HEX); // display IR code on the Serial Monitor
        Serial.print(" ");
        irrecv.resume(); // receive the next value
     }
   }</p>

I got the following Hex codes:

Up arrow= 9CB47

Down= 5CB47

Left= 3CB47

Right= DCB47

Test ends here. Full setup will be explained in the schematics and code section.

Step 4: Schematics

In addition to my previous project's schematics, this setup should be accompanied with it.

Unlike previous project, there is a slight change in the pins that are connected to the motor are as follows:

Right side
Pin 1 --------------------------------- 4 of Arduino

Pin 2 --------------------------------- 7

Pin 3 --------------------------------- 6 (PMW pin)

Pin 4 --------------------------------- 13

Pin 5 --------------------------------- 12

Pin 6----------------------------------- 9 (PMW pin)

If you find the robot tracks are rotating in opposite directions, that is clockwise and anti-clockwise or vice-versa, reverse the pins (4-7 to 7-4) or numbers in the code.

see the full code in next step.

Step 5: Code

<p>int receiverpin= 11;<br>#include <IRremote.h><irremote.h></irremote.h></p><p>IRrecv irrecv(receiverpin); // create instance of irrecv
decode_results results;</p><p>void setup() 
{
  Serial.begin(9600);

  //left motor 
  pinMode(4,OUTPUT); //
  pinMode(7,OUTPUT);
  pinMode(6,OUTPUT); //pwm
  //right right
  pinMode(13,OUTPUT);
  pinMode(12,OUTPUT);
  pinMode(9,OUTPUT);//pwm
  
  irrecv.enableIRIn(); // start the receiver
}</p><p>void onLED(int pin, int voltage)
{
  digitalWrite(pin, voltage);
}</p><p>void goForward(int duration, int pwm)
{
   digitalWrite(4,HIGH);
   delay(duration);//100
   digitalWrite(7,LOW);
   analogWrite(6,pwm);//right motor
  
   digitalWrite(13,HIGH);
   delay(duration);
   digitalWrite(12,LOW);
   analogWrite(9,pwm);// right motor 
}</p><p>void fullReverse(int duration, int pwm)
{
   digitalWrite(4,LOW);
   delay(duration);
   digitalWrite(7,HIGH);
   analogWrite(6,pwm);
  
   digitalWrite(13,LOW);
   delay(duration);
   digitalWrite(12,HIGH);
   analogWrite(9,pwm);// right motor
    
}</p><p>void fullStop(int duration, int pwm)
{
   digitalWrite(4,LOW);
   delay(duration);
   digitalWrite(7,LOW);
   analogWrite(6,pwm);// 
  
   digitalWrite(13,LOW);
   delay(duration);
   digitalWrite(12,LOW);
   analogWrite(9,pwm);// right motor
}</p><p>void turnLeft(int duration, int pwm)
{
   digitalWrite(13,LOW); 
   delay(duration);
   digitalWrite(12,HIGH);
   analogWrite(9,pwm);// right motor
  
   digitalWrite(4,HIGH);
   delay(duration);
   digitalWrite(7,LOW);
   analogWrite(6,pwm);
    
}</p><p>void turnRight( int duration, int pwm)
{
   digitalWrite(13,HIGH); 
   delay(duration);
   digitalWrite(12,LOW);
   analogWrite(9,pwm);// right motor
  
   digitalWrite(4,LOW);
   delay(duration);
   digitalWrite(7,HIGH);
   analogWrite(6,pwm);
  
}
void translateIR()
// takes action based on IR code received
  // uses Sony IR codes
{
  switch(results.value)
  {
    case 0x9CB47: goForward(100,120); // (x,y), adjust the y values for speed
    break;</p><p>    case 0x5CB47: fullReverse(100,100); 
    break;</p><p>    case 0x3CB47: turnLeft(100,120);
    break; </p><p>    case 0xDCB47: turnRight(100,120);
    break; </p><p>    default:fullStop(100,0);
    break;</p><p>  }
}</p><p> void loop()
  {
   if (irrecv.decode(&results)) // have we received an IR signal?
    {
      onLED(2,255); // on led when the signal is being recieved 
      translateIR();
        for (int z = 0 ; z < 2 ; z++) // ignore the repeated codes
           {
              irrecv.resume(); // receive the next value
            }
     }
    else
    {
      onLED(2,0); // off if the signal is not being recived
    }
  }</p>

Step 6: Future Updates

Very soon I'll be posting on how to make an object avoiding robot. Followed by, camera and wifi controlled robot.

So, stay tuned for more instructables. Until then, hasta la vista.

Thanks

Saimouli Katragadda

Any donations will be used for future projects, thank you!
Donate

Share

Recommendations

  • Microcontroller Contest

    Microcontroller Contest
  • Spotless Contest

    Spotless Contest
  • Science of Cooking

    Science of Cooking
user

We have a be nice policy.
Please be positive and constructive.

Tips

Questions

28 Comments

Hi,

I have a different generic remote to the sony remote and the hex codes for it says it cant define them could you help

I made one and it was working fine until it suddenly stopped with weird responses, like one wheel going forward and other going backwards or sometimes moving forward and not changing directions on following keypresses. i checked the receiver using a multimeter and there was a voltage change everytime a remote key was pressed. but voltage across microcontroller's pins was not changing as coded. plz help

This is interesting, This would make a great weapon for military, great idea!

Hi, when compiling the code to read my remote control, I get this error message:

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

CAn you help?

Try the code below. Did you install the library?

Yes I did, I just don't understand where the 'TKD2' comes from,

I also tried thr recive code from here:


http://www.righto.com/2009/08/multi-protocol-infra...

which is the same as you posted in the next comment but I get the same error...

Well I will sort it out after my vacations ;-) thank you anyway for the nice instructable


Sorry for not being helpful. I looked into it and found a forum : https://github.com/z3t0/Arduino-IRremote/issues/98

Thank you for your help, I am still unable to test the code on Arduino, but removing RobotIRremote from the libraries and replacing it with Arduino-IRremote-master from https://github.com/z3t0/Arduino-IRremote the code compiles with no errors.

Sorry for late feedback but I am still on vacation ;-)

Tested with Arduino, works fine, thanks again.