RobotRemoteControl

Reuse that old tv-remote to command the bot on distance.

Remote Control

This example is considered experimental, you will need to install the IR-Remote library by Ken Shirriff on your IDE for it to run, read the code for more information

If you connect a IR remote receiver to the robot, you can control it like controlling your TV set. Take a Sony compatible remote controller, map some buttons to different actions, and you can make the robot move around without touching it!

Hardware Required

  • Arduino Robot

  • Infrared sensor

  • cable to connect the sensor

  • Sony compatible remote control

Instruction

  1. Connect the IR sensor to TKD2 on the top board, using the cable provided.

  2. Fix the sensor on the board

  3. Upload the example, unplug USB and turn on power

  4. After the starting screen, use the remote control to send it commands

  5. Press the buttons you've coded to move the robot.

  6. You can see received signals and commands (if recognized) on the LCD.

  7. If you want to customize your commands:

  8. Press the buttons on remote control and write down the values showing up on LCD.

  9. Locate these lines in the example code: #define IR_CODE_FORWARD 0x2C9B #define IR_CODE_BACKWARDS 0x6C9B #define IR_CODE_TURN_LEFT 0xD4B8F #define IR_CODE_TURN_RIGHT 0x34B8F

  10. Change the values here to the ones you saw on the screen.

Try it out

Use the remote control with the robot
Use the remote control with the robot

Code

1/* 08 Remote Control
2
3 If you connect a IR receiver to the robot,
4
5 you can control it like a RC car.
6
7 Using the remote control comes with sensor
8
9 pack, You can make the robot move around
10
11 without even touching it!
12
13 Circuit:
14
15 * Arduino Robot
16
17 * Connect the IRreceiver to D2
18
19 * Remote control from Robot sensor pack
20
21 based on the IRremote library
22
23 by Ken Shirriff
24
25 http://arcfn.com
26
27 created 1 May 2013
28
29 by X. Yang
30
31 modified 12 May 2013
32
33 by D. Cuartielles
34
35 This example is in the public domain
36
37 */
38
39// include the necessary libraries
40#include <RobotIRremote.h>
41#include <RobotIRremoteTools.h>
42#include <ArduinoRobot.h>
43#include <Wire.h>
44
45// Define a few commands from your remote control
46#define IR_CODE_FORWARD 284154405
47#define IR_CODE_BACKWARDS 284113605
48#define IR_CODE_TURN_LEFT 284129925
49#define IR_CODE_TURN_RIGHT 284127885
50#define IR_CODE_CONTINUE -1
51
52bool isActing = false; //If the robot is executing command from remote
53long timer;
54
55const long TIME_OUT = 150;
56
57void setup() {
58
59 // initialize the Robot, SD card, display, and speaker
60
61 Serial.begin(9600);
62
63 Robot.begin();
64
65 Robot.beginTFT();
66
67 Robot.beginSD();
68
69 // print some text to the screen
70
71 beginIRremote(); // Start the receiver
72}
73
74void loop() {
75
76 // if there is an IR command, process it
77
78 if (IRrecived()) {
79
80 processResult();
81
82 resumeIRremote(); // resume receiver
83
84 }
85
86 //If the robot does not receive any command, stop it
87
88 if (isActing && (millis() - timer >= TIME_OUT)) {
89
90 Robot.motorsStop();
91
92 isActing = false;
93
94 }
95}
96void processResult() {
97
98 unsigned long res = getIRresult();
99
100 switch (res) {
101
102 case IR_CODE_FORWARD:
103
104 changeAction(1, 1); //Move the robot forward
105
106 break;
107
108 case IR_CODE_BACKWARDS:
109
110 changeAction(-1, -1); //Move the robot backwards
111
112 break;
113
114 case IR_CODE_TURN_LEFT:
115
116 changeAction(-0.5, 0.5); //Turn the robot left
117
118 break;
119
120 case IR_CODE_TURN_RIGHT:
121
122 changeAction(0.5, -0.5); //Turn the robot Right
123
124 break;
125
126 case IR_CODE_CONTINUE:
127
128 timer = millis(); //Continue the last action, reset timer
129
130 break;
131
132 }
133}
134void changeAction(float directionLeft, float directionRight) {
135
136 Robot.motorsWrite(255 * directionLeft, 255 * directionRight);
137
138 timer = millis();
139
140 isActing = true;
141}

Contribute to Arduino

Join the community and suggest improvements to this article via GitHub. Make sure to read out contribution policy before making your pull request.

Missing something?

Check out our store and get what you need to follow this tutorial.

Suggest Changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. You can read more on how to contribute in the contribution policy.