Previous                                                                    Tutorial                                                                   Tutorial

Contents

Authorized Online Retailers

Buy from US Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES

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.

top

Parts and Devices

Device

Picture
Qty.

Accessories

OSOYOO UNO R3(fully compatible with Arduino UNO R3) 1

M3*6 Plastic Screw  x 3

M3 Plastic Nut  x 4

M3*5+6 Plastic Pillar x 4

OSOYOO Model-X Motor Driver Module
1

M3*6 Plastic Screw  x 4

M3 Plastic Nut  x 4

M3*5+6 Plastic Pillar x 4

Sensor Shield V5.0 for Arduino UNO
1
IR receiver
1

M3*6 Plastic Screw  x 1

M3 Plastic Nut  x 1

M3*5+6 Plastic Pillar x 1

IR remote controller
1
Car Chassis
1
Motors with wires
2
Wheels
2

Universal Wheel

1
M3*10 Double Pass Copper Pillar x 4

M3*5 Screw x 8

18650 Battery Box
(Battery is not include,
Battery Height ≤ 67 mm)
1

M3*10 Screw  x 4

M3*10 Nut  x 4

Metal Motor Holders
2
DC Power Connector
1
Phillips Screwdriver
1
Slot Type Screwdriver
1
40pin 10cm Female to Female Cable 1
Cable Tie 20

top

top

Hardware Installation

1) Install the 2WD Robot Car Chassis

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.

2) Install the IR receiver module

Accessories:

Install the IR receiver at the front of the chassis with the screws and nuts:

3) Wire Connection

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:

Arduino lesson – IR Remote Receiver Module and Controller

Software Installation

Notice: Shut off your battery or Unplug your power adapter when upload sketch code to Arduino.

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.

top

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:

#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(); } } }

top

Testing

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:

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

top

Previous                                                                    Tutorial                                                                   Tutorial