Previous                                                                                                      Tutorial

Contents

Objective

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

In this lesson, we will introduce how to control the car by the mobile APP through bluetooth.

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
Tracking sensor module
2
M3*5 Screw x4

M3*12 Double Pass Copper Pillar x2

Bluetooth module
1
Car Chassis
1
Motors with wires
 
2
Wheels
 
2

Universal Wheel

1 M3*12 Double Pass Copper Pillar x 4

M3*5 Screw x 8

18650 Battery Box
                  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
10pin 30cm Female to Female Cable   1
Cable Tie   20

top

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 and unzip lesson-4.zip , you will see a folder called lesson-4.

Step 3: Connect UNO R3 board to PC with USB cable, open Arduino IDE, choose corresponding board/port for your project,upload the sketch to the board.

Step 4: Arduino IDE: Click file -> click Open -> choose code “lesson-4.ino” in lesson-4 folder, load the code into arduino.

top

Hardware Installation

Step 1) Install the 2WD Robot Car Chassis

Install the robot car basic framework as per Lesson 1 and Lesson 3. If you have already completed the installation in Lesson 1 and Lesson 3, just keep it, no need to remove any module installed.

Step 2) Install the bluetooth module

Install the bluetooth module on the Sensor Shield V5.0 for Arduino UNO as follows:

Bluetooth Module Sensor Shield V5.0 for Arduino UNO
RXD TX
TXD RX
GND -
VCC +

top

Android APP Download

Step 1) Download Android APP

Download APP from: http://osoyoo.com/driver/car.apk

Or scan the following QR code with Android mobile phone to download the app:

Note: Android  APP Source code:http://osoyoo.com/driver/BTcar-master.zip (The APP is just compatible with Android OS)

Step 2) Install Android APP

top

Code Explanation:

The following code is used to receive the instructions sent by the APP, and then send the information back to the APP.

void do_Uart_Tick()
{

  char Uart_Date=0;
  if(Serial.available()) 
  {
    size_t len = Serial.available();
    uint8_t sbuf[len + 1];
    sbuf[len] = 0x00;
    Serial.readBytes(sbuf, len);
    //parseUartPackage((char*)sbuf);
    memcpy(buffUART + buffUARTIndex, sbuf, len);//ensure that the serial port can read the entire frame of data
    buffUARTIndex += len;
    preUARTTick = millis();
    if(buffUARTIndex >= MAX_PACKETSIZE - 1) 
    {
      buffUARTIndex = MAX_PACKETSIZE - 2;
      preUARTTick = preUARTTick - 200;
    }
  }
  if(buffUARTIndex > 0 && (millis() - preUARTTick >= 100))//APP send flag to modify the obstacle avoidance parameters
  { //data ready
    buffUART[buffUARTIndex] = 0x00;
    Uart_Date=buffUART[0];
    buffUARTIndex = 0;
  }
  switch (Uart_Date)    //serial control instructions
  {
    case '2':
            Drive_Status=MANUAL_DRIVE; Drive_Num=GO_ADVANCE;Serial.println("forward"); break;
    case '4':
            Drive_Status=MANUAL_DRIVE; Drive_Num=GO_LEFT; Serial.println("turn left");break;
    case '6':
            Drive_Status=MANUAL_DRIVE; Drive_Num=GO_RIGHT; Serial.println("turn right");break;
    case '8':
            Drive_Status=MANUAL_DRIVE; Drive_Num=GO_BACK; Serial.println("go back");break;
    case '5':
            Drive_Status=MANUAL_DRIVE; Drive_Num=STOP_STOP;Serial.println("stop");break;
    case '1':
          Drive_Status=AUTO_DRIVE_LF; Serial.println("line follow...");break;
    default:break;
  }
}

 top

Testing

Step 1)  Turn on the switch on the battery box

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.

Step 2) Turn on bluetooth of your Android phone

Please turn on bluetooth of your Android phone which you have installed APP and scan bluetooth (different bluetooth module will scan different bluetooth name), click connect and enter password “1234” or “0000” if no change:

Step 3) Open app>> select bluetooth mode>> then you can controller the robot car through bluetooth:

Working Mode

There are two working mode: manual control and tracking. Users can switch freely among two working mode.

1) Manual Cotrol Mode

In manual control mode, you can click buttons (∧) (∨) (<) (>) to control the Robot car to move forward and backward, turn left and turn right. Meanwhile, the APP can observe the car real time movement.

2) Tracking Mode

Click “tracking” button of App to switch the current mode to tracking mode. The Robot car will move forward along the black line in white background. Meanwhile, the APP can observe the car real time movement. Press “||” button to stop moving and click other button to change Robot car working mode.  To learn more about this mode, please review our lesson 3.

The rest of the buttons are for the reservation function, you can develop them by yourself.

top

Previous                                                                                                                  Tutorial