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
Connect the IR sensor to TKD2 on the top board, using the cable provided.
Fix the sensor on the board
Upload the example, unplug USB and turn on power
After the starting screen, use the remote control to send it commands
Press the buttons you've coded to move the robot.
You can see received signals and commands (if recognized) on the LCD.
If you want to customize your commands:
Press the buttons on remote control and write down the values showing up on LCD.
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
Change the values here to the ones you saw on the screen.
Try it out
Code
1/* 08 Remote Control2
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 sensor8
9 pack, You can make the robot move around10
11 without even touching it!12
13 Circuit:14
15 * Arduino Robot16
17 * Connect the IRreceiver to D218
19 * Remote control from Robot sensor pack20
21 based on the IRremote library22
23 by Ken Shirriff24
25 http://arcfn.com26
27 created 1 May 201328
29 by X. Yang30
31 modified 12 May 201332
33 by D. Cuartielles34
35 This example is in the public domain36
37 */38
39// include the necessary libraries40#include <RobotIRremote.h>41#include <RobotIRremoteTools.h>42#include <ArduinoRobot.h>43#include <Wire.h>44
45// Define a few commands from your remote control46#define IR_CODE_FORWARD 28415440547#define IR_CODE_BACKWARDS 28411360548#define IR_CODE_TURN_LEFT 28412992549#define IR_CODE_TURN_RIGHT 28412788550#define IR_CODE_CONTINUE -151
52bool isActing = false; //If the robot is executing command from remote53long timer;54
55const long TIME_OUT = 150;56
57void setup() {58
59 // initialize the Robot, SD card, display, and speaker60
61 Serial.begin(9600);62
63 Robot.begin();64
65 Robot.beginTFT();66
67 Robot.beginSD();68
69 // print some text to the screen70
71 beginIRremote(); // Start the receiver72}73
74void loop() {75
76 // if there is an IR command, process it77
78 if (IRrecived()) {79
80 processResult();81
82 resumeIRremote(); // resume receiver83
84 }85
86 //If the robot does not receive any command, stop it87
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 forward105
106 break;107
108 case IR_CODE_BACKWARDS:109
110 changeAction(-1, -1); //Move the robot backwards111
112 break;113
114 case IR_CODE_TURN_LEFT:115
116 changeAction(-0.5, 0.5); //Turn the robot left117
118 break;119
120 case IR_CODE_TURN_RIGHT:121
122 changeAction(0.5, -0.5); //Turn the robot Right123
124 break;125
126 case IR_CODE_CONTINUE:127
128 timer = millis(); //Continue the last action, reset timer129
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}
Suggest changes
The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.
License
The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.