Arduino – AT 09 BLE module

I always wanted to connect something over Bluetooth if found this module the AT 09 BLE module. But first I need to know how it works.

AT 09 BLE Module

The AT-09 is a module that contains a BLE chip (a CC2540/CC2541). This module allows to perform serial communication with the BLE chip thanks to an Rx and a Tx pin. This module is also very similar to the HM-10 module and is also compatible with it.

Connecting the AT 09 BLE Module

Let’s start by connecting the Arduino with the AT 09 BLE module in order to turn it on. To achieve that, we only need these two pinsAT-09 GND <-> Arduino GND PinAT-09 VCC <-> Arduino 5V Pin or 3.3V Pin

Turn on you Arduino, you should see the AT 09 BLE module led blink. If you have a BLE smartphone, you can also open a BLE scanning app to scan for the AT 09 BLE module. In my case, I used LightBlue | Explorer on my iPhone. The module was detected as device named ?. You can have a different result.

If you do not happen to detect the module in this step, it may be simply a problem with the configuration of the module. So keep reading to learn how to configure it.

SaveSave

Sending our first command from the Arduino to the module

To allow the Arduino to communicate with the AT-09 BLE module, we use the serial interface (the TXD and RXD pins). Arduino allows to turn any pair of digital pins into a serial interface using the SoftwareSerial library included in the Arduino IDE. After establishing the serial connection, We can start transmitting data to the AT-09 BLE module. The module understands certain data as commands. These commands are the HM-10 AT commands. In order to send command to the module we need to:

Connect the TXD and RXD pins of the module to any pair of Arduino pins other than 1 and 2.

After running this loop, you should see an “OK” appear on the serial monitor.

Congratulations, we sent our first command to the AT-09 module through the Arduino. Next we will configure the module as a BLE peripheral using commands.

Configuring the AT-09 as a BLE peripheral

configuring the AT-09 BLE module is done by so called AT commands. The goal of this section is to call the commands that allows you to do the following.

Set the module as peripheral

Set the service UUID

Set the characteristic UUID

Set a nice name to the peripheral

An important detail to note here is that the AT-09 BLE module allows only one service that contains only one characteristic when it is configured as a peripheral.
The HM-10 datasheet contains a section that lists AT commands. After some research, we find the commands that we are going to use.

Set the module as peripheral if not set yet: AT+ROLE0 where 0 is for peripheral and 1 is for central.

Set the service UUID: AT+UUIDuuid where uuid is the UUID of the service. It ranges from 0x0001~0xFFFE and defaults to 0xFFE0

Set the characteristic UUID: AT+CHARuuid where uuid is the UUID of the characteristic. It ranges from 0x0001~0xFFFE and defaults to 0xFFE1

Set a nice name to the peripheral: AT+NAMEnew_name where new_name is the new name that we want to set

Suppose we want this configuration

Role: peripheral

Name: LightBlue

Service UUID: 0xFFE0

Characteristic UUID: 0xFFE1

By consolidating all this information, we conclude to these commands.

AT+ROLE0

AT+NAMELightBlue

AT+UUID0xFFE0

AT+CHAR0xFFE1

On the Arduino sketch, we will send these commands during thesetup() step since we will do it once when the board it boots up. It will take the command as a parameter, sends it, and displays its result. Note that I force a delay between sending a command and reading its reply. I did it because I noted in my tests that there is a lag between these two steps. So, better keep the delay. Here is the code.

When you run the sketch, you should see the following output on the serial monitor.

On the iOS side, the name of peripheral gets updated. I used LightBlue on iOS to perform the verification.

We can also verify the UUIDs of the services and characteristics.

We are making good progress. The next step consists in reading and writing data on the characteristic using the Arduino. The next section first focuses on reading the data available in that characteristic.

Reading the data on the AT-09’s characteristic

After configuring the AT-09 BLE module as a peripheral, our Arduino can easily read the data sent to its characteristic by reading TXD pin. Any connected central can inject data into the characteristic. Please note that the only available characteristic can store up to 20 bytes of random data.

In this code we see there is a function that puts the characteristic data into a buffer and then writes it to the serial monitor. The loop() function does simply a call to the readSerial() function.

This sketch will write these values one by one: 1, 2, 3, 4, 5, etc. After each write, the AT-09 BLE module will update the characteristic and also send a notification. On our central app, we will receive notifications following this order: 1, 2, 3, 4, 5, etc.

and select Listen for notifications. Now you will see the messages that arrives from your AT-09 BLE module.

Application

Time to build a realise example a small cool temperature / Humidity application. sending temperature and humidity to the iPhone through BLE. Here we will need a temperature / humidity sensor. I am using the DHT22 sensor here.

We will connect the sensor to the Arduino following this scheme.

After establishing the connections, we will need to read the temperature from one of the free pin’s. The Used library that allows to read the temperature in Celsius or Fahrenheit. we just need to send the string to the serial port of the AT-09 BLE module.

Donate

Since October 2015, StudioPieters® has been writing this blog. Help accelerate its development with a small contribution! StudioPieters® is open source, and 100% free . Please consider donating to StudioPieters® before starting the fun of building and learning. StudioPieters® is a non-profit organisation devoted to making creative use of electronics accessible to everyone.