Buy from US | Buy from UK | Buy from DE | Buy from IT | Buy from FR | Buy from ES |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
In this lesson, we will use 2WD Robot Car Starter Kit to make a simple remote controlled car. Once the car installation is completed, we will use a Infrared Remote to control the car movements including go forward, go backward, stop, turn left and turn right.
Install the robot car basic framework as per Lesson 1. If you have already completed the installation in Lesson 1, just keep it, no need to remove any module installed.
Install the IR receiver at the front of the chassis with the screws and nuts:
Using the female to female Dupont line to connect IR receiver with Sensor Shield V5.0 for Arduino UNO:
IR receiver |
Sensor Shield V5.0 for Arduino UNO |
S |
S4 |
+ |
5V |
– |
GND |
More information about this module please refer to:
Step 1: Install latest Arduino IDE (If you have Arduino IDE version after 1.1.16, please skip this step)
Download Arduino IDE from https://www.arduino.cc/en/Main/Software?setlang=en , then install the software.
Step 2: Open Arduino IDE, install IRremote library into Arduino IDE (If you have already installed IRremote library, please skip this step)
Download IRremote.zip library, then import the library into Arduino IDE(Open Arduino IDE-> click Sketch->Include Library->Add .Zip Library)
Step 3: Download lesson-2.zip and unzip it, you will see a folder called lesson2.
Step 4: Connect UNO R3 board to PC with USB cable, open Arduino IDE, choose corresponding board and port for your project
Step 5: Arduino IDE: Click file -> click Open -> choose code “lesson2.ino” in lesson-2 folder, load the code into arduino, upload the sketch to the board.
The following 4 lines of code expresses the IR code of ∧∨ in the IR controller, each IR code of the button can get from the IR sample code:
#define IR_ADVANCE 0x00FF18E7 //code from IR controller "∧" button #define IR_BACK 0x00FF4AB5 //code from IR controller "∨" button #define IR_RIGHT 0x00FF5AA5 //code from IR controller ">" button #define IR_LEFT 0x00FF10EF //code from IR controller "<" button
Instantiate an IRrecv object for decoding the infrared signal, store the decoded result in IRresults
IRrecv IR(IRPIN); // IRrecv object IR get code from IR remoter decode_results IRresults;
Decodes the infrared signal and compares the received infrared signal with a predefined value, if it is equal, assigns the corresponding value to Drive_Num
void do_IR_Tick() { if(IR.decode(&IRresults)) { if(IRresults.value==IR_ADVANCE) { Drive_Num=GO_ADVANCE; } else if(IRresults.value==IR_RIGHT) { Drive_Num=GO_RIGHT; } else if(IRresults.value==IR_LEFT) { Drive_Num=GO_LEFT; } else if(IRresults.value==IR_BACK) { Drive_Num=GO_BACK; } IRresults.value = 0; IR.resume(); } }
This piece of code is the core of the infrared control code, press the corresponding key, the car perform the corresponding action, if the pressed key is not defined in the program, the car will not respond.
void do_Drive_Tick() { switch (Drive_Num) { case GO_ADVANCE: go_ahead(20);JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;//if GO_ADVANCE code is detected, then go advance case GO_LEFT: turn_left(1);JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;//if GO_LEFT code is detected, then turn left case GO_RIGHT: turn_right(1);JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;//if GO_RIGHT code is detected, then turn right case GO_BACK: go_back(20);JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;//if GO_BACK code is detected, then backward default:break; } Drive_Num=DEF; //keep current moving mode for 200 millis seconds if(millis()-JogTime>=200) { JogTime=millis(); if(JogFlag == true) { stopFlag = false; if(JogTimeCnt <= 0) { JogFlag = false; stopFlag = true; } JogTimeCnt--; } if(stopFlag == true) { JogTimeCnt=0; go_stop(); } } }
Disconnect OSOYOO UNO R3 board from PC, put 2 fully-charged 18650 battery into battery box (check the box instruction and make sure polar direction is correct). Open the power switch in the battery box.
Press IR controller keys to control the car movements:
∧: Forward
∨: Backward
<: Turn left
>: Turn right
If the car can’t move, please check the following:
DownLoad Url osoyoo.com
You must be logged in to post a comment.
Can sketches be combined? Can the IR control be used to activate the Robot movement from lesson 1, for example? Or, can the IR remote be used at the same time as the line follow?
Can an obstacle avoidance module be added to the 2WD Robot Kit?
Thanks
the code on the cd does not work …. IRremote.H: no such file or directory
please help!
please read the software installation STEP 2, https://osoyoo.com/2017/09/21/2wd-robot-car-infrared-remote/#4
You need install the IRremote library first.
I’m having difficulty with this lesson. I have the library imported and code loaded with no errors. When I try the IR remote, I see the sensor blinking showing it is receiving the signal, but the car only sometimes goes and only for a split second. The batteries are new and fully charged and the IR Remote is close and unhindered. The code in lesson one worked perfectly, so that eliminates the wiring/boards with the exception of the IR receiver.
Any thoughts? Thank you!
hi, TheMuffinMan,
It seems that your IR receiver did not send the data to Arduino. I believe the wire from IR receiver S pin to extension S4 pin is loose or broken. Please change a new wire and try again. if it does not work, then let me know I will tell you how to make further test.
thanks
admin
Hello, and thanks for the quick response.
I went ahead and replaced all the wiring, assuring that they were all were snug.
The issue still persists though. Any suggestions would be much appreciated.
Thank you,
TheMuffinMan
Ok. Please keep all your current wire connection (make sure IR receiver S pin is connected to D4) and then download an IR test sketch from https://osoyoo.com/driver/IRrecvDemo.ino
Above sketch will tell you of the IR code of each key on a remote controller. After upload above sketch into Arduino, Open the serial monitor, then press ∧ V > < (the direction arrow keys) in the remote, it will show result in following sequence.
00FF18E7
00FF4AB5
00FF5AA5
00FF10EF
They are the IR codes of ∧ V > < four keys.
Please let me know :
1)Does the serial monitor show any message ?
2)if 1) answer is yes, then what is the IR code of your IR remote ∧ V > < four keys.
I will tell you solution after I got your answer.
Thank you for getting back with me. I did output in the serial monitor. Here’s the code output:
∧ = 3D9AE3F7
V = 1BC0157B
> = 449E79F
< = 8C22657B
now I understand what is your problem. Your remote sends different IR code to our receiver. Ok, that is easy to fix.
Please open your lesson2.ino file, you can see line 10,11,12,13 as follows:
#define IR_ADVANCE 0x00FF18E7 //code from IR controller “▲” button
#define IR_BACK 0x00FF4AB5 //code from IR controller “▼” button
#define IR_RIGHT 0x00FF5AA5 //code from IR controller “>” button
#define IR_LEFT 0x00FF10EF //code from IR controller “<" button
Change above code to follows which match your IR code :
#define IR_ADVANCE 0x3D9AE3F7 //code from IR controller “▲” button
#define IR_BACK 0x1BC0157B //code from IR controller “▼” button
#define IR_RIGHT 0x449E79F //code from IR controller “>” button
#define IR_LEFT 0x8C22657B //code from IR controller “<" button
Also please double check the key > , this key code should be 8 digits , but you only give me 7 digits. I double you might have typed wrong code. If I am correct, please put change line 12 with correct code.
Let me know if above code works.