loading

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

<p>Hi,</p><p>I have a different generic remote to the sony remote and the hex codes for it says it cant define them could you help</p>
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
<p>It works fine, I had to set up the code a bit but it's cool! </p>
<p>This is interesting, This would make a great weapon for military, great idea!</p>
<p>Thanks</p>
<p>Hi, when compiling the code to read my remote control, I get this error message: </p><p><em>&quot;C:\Program Files (x86)\Arduino\libraries\RobotIRremote\src\IRremoteTools.cpp:5:16: error: 'TKD2' was not declared in this scope</em></p><p><em> int RECV_PIN = TKD2; // the pin the IR receiver is connected to&quot;</em></p><p>CAn you help?</p>
<p>Try the code below. Did you install the library?</p>
<p>Yes I did, I just don't understand where the <em>'TKD2' comes from,</em></p><p><em>I also tried thr recive code from here:</em></p><p><em><br></em></p><p><a href="http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html" rel="nofollow">http://www.righto.com/2009/08/multi-protocol-infra...</a></p><p>which is the same as you posted in the next comment but I get the same error...</p><p>Well I will sort it out after my vacations ;-) thank you anyway for the nice instructable</p><p><em> <br></em></p>
<p>Sorry for not being helpful. I looked into it and found a forum : https://github.com/z3t0/Arduino-IRremote/issues/98</p>
<p>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 <a href="https://github.com/z3t0/Arduino-IRremote" rel="nofollow">https://github.com/z3t0/Arduino-IRremote </a> the code compiles with no errors.</p><p>Sorry for late feedback but I am still on vacation ;-)</p>
<p>Tested with Arduino, works fine, thanks again.</p>
<p>int receiverpin= 11;</p><p>#include &lt;IRremote.h&gt;</p><p>IRrecv irrecv(receiverpin); // create instance of irrecv <br>decode_results results;</p><p>void setup() <br>{ <br>Serial.begin(9600); <br>irrecv.enableIRIn(); <br>}</p><p> void loop() <br> { <br> if (irrecv.decode(&amp;results)) // have we received an IR signal? <br> { <br> Serial.print(results.value, HEX); // display IR code on the Serial Monitor <br> Serial.print(&quot; &quot;); <br> irrecv.resume(); // receive the next value <br> } <br> }</p>
please tell me which motor did u used??
<p>I would like to make this robot using an android application with speed control . is that possible ?? </p>
Absolutely, just add/change the voltage values. Create a new function to control the speed and declare it in the main saying if I press a button go this much speed.
<p>Well Explained!</p>
<p>Thank you</p>
<p>I like this idea a lot! I seen you posted it in the raspberry pi competition but your only using a arduino. Does it still count?</p>
<p>Thanks. When I read the competition rules, they said raspberry pi or other microcontrollers. </p>
<p>Where does it say that because I looked over the rules but didn't see anything? I'm just wondering because my pi is still in shipping but my friend has an arduino that I could use instead of waiting.</p>
<p>Sorry W3RTZ, I'm wrong! I read &quot;The Raspberry Pi is a powerful microcontroller that utilizes the Python programming language to drive a multitude of components. For the Raspberry Pi Contest.&quot; I think I should buy raspberry pi now!!</p>
<p>No problem! I was just wanting to clarify. I guess I'll have to wait for my pi.</p>
<p>A great robot easily walkable.Cool project!</p>
<p>Thank you!</p>
Onto the robot?
<p>Yes, I did.</p>
Do you copy the pin part?
I have been working on one for a while now but I was not able to make it accept second command. I will try it your way. Thanks
<p>Sure and if you have any questions don't hesitate to ask questions</p>

About This Instructable

9,442views

201favorites

License:

More by saimouli:Control robot with a TV remote Make a Robot With Arduino for Beginners  
Add instructable to: