Remote Flying Fish Project Part 4: Bluetooth TestingFollow article
Before starting, please have a look at the mechanism of the communication of this DIY gadget.
Bluetooth is a communication medium between the mobile APP (controller) and Arduino board (motors). And this time, we need to make sure that the Bluetooth module, acts as a messenger and can serve this well.
Bluetooth is a wireless communication technology standard for sending or receiving data over short distances. It uses short wavelength Ultra High Frequency(UHF) radio waves in the Industrial Scientific Medical(ISM) band from 2.4 GHz to 2.485GHz. It can perform in both fixed and mobile devices, and building Personal Area Networks (PANs). Invented by telecom vendor Ericsson in 1994. It was originally conceived as a wireless alternative to RS-232 data cables.
Bluetooth Low Energy
Bluetooth Low Energy, BLE has dominated the electronic applications market due to the Internet of Things (IoT). Internet of things can be understood as an inter-networking of physical devices (i.e. Sensors). It is normally a bunch of small devices that require long-lasting performance. In this case, a small battery will be good enough. An example of IoT could be a device with a sensor that monitors the human heart rate via a smartphone app. So, BLE is an excellent technology to improve energy saving and increase the operating time of devices.
In this course, we will use BLE [HM-10] as well since it can help to reduce power consumption and it is a trend in reality.
Implement BLE via Arduino
After knowing the basic concepts of BLE, we can try to implement BLE with the Arduino board. We will first use the Serial Monitor inside the Arduino IDE to simulate the Android Application. You can open the Serial Monitor by clicking the button on the top right-hand side within the Arduino IDE. With the Serial Monitor, you can send and read different signals (i.e. number, alphabet).
Testing AT Command
Take the BLE 4.0 Bluetooth chip, the simplest way is to bridge the Bluetooth module with a USB TTL tool.
Connection of ports between TTL and Bluetooth:
'DTR' : none
'RXD' : 'TX' of Bluetooth
'TXD' : 'RX' of Bluetooth
'VCC' : '5V' of Bluetooth
'CTS' : none
'GND' : 'GND' of Bluetooth
You can use the Arduino IDE to test it. Firstly, open a new file, select the port that represents the USB TTL, and open the serial monitor.
Be careful: The pin position varies from one module to another, even though they all are named "hm-10"
An alternative method to test AT command
If you do not have a USB TTL, you can test the Bluetooth by the Arduino board. Firstly, let's see how the code works, it may also be useful in the future part when you design your own Arduino program.
Inside the loop(), using 'if condition' to check whether the serial monitor of Arduino or Bluetooth received any message. If they received any message, 'available()' will return '1', otherwise, it will return '0'. Then, use 'readString()' to save the received messages into a variable and print it to each other.
Also, be reminded that the return type of 'readString()' is 'String', if you want to return it by 'Character', change the type of ‘req’ to 'char' and use 'read()' instead of 'readString()'.
Then send AT commands via the Arduino Serial Monitor to do the setup. In the following example, it shows you the response after sending some AT commands.
The commands being sent in the demo in ascending order are:
Check module connectivity
Check module baud rate setting
Check module display name
Set module display name to ABCDE
There are a bunch of other AT commands at Ch.3.
Checking the connection between Arduino and Bluetooth
One of the easiest ways to check the connection is to type “AT” in your serial monitor, the Bluetooth should receive and return “OK” to Arduino. Make sure you selected a correct baud rate and 'Both NL & CR' on the bottom.
However, if you want to test sending other words or sentences instead of only AT command, you may download a mobile application called HM10 Bluetooth Serial Lite. After connecting it to your BLE, your phone can open a terminal as the monitor of Bluetooth. When you input some texts, the Arduino monitor should receive and print it out, and vice versa. [Please make sure you selected the right port for the TTL]
1. A similar interface will be shown when you open the mobile application.
2. Press the 'Connect' button on the left upper side. [This button will only be enabled when your mobile device turns on Bluetooth function.] Then your Bluetooth should be shown.
3. Press the 'Connect' button of the Bluetooth. When the 'Connect' button on the left upper side turns into 'Disconnect', the Bluetooth is successfully connected.
4. Type 'Hi' on your mobile device, you should receive the same message 'Hi' from the serial monitor.
5. Same as step 4, type 'Hi too' on the serial monitor, you should receive the same message 'Hi too' from your mobile device.
Now your Bluetooth is ready, let's move on to the next chapter, Motor Testing with Remote XY coming soon.
You can download the pdf version of this chapter in the Download section below.
Parts in this series
- Remote Flying Fish Project Part 1: Introduction
- Remote Flying Fish Project Part 2: DIY Series - Arduino Testing
- Remote Flying Fish Project Part 3: Motor Testing
- Remote Flying Fish Project Part 4: Bluetooth Testing
- Remote Flying Fish Project Part 5: Motor Testing with Remote XY
- Remote Flying Fish Project Part 6: PCB Design (preparatory)
- Remote Flying Fish Project Part 7: PCB Design (Schematic)
- Remote Flying Fish Project Part 8: PCB Design (PCB Layout)
- Remote Flying Fish Project Part 9: Soldering and Arduino Programming
- Remote Flying Fish Project Part 10: Flutter Introduction
- Remote Flying Fish Project Part 11: Flutter Installation on MacOS
- Remote Flying Fish Project Part 12: Flutter Installation on Windows