Project tutorial
Infrared controlled robot

Infrared controlled robot © GPL3+

Learn how to control a robot with a infrared TV remote

  • 3,402 views
  • 0 comments
  • 12 respects

Components and supplies

IR Receiver Module
×1
12002 04
Breadboard (generic)
×1
Infrared LED
×1
A000066 iso both
Arduino UNO & Genuino UNO
×1

About this project

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.

Before moving any further, download and install infrared library. so visithttps://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. 

I got the following Hex codes:

Up arrow= 9CB47

Down= 5CB47

Left= 3CB47

Right= DCB47

*Note:- You'r Hex codes might be different, use the library form github and schematic 1 to setup and note codes

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:

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.


Code

Ir_tank_fullcode.inoC/C++
 int receiverpin= 11;
#include <IRremote.h>

IRrecv irrecv(receiverpin); // create instance of irrecv
decode_results results;

void setup() 
{
  Serial.begin(9600);
  //pinMode(4,OUTPUT); // LED
  //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
}

void onLED(int pin, int voltage)
{
  digitalWrite(pin, voltage);
}

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 
}

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
    
}

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
}

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);
    
}

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,80);
    break;

    case 0x5CB47: fullReverse(100,77);
    break;

    case 0x3CB47: turnLeft(100,120);
    break; 

    case 0xDCB47: turnRight(100,120);
    break; 

    default:fullStop(100,0);
    break;

  }
}

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

Schematics

Infrared receiver schematics
Fkvee7eidh7oug5.large

Comments

Similar projects you might like

MeArm Robot Arm - Your Robot - V1.0

Project tutorial by Benjamin Gray

  • 19,302 views
  • 3 comments
  • 34 respects

2WD Voice Controlled Robot with Arduino and BitVoicer Server

Project tutorial by Marcio Tamagushi

  • 10,203 views
  • 11 comments
  • 32 respects

Voice Controlled Robot using your Smart Phone

Project tutorial by Ahmed Yassin

  • 3,062 views
  • 0 comments
  • 7 respects

Hand Gesture Controlled Robot

Project tutorial by Mayoogh Girish

  • 54,973 views
  • 78 comments
  • 65 respects
Add projectSign up / Login