Lesson 5 Bluetooth Car
Lesson 5 Bluetooth Car
com
Learning Parts:
Learn how to use the Bluetooth module and the Bluetooth APP
Preparations:
Smart Car (with battery)
USB cable
Bluetooth module
1
Http://www.elegoo.com
Ⅰ. Bluetooth module
The Bluetooth is a wireless technology standard for exchanging data between fixed and mobile devices
over short distances using short-wave UHF radio waves in the industrial, scientific, and medical radio
bands (2.400 to 2.485 GHz), and building personal area networks (PANs). There are also RF protocols
such as ZigBee and Wi-Fi.
In Smart Car Kit, we use the Bluetooth module model "HC-08", it can send serial data to other devices
via Bluetooth
HC-08 communicates with UNO through the RX/TX pin on the shield.
2
Http://www.elegoo.com
Before starting, connect the HC-08 Bluetooth module to the expansion board and turn on the power.
You can download the latest version of the "ELEGOO BLE TOOL" app on the App Store and Google Play.
3
Http://www.elegoo.com
4
Http://www.elegoo.com
Put your phone close to the car(within 10cm), the app will recognize the Smart Car and automatically connect with it
You can also open the Bluetooth device list by tapping the menu icon ” ” in the upper left corner
5
Http://www.elegoo.com
The Bluetooth status icon will turn blue when the connection is successful!
Great, now the Smart Car is already connected to the App, we can control it in two different ways.
The Rocker Control panel of the “Elegoo BLE Tool” App.
The main functions in the Rocker Control panel are divided into three parts:
Rocker controller: You can freely control the movement of the Smart Car, press the square button to stop the car
Obstacle mode: The car will turn into the obstacle avoidance mode, which is the same as the function in Lesson2.
Line tracking mode: The car will turn into the line tracking mode, which is the same as the function in Lesson 3
6
Http://www.elegoo.com
In the default settings, the DIY interface has only a few blank grids, we need to set their name, message
and color to creat buttons.
Long press the button you want to set, a “Button editor” option box will pop up as shown below. You need to fill
in the “Button Name”, “Message” and select the color of the button in this page
(All preset Messages are of the character type, so you only need to check the "Character" option.).
7
Http://www.elegoo.com
In this lesson, we used all the features of a smart car, so we need to put the code from all the previous
lessons in one single sketch, which we call SmartCar_Core.
A large part of the code has been explained in the previous Lessons, here we will explain the Bluetooth-
related part of the entire Sketch.
For example: When we push the rocker forward in the Rocker control panel of the APP, you phone will
send a letter 'f' to the Smart Car through the Bluetooth. After receiving the letter, UNO wakes up the
8
Http://www.elegoo.com
“getBTData()” function and passes the “getBTData()” function. The letter 'f' is converted to the
movement_mode : “FORWARD”.
Bluetooth command code:
void bluetooth_mode() {
if(func_mode == Bluetooth){
switch(mov_mode){
case FORWARD: forward(); break;
case BACK: back(); break;
case LEFT: left(); break;
case RIGHT: right(); break;
case STOP: stop(); break;
default: break;
}
}
}
After the previous function, the Bluetooth signal has been converted to a direct control command,
which will be received by “bluetooth_mode()”, it determine which motion functions will be executed.
For example: In the previous example, The letter 'f' is converted to “FORWARD”, the
bluetooth_mode()” will turn this command to the motion control function “forward()”.
//ect…
9
Http://www.elegoo.com
At last, those are Smart Car motion control functions that control the UNO's output, which will drive
the motor to work.
10