E Shore Technologies - Online Robotic Center

  • Increase font size
  • Default font size
  • Decrease font size
Home All Projects IR Remote Control Mobile Robot


IR Remote Control Mobile Robot

E-mail Print PDF

In this project I am going to add in IR Remote Control (Infrared Kit) to the previous 2 Wheels Robot Platform (link).

Hardware

The first step is to mount the IR Receiver Module to the platform. You can use your creativity to do this. For me, I mount it at the front side of the platform.

Connect the 3 pin from the IR Receiver Module to 5V (Red), GND (Black) and Digital Pin 2 (Green).

 

Closer view, there are total of 5 jumper wire connected to Arduino, 2 for the 7.2V battery input (+ve and –ve), and another 3 for IR Receiver Module (5V, GND, and Signal).

Now, we are done with the hardware, let's move on to the coding/programming of the robot.

IRremote Library

For the coding, we will be using the IRremote library to encode the IR signal from the remote. You can download the IRremote library from the product page (http://www.e-shore.com.my/homepage/eshop/infrared-kit), click on the Arduino Library to initiate the download.

Then follow this guide (http://www.e-shore.com.my/homepage/installation-guide/arduino-ide/175-arduino-ide-new-library-installation-guide-windows.html) to install the IRremote library to your Arduino IDE. After installing the library, open the IRremote example called IRrecvDemo.

This example code will basically wait for IR signal from remote, once it receive IR signal, it will encode the signal and send the signal to PC through UART on Arduino. Modify the code by changing the RECV_PIN to 2, because we are using Digital Pin 2 for the Signal from IR Receiver Module.

After that upload the code to the 2 Wheel Robot Platform. Open Hyper Terminal on your PC and connect Hyper Terminal to the corresponding COM Port for Arduino UNO. Use the default setting for the COM Port on Hyper Terminal.

Try to press any button on the IR Remote Control and the Hyper Terminal should receive HEX code representing each button on the Remote Control. Take note that if you press and hold a button, the Hyper Terminal will first received the HEX code for that button, and after the first Hex code, it will keep receiving "FFFFFFFF" code until you release that button (this behavior is different for different remote control). We will need to take care of that in the coding later.

Table of the HEX Code for all button on the Remote Control.

Button

HEX Code

Button

HEX Code

Button

HEX Code

POWER

FD00FF

VOL+

FD807F

FUNC/STOP

FD40BF

PREVIOUS

FD20DF

PLAY/PAUSE

FDA05F

NEXT

FD609F

DOWN

FD10EF

VOL-

FD906F

UP

FD50AF

KEY 0

FD30CF

EQ

FDB04F

ST/REPT

FD708F

KEY 1

FD08F7

KEY 2

FD8877

KEY 3

FD48B7

KEY 4

FD28D7

KEY 5

FDA857

KEY 6

FD6897

KEY 7

FD18E7

KEY 8

FD9867

KEY 9

FD58A7

Code

For the code, I will use the template code from 2 Wheels Robot Platform (http://www.e-shore.com.my/homepage/all-projects/134-2-wheels-robot-platform-setup.html) to start. The code is a bit long; you can also download the full IR Remote Control Mobile Robot Code from the end of this article. Make sure that IRremote library is installed to ensure the functionality of the code.

//=======================================================================
//  IR Remote Control Mobile Robot
//  www.e-shore.com.my
//=======================================================================
 
#include <IRremote.h>
#include <IRremoteInt.h>
 
//motor control pin
const int E1=5;    //motor 1 (right) enable pin
const int M1=4;    //motor 1 (right) direction pin
const int E2=6;    //motor 2 (left) enable pin
const int M2=7;    //motor 2 (left) direction pin
 
//IR Receiver Module Pin and variable
int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;
 
//  setup function
//=======================================================================
void setup()
{
//configure all motor control pin as output
pinMode(E1,OUTPUT);
pinMode(M1,OUTPUT);
pinMode(E2,OUTPUT);
pinMode(M2,OUTPUT);
 
//disable both motor by default
digitalWrite(E1,LOW);
digitalWrite(E2,LOW);
 
//start IR receiver
irrecv.enableIRIn();
}
 
//  loop function
//=======================================================================
void loop()
{
//IR signal received
if(irrecv.decode(&results))
{
//forward (VOL+)
if(results.value==0xFD807F)
{
motor(40,40);
}
//reverse (VOL-)
else if(results.value==0xFD906F)
{
motor(-40,-40);
}
//rotate left (PREVIOUS)
else if(results.value==0xFD20DF)
{
motor(-30,30);
}
//rotate right (NEXT)
else if(results.value==0xFD609F)
{
motor(30,-30);
}
//forward left (POWER)
else if(results.value==0xFD00FF)
{
motor(10,40);
}
//forward right (FUNC/STOP)
else if(results.value==0xFD40BF)
{
motor(40,10);
}
//reverse left (DOWN)
else if(results.value==0xFD10EF)
{
motor(-10,-40);
}
//reverse right (UP)
else if(results.value==0xFD50AF)
{
motor(-40,-10);
}
 
//receive the next value
irrecv.resume();
 
//short delay waiting for repeating IR signal
// (prevent it to stop if no signal received)
delay(150);
}
//no IR signal received
else
{
//right wheel stop
digitalWrite(E1,LOW);
 
//left wheel stop
digitalWrite(E2,LOW);
}
}
 
//  extra function
//=======================================================================
 
//function to control the motor
void motor(int left, int right)
{
//limit the max speed
if(left>255)left=255;
else if(left<-255)left=-255;
if(right>255)right=255;
else if(right<-255)right=-255;
 
//left wheel forward
if(left>0)
{
//left wheel direction forward
digitalWrite(M2,HIGH);
//left wheel speed
analogWrite(E2,left);
}
//left wheel reverse
else if(left<0)
{
//left wheel direction reverse
digitalWrite(M2,LOW);
//left wheel speed
analogWrite(E2,-left);
}
//left wheel stop
else
{
//left wheel stop
digitalWrite(E2,LOW);
}
 
//right wheel forward
if(right>0)
{
//right wheel direction forward
digitalWrite(M1,LOW);
analogWrite(E1,right);
}
//right wheel reverse
else if(right<0)
{
//right wheel direction reverse
digitalWrite(M1,HIGH);
analogWrite(E1,-right);
}
//right wheel stop
else
{
//right wheel stop
digitalWrite(E1,LOW);
}
}

The button assignment for the robot control is as follows:

The code will basically wait for IR Code, compare the received code with the HEX Code for the buttons involve, and perform the action based on the pressed button. From the code, you will see that there is a short delay of 150ms at line 91 which is required to wait for the repeating IR signal if the button is being held. This delay also prevents the code to quickly jump to "no IR signal received" portion that will stop the motor, even if the button is being held.

In the coding, the function motor( left , right ) will be use to ease the control of the left and right wheel. There are 2 variable for the function (left and right), which represent the left wheel and right wheel. Positive value set the motor forward and negative value will set the motor reverse, and the speed will be determine by the absolute value of these variable. For example calling the function motor(100,-70) will set the left wheel forward with speed of 100 and right wheel reverse with the speed of 70.

The sample video of the demo for IR Remote Control Mobile Robot:

Hardware List

  1. 2 Wheels MiniQ Balancing Robot Chassis or 2 Wheels MiniQ Robot Chassis (comes with castor)
  2. Arduino UNO
  3. 2A Motor Driver Shield for Arduino
  4. Infrared Kit
  5. 7.4V 500mAH Lipo Rechargeable Battery
  6. PCB Stands, screws, nuts and also some components
Attachments:
FileFile size
Download this file (IR_Remote_Control_Mobile_Robot.zip)IR Remote Control Mobile Robot1 Kb
 

Comments  

 
#4 burberry outlet 2014-04-15 21:26
Since the 1970s, Mulberry has for ages been the most innovative and avant-grade popularity in the uk.
Paper might be the oldest form of flexible product packaging.
In 1690, this method was adopted in Germantown, Pennsylvania.
Quote
 
 
#3 AnalysIR 2013-07-04 04:43
Hi Guys
We have just launched a Crowdfunding campaign on IndieGoGo for AnalysIR - IR Decoder & Analyzer (Arduino & Raspberry Pi). Currently we support 17 IR protocols and are looking for more to add as part of the campaign. Suggestions Welcome!

You can find out more about the Campaign on http://bit.ly/1b7oZXH or Screenshot via www.AnalysIR.com
Quote
 
 
#2 Jerod 2012-10-19 04:47
I just wanted to say - thank you. I coded mine differently, and it was working well. I was still having issues with the control being jittery. I figured out the issue was simply that I was missing that 150ms delay. Works great now. Also, I have YOUR code on my bot right now and am playing around with it. Thanks a lot.
Quote
 
 
#1 Mauricio 2012-04-24 01:40
wow, looks awesome
am looking for something like this
well explained tutorial :-)
sorry for my english ;-)
Quote
 

Add comment


Security code
Refresh

Login/Register

E-Mail Address:

Password:


Find us on Facebook



Sponsored Links