Skip to main content

Remote Flying Fish Project Part 4: Bluetooth Testing

Before starting, please have a look at the mechanism of the communication of this DIY gadget.

image54_f4b13620ac8c24c3a1cb7a7749b101398205190c.png

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. bluetooth2_e81902ab5457eab6f180244856b5e2407ed62a98.jpg

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).%25E6%2593%25B7%25E5%258F%25968_df130c165fe76acc7ab81b455dcb0a8c7c818957.png

Testing AT Command

Take the BLE 4.0 Bluetooth chip, the simplest way is to bridge the Bluetooth module with a USB TTL tool.

image112_9128b2e83c5d401d3bebf42beece3b436787333d.png

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.

image121_a4945a20309a7bf529e225ee708f9753a6bde108.png

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()'.

AT commands

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:

Command

Function

Output

AT

AT+BAUD?

AT+NAME?

AT+NAME[ABCDE]

Check module connectivity

Check module baud rate setting

Check module display name

Set module display name to ABCDE

OK

OK

OK

OK

Check out other AT commands here.

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.

Capture46_325e3a9a01c1cde7c658ae5fe6081e30c87c2b35.png

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.

PNG_image_b0befa8fbb14e7ba56d2d9077d035a83f1d6e616.png

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.

File_001%281%29_9611a1b0a7b0e638daaa75e643af56aeb0497aa0.png

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.

File_001_73ee32e266944a31500fc5838e1832e6371000a8.png

4. Type 'Hi' on your mobile device, you should receive the same message 'Hi' from the serial monitor.

File_001%282%29_af322bf8a5a12137d9b05971e0b43cf64b9650a9.pngCapture110_20d5e4201d1e90dc0ab47bf01c2c94a06b122fe9.png

5. Same as step 4, type 'Hi too' on the serial monitor, you should receive the same message 'Hi too' from your mobile device.

Capture215_ae06ec54ca3362d38c724719fbc4838bcec05146.pngFile_001%283%29_fa9e56da82dc28508d1a93c49fd1087b1ece502d.png

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

lokit has not written a bio yet…
DesignSpark Electrical Logolinkedin