Bluetooth Low Energy, often abbreviated as Bluetooth LE or simply BLE, is a wireless communication technology that allows devices to connect and interact. BLE was designed with the primary goal of providing a more energy-efficient alternative to classic Bluetooth, while maintaining a reliable and robust wireless connection.
BLE is a respectable choice when battery life and efficiency are prioritized. With possible applications in wearable technologies, automation, IoT, and healthcare, it is essential for every developer to understand the fundamentals of BLE.
BLE supports communication in the 2.4 GHz
BLE devices typically come in two forms:
Generic Attribute Profiles (GATT) define how two BLE devices organize and communicate data. These profiles are essentially standardized templates that ensure compatibility between different BLE devices, allowing them to understand and exchange data seamlessly. They use a generic data protocol called the Attribute Protocol (ATT), which stores data in a simple lookup table using 16-bit IDs for each entry in the table. There are two main components of a GATT Profile:
Note: GATT connections are exclusive. This means a peripheral device can only be connected to one central device at a time; it stops advertising itself once it connects to a central device.
GATT transactions refer to the data exchange processes that occur between a central and peripheral device. There are four key GATT transactions:
Read: In a read transaction, the central requests data from a specific characteristic. The peripheral responds with the requested data if it supports reading from that characteristic.
Write: In a write transaction, the central sends data to a specific characteristic for the peripheral to process or store, and the peripheral acknowledges the write operation if it supports it.
Notify: Some characteristics can be configured to send notifications to the central device when their values change in real-time, given the central has subscribed to these notifications.
Descriptor operations: Descriptors are metadata associated with characteristics and can be used to modify their behavior. Central devices can read and write descriptors to control how characteristics behave.
BLE offers low-power consumption, cost-effectiveness, and compatibility, making it suitable for various applications. It particularly benefits IoT, health and fitness, proximity-based services, asset tracking, home automation, and industrial applications. These are the main advantages BLE provides over other communication protocols:
Efficiency: BLE is designed for low-power systems, making it ideal for battery-operated or energy-efficient devices. This is crucial for applications like wearables, IoT sensors, and other devices that need to run on a small power source for extended periods.
Portability and low cost: BLE chips and components are small in size and relatively inexpensive, which makes them suitable for a wide range of devices. This cost-effectiveness allows BLE to be used in various applications.
Compatibility: BLE is compatible with a wide range of devices, including smartphones, tablets, and computers. This makes it easy to connect and communicate with multiple devices, facilitating cross-platform development.
Short range: BLE is designed for short-range communication, typically within a range of 10 meters. This is advantageous for applications where data transmission needs to be localized and secure.
Fast connection: BLE enables fast and efficient connection between devices, reducing latency and improving the user experience.
Low interference: BLE operates in the 2.4 GHz ISM band, which is often used for other wireless technologies. Despite this, it employs advanced techniques to minimize interference, ensuring reliable communication.
BLE implementations vary depending on the type of libraries and environments being used. For this example, let’s use the Arduino BLE library, which has predefined transaction functions, making it easy to use and implement. Our goal is to configure a peripheral device, connect to a central device, and transmit a “Hello world” string.
#include <ArduinoBLE.h>BLEService customService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Define a custom service UUIDBLECharacteristic customCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); // Define a custom characteristic UUIDstring dataToSend = "Hello world"; // Your data to be sentvoid setup() {// Initialize the BLE libraryif (!BLE.begin()) {while (1);}// Set the local name and advertising parametersBLE.setLocalName("Peripheral 1");BLE.setAdvertisedService(customService);customService.addCharacteristic(customCharacteristic); // Add the characteristic to the serviceBLE.addService(customService); // Add the serviceBLE.advertise(); // Start advertising}void loop() {BLEDevice central = BLE.central(); // Wait for a connectionif (central) {while (central.connected()) {customCharacteristic.writeValue(dataToSend);delay(1000); // Send data every second}}}
Lines 1–5: We define a custom service and characteristic using the BLEService
and BLECharacteristic
functions. We load them with arbitrary UUIDs, and the permitted transactions: BLERead
and BLEWrite
.
Line 6: We store the string we want to send in the dataToSend
variable.
Lines 8–22: In the setup()
function, we configure our peripheral device by giving it a name, adding our custom characteristic to our custom service, and advertising it.
Lines 23–33: In the loop()
function, we first check if our device is connected to a central device using BLE.central()
, entering a while
loop when it does. In this loop, we send dataToSend
every second using the writeValue()
and delay()
functions.
As we continue to witness the rapid growth of energy-efficient and reliable wireless connectivity, BLE’s significance in the world of technology remains undeniable. Its efficiency, compatibility, and adaptability make it a crucial player in the ever-expanding landscape of connected devices, promising a future filled with innovative and efficient wireless solutions.
Free Resources