$USD
  • EUR€
  • £GBP
  • $USD
TUTORIALS Robotics

Control Robot With A TV Remote

DFRobot Sep 06 2015 269
DFRobot
DFRobot
DFRobot

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

DFRobot
DFRobot


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

DFRobot


 
DFRobot


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.

Please VOTE, if you like it.

Thanks

Saimouli Katragadda


Source:Instructables

 
REVIEW