Introduction                                      Next

Contents

Authorized Online Retailers

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

Objective

Welcome to the first lesson of OSOYOO 2WD Robot Car Starter Kit!

In this "Hello World" version lesson, we will install the most important framework of the robot car and program the car to do some simple movements. If you have passed the test movement of this lesson, it means Arduino, motor control module, motors, batteries, chassis and wire connections between these parts are all functioning well.

As your experiments in future lessons are all based on frame work of Lesson 1, it is very important to
test the installation and sample code in this Lesson properly.

top

Parts and Devices

Device

Picture
Qty.

Accessories

OSOYOO UNO R3(fully compatible with Arduino UNO R3)

1 M3*6 Plastic Screw  x 3M3 Plastic Nut  x 4

M3*5+6 Plastic Pillar x 4

OSOYOO Model-X Motor Driver Module
1 M3*6 Plastic Screw  x 4M3 Plastic Nut  x 4

M3*5+6 Plastic Pillar x 4

Sensor Shield V5.0 for Arduino UNO
1
Car Chassis
1
Motors with wires
2
Wheels
2

Universal Wheel

1 M3*10 Double Pass Copper Pillar x 4M3*5 Screw x 8
18650 Battery Box
(Battery is not include,
Battery Height ≤ 67 mm)
1 M3*10 Screw  x 4M3*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

Remove the protective film from the chassis.

Please pay attention:

The chassis has front side and back side, please pay attention to the front side as the picture shows:

1 Motors

Accessories:

  • Motor Holder Set x2

Install 2 motors on the chassis with the motor holders

2 Universal Wheel and Wheels

Accessories:

  • M3*10 Double Pass Copper Pillar x 4
  • M3*5 Screw x 8

Install the wheel on the chassis with M3*10 Double Pass Copper Pillars and M3*5 Screws(please install the Copper Pillar on the chassis first), then install the two wheels onto the motors.

3 Battery Box

Accessories:

  • M3*10 Screw  x 4
  • M3*10 Nut  x 4

Fixed the battery box on the surface of the chassis with the M3 screws and nuts , please note that battery is not include,
battery height should ≤ 67 mm.

4 OSOYOO Model-X Motor Driver Module

Accessories:

  • M3*6 Plastic Screw  x 4
  • M3 Plastic Nut  x 4
  • M3*5+6 Plastic Pillar x 4

Fixed the OSOYOO Model-X motor driver module on the surface of the chassis with the M3 screws and nuts

5 OSOYOO UNO

Accessories:

  • M3*6 Plastic Screw  x 3
  • M3 Plastic Nut  x 4
  • M3*5+6 Plastic Pillar x 4

Fixed the OSOYOO UNO board on the surface of the chassis with the M3 screws and nuts

6 Sensor Shield V5.0 for Arduino UNO

Plug the Sensor Shield V5.0 for Arduino UNO into OSOYOO UNO R3

7 Wire Connection

1)Connect the UNO board, battery box and OSOYOO Model-X according to the following connection diagram:

The wire should in the up side of the DC power connector as picture show:

More detail about OSOYOO Model-X please refer to this link:

http://osoyoo.com/2017/08/15/l298npro-motor-driver-module/

2) Connect the OSOYOO Model-X and Sensor Shield V5.0 for Arduino UNO as shown below:

Sensor Shield V5.0 for Arduino UNO OSOYOO Model-X
S5 ENA
S6 ENB
S7 IN1
S8 IN2
S9 IN3
S10 IN4

If you want to connect only with the OSOYOO UNO, you can follow this diagram:

OSOYOO UNO OSOYOO Model-X
D5 ENA
D6 ENB
D7 IN1
D8 IN2
D9 IN3
D10 IN4

3)Connect OSOYOO Model-X Motor Driver Module with 2 motors

The right motor connected to K1 or K2, the left motor connected to K3 or K4 as shown below:

Now hardware installation is almost done. Before we install 18650 batteries into the box, we need burn the sample code into Arduino first.

top

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:

Download lesson-1.zip , unzip it, you will see a folder called lesson-1

Step 3:

Connect UNO R3 board to PC with USB cable, open Arduino IDE, choose corresponding board/port for your project

Step 4:

Click file -> click Open -> choose code “lesson-1.ino”, load the code into Arduino, and then upload the sketch to the board.

top

Code Explanation

Below is the interface definition between OSOYOO Model-X and arduino

Notice: ENA and ENB should connect to PWM port,  D3, D5, D6, D9, D10, D11 of   Arduino have the PWM output function.

#define IN1  7   //K1、K2 motor direction
#define IN2  8     //K1、K2 motor direction
#define IN3  9    //K3、K4 motor direction
#define IN4  10   //K3、K4 motor direction
#define ENA  5    // Needs to be a PWM pin to be able to control motor speed ENA
#define ENB  6    // Needs to be a PWM pin to be able to control motor speed ENA

The below functions can control the car forward, backward, stop, turn right and turn left:

void go_ahead()  //motor rotate clockwise -->robot go ahead
{
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4,HIGH);
}
void go_back() //motor rotate counterclockwise -->robot go back
{
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4,LOW); 
}
void go_stop() //motor brake -->robot stop
{
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4,LOW); 
}
void turn_right(int t)  //left motor rotate clockwise and right motor rotate counterclockwise -->robot turn right
{
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  delay(t);
}
void turn_left(int t) //left motor rotate counterclockwise and right motor rotate clockwise -->robot turn left
{
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  delay(t);
}

The below functions can change motor speed, viriable lspeed can change the left motor speed, variable rspeed can control the right motor speed.

The valid range for this function parameter is 0-255

void set_motorspeed(int lspeed,int rspeed) //change motor speed
{
  analogWrite(ENA,lspeed);//lspeed:0-255
  analogWrite(ENB,rspeed);//rspeed:0-255   
}

top

Testing

Disconnect Arduino from PC, put 2 fully-charged 18650 battery into battery pox(check the box instruction and make sure polar direction is correct, otherwise it can destroy your device and cause fire hazard). Please install your battery as per following instruction:

Put the car on the ground, open the power switch in the battery box, the car should go forward 2 seconds, then go backward 2  seconds, then left turn for 2 seconds, then right turn for 2 seconds, then stop.

If the car does not move as per above mentioned result, you should check your wire connection, battery voltage(must over 7.2v).

top

                                                                                              Introduction                                                                  Next