Shopify Amazon
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.
More information about this module please refer to:
Step 1: Install latest IDE (If you have IDE version after 1.1.16, please skip this step)
Download IDE from https://www.arduino.cc/en/Main/Software?setlang=en, then install the software.
Step 2: Install IRremote library into IDE (If you have already installed IRremote library, please skip this step)
Download IRremote library from https://downloads.arduino.cc/libraries/github.com/z3t0/IRremote-4.3.1.zip, then import the library into IDE(Open IDE-> click Sketch→Include Library→Add .Zip Library)
In the pop-up window, go to your downloads’ folder, select the IRremote.zip file you downloaded just now.
NOTE!!
Step 3: Download https://osoyoo.com/driver/2wd/lesson2.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 lesson2 folder, load the code into Arduino, upload the sketch to the board.
The following 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:
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_Advance();JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;//if GO_ADVANCE code is detected, then go advance case GO_LEFT: go_Left();JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;//if GO_LEFT code is detected, then turn left case GO_RIGHT: go_Right();JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;//if GO_RIGHT code is detected, then turn right case GO_BACK: go_Back();JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;//if GO_BACK code is detected, then backward case STOP_STOP: stop_Stop();JogTime = 0;break;//stop 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; stop_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:
If above 3 points are all checked and the IR control still doesn’t work. The reason might be the IR remote sends a different button code which does not match our sample code. In order to solve this problem. Please take following steps:
Step A) Get the IR code of each button in your IR remote from following link.
https://osoyoo.com/driver/2wd/IR_print_commands_v4.zip
unzip the file upload above sketch into your board and open the serial monitor in your upper-right corner.
Press the ◄ ► ▲ ▼ “OK” button in your remote, you will see their IR code as following picture:
Write down the IR code of your control buttons ◄ ► ▲ ▼ “OK” button,
No. | Picture | Device | Qty. | Data sheet | Buy in Link |
1 | OSOYOO basic board | 1 | click here | Click here to buy | |
2 | OSOYOO UART Wi-Fi shield V1.3 | 1 | click here | Click here to buy | |
3 | OSOYOO model X motor driver module | 1 | click here | Click here to buy | |
4 | IR receiver | 1 | click here | Click here to buy | |
5 | IR remote controller | 1 | click here | Click here to buy | |
6 | Tracking sensor module | 2 | click here | Click here to buy | |
7 | HC module | 1 | click here | Click here to buy | |
8 | Gear motor | 2 | Click here to buy | ||
9 | Metal Motor Holders with screws | 2 | Click here to buy | ||
10 | Wheel | 2 | Click here to buy | ||
11 | Universal Wheel | 1 | |||
12 | 6pin male to 6pin female jumper wire | 1 | Click here to buy | ||
13 | OSOYOO 2pin PnP cable 20 cm | 1 | Click here to buy | ||
14 | 20Pin jumper wire Male to female 15 cm | 1 | Click here to buy | ||
15 | Philips screwdriver | 1 | Click here to buy | ||
16 | Hex Screwdriver | 1 | Click here to buy | ||
17 | 18650 battery box | 1 | Click here to buy | ||
18 | Battery charger for 18650 battery | 1 | Click here to buy | ||
19 | 1Pair 18650 batteries | 1 | Click here to buy | ||
20 | M3*5 Hex Screws | 10 | |||
21 | M3*10 screw | 4 | |||
22 | M3 nut | 4 | |||
23 | Copper pillar | 4 | |||
24 | Screw for wheel | 2 | |||
25 | M3 plastic screw | 15 | |||
26 | M3 plastic pillar | 15 | |||
27 | M3 plastic nut | 15 |
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.
I just assembled this kit and I’m trying lesson 2 (with the IR). The code itself seems to want to use pin 12 for the IR receiver and the code to simply print the codes received wants to use pin 2
I think these are for the line following sensor – no ? the IR is connected to Pin 10
Nothing works – not the original code or if I change your debugging code (to print just the codes) to use pin 10
any suggestions ?
hi, mattganis,
You are right, the code has some error, you need to change the receiver port to 10 instead of 12 in our code line 12.
If it still not working , then please read following link:
https://osoyoo.com/2017/09/21/2wd-robot-car-infrared-remote/#tbst
It will ask you to run a testing program irdemo.ino , open your Serial monitor and run irdemo.ino file, press ^ key in your IR controller, let us know if you can see any response, if not , please email to [email protected] and we will give you solution.