Contents

Objective

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.

Parts and Devices

Device Picture Qty. Accessories
IR receiver(VS1838) 1 M3*6 Plastic Screw  x 1

M3 Plastic Nut  x 1

M3*5+6 Plastic Pillar x 1

IR remote controller   1  
2WD Robot Car Chasis

(Installation please refer to Lesson 1)

  1

Hardware Installation

Using the female to female Dupont line to connect Arduino UNO Sensor Expansion Board  V5.0 with IR receiver:

Expansion Board  V5.0

IR receiver(VS1838)

S

D4
+

5V

GND

Picture

Install the IR receiver on the chassis with M3*10 screws and nuts:

Picture

Software Installation

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.

Code Explanation:

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:

 
 
  1. #define IR_ADVANCE       0x00FF18E7       //code from IR controller "▲" button
  2. #define IR_BACK          0x00FF4AB5       //code from IR controller "▼" button
  3. #define IR_RIGHT         0x00FF5AA5       //code from IR controller ">" button
  4. #define IR_LEFT          0x00FF10EF       //code from IR controller "

Instantiate an IRrecv object for decoding the infrared signal, store the decoded result in IRresults

 
 
  1. IRrecv IR(IRPIN); // IRrecv object IR get code from IR remoter
  2. 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

 
 
  1. void do_IR_Tick()
  2. {
  3. if(IR.decode(&IRresults))
  4. {
  5. if(IRresults.value==IR_ADVANCE)
  6. {
  7. Drive_Num=GO_ADVANCE;
  8. }
  9. else if(IRresults.value==IR_RIGHT)
  10. {
  11. Drive_Num=GO_RIGHT;
  12. }
  13. else if(IRresults.value==IR_LEFT)
  14. {
  15. Drive_Num=GO_LEFT;
  16. }
  17. else if(IRresults.value==IR_BACK)
  18. {
  19. Drive_Num=GO_BACK;
  20. }
  21. IRresults.value = 0;
  22. IR.resume();
  23. }
  24. }

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.

 
 
  1. void do_Drive_Tick()
  2. {
  3. switch (Drive_Num)
  4. {
  5. case GO_ADVANCE:
  6. go_ahead(20);JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;//if GO_ADVANCE code is detected, then go advance
  7. case GO_LEFT:
  8. turn_left(1);JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;//if GO_LEFT code is detected, then turn left
  9. case GO_RIGHT:
  10. turn_right(1);JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;//if GO_RIGHT code is detected, then turn right
  11. case GO_BACK:
  12. go_back(20);JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;//if GO_BACK code is detected, then backward
  13. default:break;
  14. }
  15. Drive_Num=DEF;
  16. //keep current moving mode for 200 millis seconds
  17. if(millis()-JogTime>=200)
  18. {
  19. JogTime=millis();
  20. if(JogFlag == true)
  21. {
  22. stopFlag = false;
  23. if(JogTimeCnt
  24. {
  25. JogFlag = false; stopFlag = true;
  26. }
  27. JogTimeCnt--;
  28. }
  29. if(stopFlag == true)
  30. {
  31. JogTimeCnt=0;
  32. go_stop();
  33. }
  34. }
  35. }

Testing

Disconnect Arduino 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:

  1. If the battery can work;
  2. If the IR controller is too far away from the receiver;
  3. If the connection is right

Leave a Reply

WordPress spam blocked by CleanTalk.
Bombax Theme designed by itx
"