Robot Tank Car Kit Lesson 7:Control Robot Tank Car through Wifi and Bluetooth

Byamber

Robot Tank Car Kit Lesson 7:Control Robot Tank Car through Wifi and Bluetooth


Robot Tank Car Kit Lesson 7:Control Robot Tank Car through Wifi and Bluetooth

I. Objective:

In this lesson, we learn how to control the Robot car mobile APP through WiFi and Bluetooth. , we just use the ESP8266 Wifi board as expansion board and control the tank car via IR receiver in previous lessons. In this lesson, we will learn how to use the phone to connect the hot spot from esp8266 board and control the car movement via phone app. At the same time, you also can put the bluetooth into the esp8266 board and control the car movement via phone bluetooth.

II. How it Work

There is a hot spot called DoitWIFI_Config from ESP8266 board in working time and you could connect the hot spot via phone wifi without password. When turn the switch of ESP8266 board  to “ON”, the message from the arduino and esp8266 can be exchanged by serial ports.The control command can be send to ESP8266 via phone app and then send to arduino via serial ports between arduino and ESP8266 board.

When turn the switch of ESP8266 board to “1” and “2” position to disconnect the serial ports between arduino and ESP8266 board. If you put the bluetooth module on esp8266 board and connect it via phone bluetooth, the message from the arduino and esp8266 can be exchanged by serial ports via bluetooth module.

ESP8266-pin

Find more about the ESP8266 Wifi shiled board, please click here.

ESP8266 UART WIFI Shield use guide

III. 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 7 sample code from http://www.kookye.com/download/car/tank_robot_lesson7.zip, unzip the download zip file tank_robot_lesson7.zip, you will see a folder called tank_robot_lesson7.

Step 3: Connect UNO R3 board to PC with USB cable, Open Arduino IDE -> click file -> click Open -> choose code “tank_robot_lesson7.ino” in tank_robot_lesson7 folder, load the code into arduino.

open

Step 4: Choose corresponding board and port for your project,upload the sketch to the board.

port

Step 5: Download the APP and install it on you phone:  (http://kookye.com/download/car/car.apk)

Note: This app can just support Android and we offer the app source code( http://kookye.com/download/car/BTcar-master.zip). You could revise and personalize the code as per your needs.

IV. Understand the Code:

This program is used to receive the control command from phone app.

//WiFi / Bluetooth through the serial control
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;
    if(buffUART[0]=='C') 
    {
      Serial.println(buffUART);
      Serial.println("You have modified the parameters!");//indicates that the obstacle avoidance distance parameter has been modified
      sscanf(buffUART,"CMD%d,%d,%d",&distancelimit,&sidedistancelimit,&turntime);
    }
    else  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;buzz_off();Serial.println("stop");break;
    case '3':
            Drive_Status=AUTO_DRIVE_UO; Serial.println("avoid obstacles...");break;
    case '1':
          Drive_Status=AUTO_DRIVE_LF; Serial.println("line follow...");break;
    default:break;
  }
}

V. Hardware Installation:

Step 1: Install ESP8266 Expansion Board on UNO R3 board.
lesson2-HW-1
Step 2: Put the bluetooth module into ESP8266 wifi Board as the following picture.

bluetooth-esp8266
Step 3: Put two 12865 batteries into battery box and turn the swith of box to “ON”.
(If you have finished the above steps on lesson one, please skip these step)
Step 4: Open phone app and wifi, find the hot spot called”DoitWIFI_Config” and connect it.

step5: Open app>> select WiFi mode>> then you can controller the robot car through wifi

step 6: If you want to control the robot car through Bluetooth, 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 (You can change wifi or bluetooth settings in Android phone to switch to control car through wifi or bluetooth):

Step7:  Open app>> select bluetooth mode>> then you can controller the robot car through bluetooth:

There are three working mode: manual control, obstacle avoidance and tracking. Users can switch freely among three working mode.
1) In manual control mode, you can click buttons (^) (V) (<) (>) to control the Robot car to move forward and backward, turn right and left. Meanwhile, the APP can observe the car real time movement.

2) 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 4.

3) Click “Obstacle” button to switch the current mode to obstacle avoidance mode. The Robot car can be driven forward continuously and stopped and steered away once any obstacle in its way. Press “||” button to stop moving and then click other button to change Robot car working mode. To learn more about this mode, please review our lesson 5.

About the Author

amber administrator

You must be logged in to post a comment