Remote Control Slam Bot

How to turn an autonomous robot into a remote control Slambot

by TY student Vladimir Trofimov

After you have finished RoboSlam, where the robot is autonomous and uses a colour sensor, you might be thinking “What can I do next?” Well you could move on and add a receiver to control the robot with an Infrared remote.

remote

Here is the one that I used.

Materials needed for this task,
•    IR universal TV remote (see above)
•    2  infrared receivers (GP1UX310QS see below)
•    AAA batteries for the remote
•    A 4.7 kΩ resistor (or two 10kΩ resistors wound together)
•    three 6cm wires with 0.5cm stripped at each end

receiver

Here is an Infra red receiver showing the “dome” which is the part that does the receiving of infra-red signals. We are using two infrared receivers in order to allow you to control the robot from every angle.

Start by placing one receiver in holes I16-18 with the little “dome” on the IR device facing in towards the centre of the breadboard then the place the second IR receiver right beside the first in holes H18-20 but this time the “dome” should facing out towards the edge of the breadboard. Now place a blue wire from J2 to J17, a red wire from J18 to the “red rail” and a black wire from I20 to the “black rail”.

Then in order for the IR signals from the remote to reach both infrared receivers you need to connect the two. Grab a small black wire and connect it between holes J20 to J16 and then connect a small blue wire from J19 to J17. Then place the resistor (or pair of twisted resistors) between F20 and the red “rail”.

Finally if you wish to power the circuit from a battery pack, connect the red “rail” to A15  with a red wire and the blue “rail” to A14 with a black wire. Then plug the battery leads in (Red lead to red “rail”, black lead to blue “rail”)

The circuit should now look like this:

circuit1

This is how it should look on your current robot:

 

 

“Capture” the IR codes from your remote

Each time you press a button on your remote control it sends out an IR Code, a binary number that is represented as a series of short flashes of Infra red. (You can “see” these flashes if you point the camera of an Android phone at the end of the remote). You obviously need your Arduino to control the robot – but it will get instructions from the remote control unit. So we need to find the IR codes sent by your particular remote. We need to find these codes so that the program will “notice” when you press a particular button on the remote. First of all however, you will need to download an IR remote library.

In the Sketch Menu on the Arduino editor, click on Include Library, then select Manage Libraries and search for IR Remote, install it and make sure it is the latest version.

managelib

If you are using an older version of the Arduino editor, the Manage Libraries option is not there , then you you need to click on Add Library , and download the IR remote library directly from the web. Here’s a link you can use for that purpose from the site github.com:

https://github.com/z3t0/Arduino-IRremote/releases/download/2.1.0/Arduino-IRremote-dev.zip

Open the Zip file, double-click and run the exe and then restart the Arduino Editor. The IRremote library should now be visible in the libraries window.

libraries.jpg

As stated above, we need to find the codes coming from the remote control. The following code adapted from one of Ken Shirriff’s IR receiver library examples will do that.

// Test code for capturing IR codes and sending them to serial monitor.
// Modified from code and IR receiver library by Ken Shirriff
// Please see http://www.righto.com for details
// Vladimir Trofimov March 2017
//

#include
int IR_PIN = 11;
IRrecv irrecv(IR_PIN);
decode_results results;

void setup()
{
//set up the serial port at 9600 baud
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
Serial.println("Ready to receive... ");
}

void loop() {
//take in the IR signals from the remote control
if (irrecv.decode(&results)) {
Serial.print("Receiving: ");
Serial.print(results.value, HEX);
Serial.print(" ...As decimal: ");
Serial.println(results.value);
irrecv.resume(); // Receive the next value
}
delay(100);
}

Now you can use the demo to check out if the commands from the remote, to do this, you should select Serial Monitor from the Tools menu.

Next you need to record the IR codes that come from the chosen five buttons for going forward,back,left,right and stop. I used the buttons shown in the diagram.

buttons

Press each of the selected buttons in turn and use the Serial Monitor in order to see the code for each command.

So for example I press forward on my universal remote control that I used (€4.50 in EuroSaver) and here is what I see in the Serial Monitor.

serialmon1

The left code 20DF02FD is in hexadecimal format which is a “base 16” format that engineers and computer scientists use to represent binary numbers understood by computers. but the Arduino counts in decimals just like we would, so we take the code on the right which is 551486205. So basically what I am saying is that 20DF02FD hexadecimal = 551486205 decimal.

These are the codes that I see on the serial monitor when I press FORWARD-BACK-LEFT-RIGHT-STOP in sequence. You will probably have a different remote, but the process is the same.

serialmonitor

These codes that you get are then used for the full program which will allow you to control the robot. Here is the code to control the robot. Paste it into the editor and compile and download, and then you are ready to control the robot. The code here uses the IR codes for my remote. You need to add in the ones that apply to yours.

// Infra-red remote control of a RoboSlam robot.
// Uses the IR Receiver library by Ken Shirriff
// Please see http://www.righto.com for details
// The basic code for the robot is based on Ted's code.
//
// Vladimir Trofimov
// March 2017

#include

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver

// Digital output for LED
pinMode(2, OUTPUT);

// Digital outputs for left motor
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);

// Digital outputs for right motor
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
}

void loop() {
if (irrecv.decode(&results)) {
//TURN LEFT 
//HEX CODE 20DFE01F
if (results.value==551542815){
Serial.println("LEFT");
// turn left for 1000ms
digitalWrite(2, HIGH); // LED on
digitalWrite(3, LOW);  // Left motor reverse
digitalWrite(4, HIGH);
digitalWrite(7, HIGH); // Right motor forward
digitalWrite(8, LOW);
}
//TURN RIGHT
//HEX CODE 20DF609F
if (results.value==551510175){
Serial.println("RIGHT");
digitalWrite(2, HIGH); // LED on
digitalWrite(3, HIGH); // Left motor forward
digitalWrite(4, LOW);
digitalWrite(7, LOW);  // Right motor reverse
digitalWrite(8, HIGH);
}

//GO FORWARD
//HEX CODE  20DF02FD
if (results.value==551486205){
Serial.println("FORWARD");
digitalWrite(2, LOW);  // LED off
digitalWrite(3, HIGH); // Left motor forward
digitalWrite(4, LOW);
digitalWrite(7, HIGH); // Right motor forward
digitalWrite(8, LOW);
}

//REVERSE
//HEX CODE 20DF827D
if (results.value==551518845){
Serial.println("REVERSE");
digitalWrite(2, LOW);  // LED off
digitalWrite(3, LOW); // Left motor forward
digitalWrite(4, HIGH);
digitalWrite(7, LOW); // Right motor forward
digitalWrite(8, HIGH);
}
//STOP
//HEX CODE 20DFC23D
if (results.value==551535165){
Serial.println("STOP");
digitalWrite(2, LOW);  // LED off
digitalWrite(3, LOW); // Left motor forward
digitalWrite(4, LOW);
digitalWrite(7, LOW); // Right motor forward
digitalWrite(8, LOW);
}

//Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
delay(100);
}

This then should allow you to control the robot from all directions like in the following video!

 

Vladimir Trofimov

Synge St. C.B.S.

Transition Year Intern

on the RoboSlam project

March 2017.

 

 

Advertisements