Contents

Objective

In 2WD Robot Car Starter Kit Lesson 2, we introduced how to control the car by Infrared Remote. In this lesson, we will introduce how to control the car by the mobile APP through bluetooth.

 Parts and Devices

Device Picture Qty. Accessories
Bluetooth module 1
2WD Robot Car Chasis (Installation please refer to Lesson 1, Lesson 2 and Lesson 3)   1

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.

Hardware Installation

Step 1) Install the 2WD Robot Car Chasis

Install the smart car basic framework as per 2WD Robot Car Starter Kit Lesson 1. If you have already completed installation in Lesson 1,  Lesson 2 and Lesson 3, just keep it, no need to remove any module installed.

Picture

Step 2) Install the bluetooth module

Install the bluetooth module on the Expansion Board  V5.0 as follows:

Bluetooth Module Arduino Sensor Shield v5.0
RXD TX
TXD RX
GND
VCC +

Picture

OSOYOO Model-X Arduino Sensor Shield v5.0
ENA S5
IN1 S7
IN2 S8
IN3 S9
IN4 S10
ENB S6
IR Receiver Arduino Sensor Shield v5.0
S S4
+ 5V
GND
The Right Tracking Sensor
Tracking Sensor Arduino Sensor Shield v5.0
VCC 5V
GND GND
DO S3
AO Not Connected
The Left  Tracking Sensor
Tracking Sensor Arduino Sensor Shield v5.0
VCC 5V
GND GND
DO S2
AO Not Connected

Download Android APP

Step 1) Turn on switch in the battery box. If the car can make movement as described in 2WD Robot Car Starter Kit Lesson 1 (go forward 2 seconds, then go backward 2  seconds, then left turn for 2 seconds, then right turn for 2 seconds, then stop), it means wire connection with Expansion Board V5.0 and Arduino UNO board are all correct. Otherwise please check each Digital Pin connection in Expansion Board V5.0 and Arduino UNO.

Step 2) Download and install APP from: http://osoyoo.com/driver/car.apk.

Android  APP Source codehttp://osoyoo.com/driver/BTcar-master.zip (Please note: the APP is just compatible with Android OS)

The car also can control by bluetooth, you can add a bluetooth module to the ESP8266 Expansion Board to control the car by APP.

Code Explanation:

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

 
 
  1. void do_Uart_Tick()
  2. {
  3. char Uart_Date=0;
  4. if(Serial.available())
  5. {
  6. size_t len = Serial.available();
  7. uint8_t sbuf[len + 1];
  8. sbuf[len] = 0x00;
  9. Serial.readBytes(sbuf, len);
  10. //parseUartPackage((char*)sbuf);
  11. memcpy(buffUART + buffUARTIndex, sbuf, len);//ensure that the serial port can read the entire frame of data
  12. buffUARTIndex += len;
  13. preUARTTick = millis();
  14. if(buffUARTIndex >= MAX_PACKETSIZE - 1)
  15. {
  16. buffUARTIndex = MAX_PACKETSIZE - 2;
  17. preUARTTick = preUARTTick - 200;
  18. }
  19. }
  20. if(buffUARTIndex > 0 && (millis() - preUARTTick >= 100))//APP send flag to modify the obstacle avoidance parameters
  21. { //data ready
  22. buffUART[buffUARTIndex] = 0x00;
  23. Uart_Date=buffUART[0];
  24. buffUARTIndex = 0;
  25. }
  26. switch (Uart_Date) //serial control instructions
  27. {
  28. case '2':
  29. Drive_Status=MANUAL_DRIVE; Drive_Num=GO_ADVANCE;Serial.println("forward"); break;
  30. case '4':
  31. Drive_Status=MANUAL_DRIVE; Drive_Num=GO_LEFT; Serial.println("turn left");break;
  32. case '6':
  33. Drive_Status=MANUAL_DRIVE; Drive_Num=GO_RIGHT; Serial.println("turn right");break;
  34. case '8':
  35. Drive_Status=MANUAL_DRIVE; Drive_Num=GO_BACK; Serial.println("go back");break;
  36. case '5':
  37. Drive_Status=MANUAL_DRIVE; Drive_Num=STOP_STOP;Serial.println("stop");break;
  38. case '1':
  39. Drive_Status=AUTO_DRIVE_LF; Serial.println("line follow...");break;
  40. default:break;
  41. }
  42. }

Testing

Step 1)  Turn on the switch in the battery box,  connect the wifi “DoitWIFI_Config”(no password needed)

Step 2) Open app>> select WiFi mode>> then you can controller the robot car through wifi

There are two working mode: manual control and tracking. Users can switch freely among two 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 3.

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

Leave a Reply

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