Bluetooth Low Energy Arduino Module

Send Data To The Arduino Nano Microcontroller

use NRF as a BLE Module | Arduino NRF24L01 Bluetooth Low Energy Tutorial

To send the data we will the following command format:

This may look like an overkill for a simple led switch, but it is a good structure to send different commands. We will use it in the next tutorials to control the engine and the steering of the BlueCArd RC car.

First we have to modify the Arduino sketch.

Create a new file called controller.ino. In this file we will put all the parse and controller logic.

SWITCH_LED is the command for the LED control.

We connected the LED to the pin D9. In the initController we set the D9 as an OUTPUT.

The executeCommand function becomes a int array with the command structure we described above.

The switchLight function sets the LED to the given value. With this we could also change the LED intensity.

The initController function should be executed only once on start. We can call this function from the setup function.

What is left is to read the command in the bluetooth.ino file.

First add this constant to the bluetooth file:

We also need an int array to read the command into and a variable for the current position in this array:

Add also these methods at the end of the file:

This code reads the data from the BLE module and checks if it is a command . If so, it reads the whole command and when finish sends it to the controller.

Now in the loop function remove updateSerial and add readCommand instead.

With this the Arduino part is finished.

Adafruit Bluefruit Le Connect App

To interact with your board from your phone or tablet, youll use the Adafruit Bluefruit LE Connect App. Download or Simply Install the App from Apple App Store or

This App only works if you have code running on nRF52840 Development Board. The device will only advertise when the code is running. The means the device will transmit/show the device name on Android/Apple Phone if the device is running.

So now lets run code on the board and check the working.

Reading The Data On The At

After configuring the AT-09 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. The communication looks like this:

Central_BLE chip BLE chip_AT-09_ TXD Pin 2_Arduino

Please note that the only available characteristic can store up to 20 bytes of random data.

Here 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.

I use LightBlue on iOS to write data to the characteristic. Note that the AT-09 led will remain red when a central is connected. The video below illustrates what we have done.

he full sketch is available here:

Next, we will see how to write data to the characteristic on the Arduino side and how to receive on the central side.

Don’t Miss: What Tvs Have Bluetooth Capability

Nordic Nrf52840 Development Board

There are various manufacturer of Nordic nRF52840 Development Board. The board are usually programmed using Segger Embedded Studio. But some of the boards do have support for CircuitPython & Arduino IDE. In this guide we will program nRF52840 Development Board using Arduino IDE.

Now we need to select a board to get started. There are multiple boards available in the market from different vendors as shown in the image below.

Most of the boards shown in the image are quite expensive and range from 30$ price to 70$. So I selected the best board which can be purchased at a reasonable price. The criteria for selection is that the board should have all the best features of nRF52840 Chip. The board should support CircuitPython as well as Arduino IDE. The board should also have support for various Bootloaders.

So I selected MakePython nRF52840 board from Makerfabs whcih costs only 20$. The board has an additional 1.3 I2C OLED Display which is an extra advantage for begineers like us. The MakePython nRF52840 Board supports both Arduino & Python Code.

You can purchase this board from this link: MakePython nRF52840 Board

Check If The Android Device Is Ready To Use Bluetooth

Arduino :: Bluetooth 4.0 BLE TI CC2541 Module Low Power HM ...
  • First, we have to check if the device can use Bluetooth. To do this we have to use the hasSystemFeature method.

Add this method to the MainActivity class and call if in onCreate:

If Bluetooth is not supported we can’t do anything else, so just toast a message to the user and finish the activity .

  • The next Thing is to check if the Bluetooth is enabled. For this add this method to the onStart: method.

We do this in the onStart method, because the user can disable the bluetooth at any time when the activity is paused.

Further if the Bluetooth is disabled we just ask the user to enable it.

The last thing to check is if the user has granted the fine location permission and if not to ask him to do so.

Add this method to the MainActivity and call it from onCreate and onStart methods.

In this way if the user grants or declines the permission after the onCreate call we can check it again in the onStart.

If the permission is not granted all we can do is to request it. We have no control over the dialog that is presented to the user.

With this the Bluetooth preparations are finished. Now we know that:

  • We have a Bluetooth capabilities

  • Bluetooth is enabled

  • And we have all the permission needed to search for BLE devices and connect to them

Now let’s search for BLE devices

Recommended Reading: Walmart Bluetooth Speaker With Lights

How To Install The Arduino Nano 33 Ble Board

After getting your Arduino Nano 33 BLE board thereâs a little setup to do. First, open up the Arduino IDE and navigate to the âBoards Manager.â

Search for Nano 33 BLE and install the board Arduino nRF528xBoards .

Your Arduino should be ready work with the Nano 33 boards, except BLE. For that, we need another library.

Use Your Ble Smartphone With Arduino

To connect your phone to Bluetooth first you need a Bluetooth Serial App. Ive used Bluetooth Serial Terminal.

After the connection is established, press the M1 key to assign it a value. Assign M1 = 1 and M2 = 2.

Now power up the Arduino and Click M1 on the Smartphone App. You should see the first LED turn on. Click M1 again to turn the LED off. Repeat this process with M2 for the second LED.

And thats it! Now that you know how to control LEDs with Arduino through Bluetooth, you can tinker around with this tutorial and modify the code to control your own projects.

If you have any questions or face any difficulty, feel free to ask in the comments below. In next tutorial, I will show you how to make bluetooth controlled robot.

Would you like to learn basics of robotics? Check out our new Robotics eCourse.

Also Check: Audi A4 Ami Bluetooth Adapter

Programming Arduino Uno To Control Led Using Hm

As always complete program with demonstration video can be found at the end of this tutorial. Programming Arduino UNO for this project neither requires much effort nor any library. You can use hardware serial and software serial library. If you are using software serial then just include software serial library else proceed with hardware serial. In this project we are using SoftwareSerial. So start with including Software Serial Library. The pins Rx and Tx are connected at 2 and 3 Pins of Arduino.

#include < SoftwareSerial.h> SoftwareSerial HM10  // RX = 2, TX = 3

Testing The Esp32 Ble Server With Your Smartphone

Ultra Low Power REYAX RYB080I BLE Module Tutorial | How to use RYB080I Bluetooth with Arduino

Most modern smartphones should have BLE capabilities. Im currently using a OnePlus 5, but most smartphones should also work.

You can scan your ESP32 BLE server with your smartphone and see its services and characteristics. For that, well be using a free app called nRF Connect for Mobile from Nordic, it works on Android and iOS .

Go to Google Play Store or App Store and search for nRF Connect for Mobile. Install the app and open it.

Dont forget go to the Bluetooth settings and enable Bluetooth adapter in your smartphone. You may also want to make it visible to other devices to test other sketches later on.

Once everything is ready in your smartphone and the ESP32 is running the BLE server sketch, in the app, tap the scan button to scan for nearby devices. You should find an ESP32 with the name MyESP32.

Click the Connect button.

As you can see in the figure below, the ESP32 has a service with the UUID that youve defined earlier. If you tap the service, it expands the menu and shows the Characteristic with the UUID that youve also defined.

The characteristic has the READ and WRITE properties, and the value is the one youve previously defined in the BLE server sketch. So, everything is working fine.

You May Like: How To Play Radio Through Bluetooth Speaker

About Bluetooth Low Energy

The Bluetooth Low Energy radio is an highly optimized version of Bluetooth classic that specially designed to work with low power consumption. It has capability to transmit the data over 40 channels in the unlicensed ISM frequency range of 2.4GHZ that provides flexibility to build products that meet the unique connectivity requirements of their market.

Bluetooth® initially known for its device communications capabilities, Bluetooth LE is now also widely used as a device positioning technology to address the increasing demand for high accuracy indoor location services. Initially supporting simple presence and proximity capabilities, Bluetooth LE now supports Bluetooth® Direction Finding and soon, high-accuracy distance measurement. That is why BLE has become one of the prominent technologies in the internet of things . BLE supports not only point-to-point communication, but also broadcast mode, and mesh network.

Bluetooth® Low Energy is designed as a low power consumption version of the generic classic Bluetooth connection. Instead of focusing on high data rates, Bluetooth® Low Energy is optimized for reduced energy consumption and is widely used in applications such as fitness trackers, smartwatches, and battery-operated devices.

The major differences between Bluetooth® Classic and Bluetooth® Low Energy in terms of electrical specifications. You can view the table below to see some of the differences between the two modes of Bluetooth connections.

Communication Between Nrf52840 Adafruit Bluefruit Le Connect App

Compile the above sketch and flash it to your nRF52840 Devleopment Board. Once you are done uploading, open the Serial Monitor . The Serial Monitor will show the following output.

Now Open the Bluefruit LE Connect application on your mobile device. Connect to the appropriate target Bluefruit52.

Once connected switch to the Controller application inside the app.

Now you can Enable an appropriate control surface. The following are the controls as shown in the image below.

Now you can check the control of each function. The Accelerometer, Gyroscope, Magnetometer, Color Picker, etc can be enabled and disabled by turning the ON/OFF virtual button. The SSD1306 I2C OLED Display will display the data obtained from your Phone.

Don’t Miss: Top Bluetooth Noise Cancelling Headphones

Difference Between Hm10 And Other Bluetooth Module

The major difference HM10 possess is the Bluetooth Version. The HM10 is Bluetooth 4.0 module, so it comes with all Bluetooth Version 4.0 features such as speed, throughput and range. The HM10 offers a data rate of up to 24 Mbps with low-energy/low-power consumption. Along with this the HM10 offers a distance range of 100 meters in open space. Compare to other Bluetooth modules such as HC-05 which is a Bluetooth 2.0 based module, the HM10 certainly performs better than the HC-05. The HC-05 only offers 3 Mbps compared to HM10 which is quite less.

Bluetooth module HC-05 and HC-06 are still very popular among makers and hobbyists as they are cheap and easy to interface. We also made many projects using HC-05/06 and interfaced them with many other microcontrollers:

All the Bluetooth related projects can be found at this link.

Today we will interface HM-10 BLE Module with Arduino Uno to control an LED wirelessly using Bluetooth protocol. The On/Off commands will be sent by Smartphone.

  • Arduino Bluetooth Controller Android App
  • Android Smart phone

Circuit diagram for connecting Arduino and HM-10 Bluetooth module is very simple as shown below.

Connect To The Bluetooth Ble Module

Arduino :: NRF52832 Bluetooth BLE 4.2 Low Power Module

First we have to add a connectToDevice method to the BLEController class:

First, we stop the scanner .

Then we can start the connection process. As usual the connectGatt method expects a callback.

The callback has two methods.

onConnectionStateChange is called when the connection state is changed .

When the state is connected we start the discoverServices right away. BLE uses services and we have to find the right one

When the state is disconnected, we just fire a disconnected event, so the listeners can show the appropriate state

onServicesDiscovered is called when a service is discovered on).

Here we have to find the right service that we configured in the previous tutorial. We are looking for a service with UUID that starts with “0000FFE0” and Characteristic UUID that starts with “0000FFE1“.

When we find the right BluetoothGattCharacteristic we have to store it in a local variable. We will need it to send data to the Bluetooth device later.

One last thing we need is a way to disconnect from the BLE device. For this add this method:

With this the connection is established and we can fire the connected event.

Now we can use this functionality from the MainActivity.

First, we need to initialize the Connect and Disconnect buttons:

These two methods are pretty straight forward and the buttons just use the corresponding methods in the BLEController class.

Now call this methods in the onCreate method. Also don’t forget to disable the buttons in onCreate.

Read Also: Tiny In Ear Bluetooth Headphones

What Is Hm10 Ble 40 Module

The HM10 is a serial BLE module which is intended to use for the low power consumption applications and can last long even with a coin-sized battery. The HM10 is a Bluetooth 4.0 module based on the Texas Instruments CC2540 or CC2541 BLE System SoC . The firmware and design of the module is made and managed by Jinan Huamao Technology. The module comes with serial/UART layer which makes the device to be able to interface with different microcontrollers. The HM10 is ideal for creating simple connections and using it with or as an iBeacon.

The HM10 has become a very popular Bluetooth 4.0 BLE module. The HM10 is a Bluetooth 4.0 based module only, so it will not connect with Bluetooth 2/2.1 module such as HC-05, HC-06 and other Bluetooth modules. The HM10 is controlled via AT commands sent over the serial UART connection. HM-10 is a Bluetooth Low Energy module, to know more about BLE follow the link. Also learn how an nRF24L01 module can be used as BLE module with Arduino.

What Is Bluetooth Low Energy

Bluetooth 5.0 is the latest version of the Bluetooth wireless communication standard. Bluetooth 5 is the most significant advancement in the Bluetooth standard since the introduction of Bluetooth Low Energy in Bluetooth 4.0. Its commonly used for wireless headphones and other audio hardware, as well as wireless keyboards, mice, and game controllers. Bluetooth is also used for communication between various smart home and Internet of Things devices.

There are four significant new features of Bluetooth 5 compared to BLE 4.0:1. A higher bit rate of 2 Mbps.2. A long-range mode with better sensitivity at two new lower bit rates of 500 kbps and 125 kbps.3. An 8 x improvement in broadcast capability with advertising extensions.4. An improved channel selection algorithm

Also Check: Bathroom Fan With Led Light And Bluetooth

How Much An Arduino With Bluetooth Costs

An Arduino with Bluetooth can cost as little as $18, however the cost can go over $100 depending on other features of the board. For most Bluetooth-related projects, expect to spend between $20 and $45 on an Arduino with Bluetooth built in.

The table below lists all the Arduino models that come with Bluetooth built in, and how much each of them costs:

Arduino Model

Typical costs of Arduino models with Bluetooth

The Nano 33 series are designed to be small form factor boards great for wearable devices and gathering data from sensors. Being equipped with Bluetooth, they can operate as a Bluetooth peripheral and be used to send data back to a host.

The Nano 33 series and the MKR WiFi 1010 operate at 3.3V. This means they may not always be compatible with 5V shields. There are work-arounds available to get them working with 5V shields, but if you have a shield in mind then it may be best to check the compatibility before buying one of these boards. I chose the UNO WiFi Rev2 for my first board because of its support for a variety of shields.

Other popular Arduino boards, such as the Mega family and the Due, do not come with Bluetooth included. In the next section of this guide Ive included how to add Bluetooth to an Arduino which doesnt already come with it.

Testing Esp32 Ble Server With A Android App

Bluetooth Low Energy Tutorial with HM-10 BLE 4.0 & Arduino

To perform this testing functionality of the ESP32 BLE server on a cell phone we will need a phone which supports BLE connection. After you have got your hands on one, open the Play Store and search for ânRF Connect for Mobile.â This is a free app that will help us to check for the connection. Install the app on your cell phone.

Before proceeding further, make sure to change your Bluetooth settings by enabling the Bluetooth adapter in your cell phone as shown in the figure.

Press the ENABLE button on your ESP32 board and open the serial monitor.

In this case, the cell phone acts as the client and the ESP32 board which has the BLE_server uploaded on it is the server.

Now, open the nRF Connect for Mobile application and tap the Scan button. This will scan for all the devices which are close to the cell phone. Thus, our ESP32 will also get scanned and you will be able to see âMicrocontrollerslab ESP32â written among the scanned devices as shown below:

Now, tap the Connect button and the following appears on the cell phone screen.

The Service and the Characteristic which we had defined in the program code can be viewed here. It displays âHello World says Neilâ which we set as our characteristic value and both the service and the characteristic UUIDs are also visible with the properties which we set to Read and write in the BLE_server example code.

We can write any message as shown below:

Recommended Reading: Vizio Sound Bar With Bluetooth

Popular Articles

Related Stories