In this guide, we’ll provide you with all the information to master Bluetooth (Classic and Low Energy) with the ESP32 in no time. ESP32 boards are great for IoT projects because they support Wi-Fi, Bluetooth Classic, and Bluetooth Low Energy. This is a comprehensive guide that compiles several of our previous projects in a logical way to make the learning process easier.
In this tutorial, we’ll cover the following topics:
- What is Bluetooth?
- What is Bluetooth Low Energy?
- Bluetooth Classic vs Bluetooth Low Energy
- Bluetooth Classic with the ESP32
- Bluetooth Low Energy with the ESP32
What is Bluetooth?
Bluetooth is a wireless technology that enables devices to communicate over short distances.
It’s commonly used for connecting devices like headphones to phones or linking a keyboard or mouse to a computer. The ESP32 board also supports Bluetooth along with Wi-Fi, making it an excellent choice for IoT projects. This capability allows ESP32-based projects to wirelessly exchange data or connect to other Bluetooth-enabled devices seamlessly.
This variant of Bluetooth is also referred to as “Bluetooth Classic” or simply “Bluetooth”.
What is Bluetooth Low Energy?
Bluetooth Low Energy, BLE for short (also called Bluetooth Smart), is a power-conserving variant of Bluetooth. BLE’s primary application is short-distance transmission of small amounts of data (low bandwidth). Unlike Bluetooth which is always on, BLE remains in sleep mode constantly except for when a connection is initiated.
This makes it consume very little power. BLE consumes approximately 100x less power than Bluetooth (depending on the use case).
Bluetooth Classic vs Bluetooth Low Energy
So, what are the main differences between Bluetooth Classic and Bluetooth Low Energy?
Bluetooth Classic is known for higher data transfer rates, making it suitable for applications like audio streaming and file transfer. It consumes more power, making it less ideal for battery-operated devices.
On the other hand, BLE is designed for low power consumption, making it perfect for devices like IoT gadgets and wearables, and is also a great solution for the ESP32 in IoT and Home Automation applications. BLE operates with lower data transfer rates but is energy-efficient and works well in short-range scenarios.
Another big difference between the two versions of Bluetooth is the way used to transfer data. Bluetooth Classic uses something similar to Serial Communication, while Bluetooth Low Energy uses a client-server model, where it employs the GATT (Generic Attribute Profile) to structure data.
Bluetooth Classic | Bluetooth Low Energy (BLE) | |
Power Consumption | Higher power consumption | Low power consumption |
Data Transfer Rate | Higher data transfer rates | Lower data transfer rates |
Range | Longer range | Shorter range |
Application Examples | Audio streaming, file transfer | IoT devices, wearables, smart home |
Data Transfer | Serial Port Profile (SPP) | Generic Attribute Profile (GATT) |
You can check in more detail the main differences between Bluetooth and Bluetooth Low Energy here.
Bluetooth Classic with the ESP32
In terms of programming, using Bluetooth Classic is much simpler than setting up the ESP32 as a BLE device. If you’ve already programmed an Arduino board with a Bluetooth module like the HC-06, it is very similar. It uses the standard serial protocol and functions.
We have a detailed tutorial explaining how to exchange data with the ESP32 via Bluetooth Classic. Check the link below:
- ESP32 Bluetooth Classic with Arduino IDE – Getting Started (only compatible with Android Smartphones)
It also includes a sample project showing how to send sensor readings to your smartphone and control an LED via Bluetooth Classic.
BLE with the ESP32 – Getting Started Guides
Understanding how Bluetooth Low Energy works is a bit more complicated than Bluetooth Classic. But, don’t worry, we have several guides focused on different subjects with project examples so that you easily understand how it works.
ESP32 Getting Started with Bluetooth Low Energy
The best way to get started with BLE and the ESP32 is to start by learning about basic concepts like BLE Server and Client, GATT, BLE Profiles, Services, and Characteristics. You can start with the following tutorial:
This tutorial explains BLE’s most important theoretical concepts and tests some basic BLE examples on the ESP32 to set it as a BLE Client and as a BLE Server.
ESP32 Bluetooth Low Energy Client and Server
With Bluetooth Low Energy, there are two types of devices: the server and the client. The ESP32 can act either as a client or as a server.
The server advertises its existence, so it can be found by other devices and contains data that the client can read. The client scans the nearby devices, and when it finds the server it is looking for, it establishes a connection and listens for incoming data. This is called point-to-point communication.
We have a tutorial explaining how to set one ESP32 board as a client and another as a server to exchange data.
Check the tutorial below:
In this project, we show how to send sensor data from one ESP32 board to another via BLE. The receiver board displays the data on an OLED display.
Setting the ESP32 Board as a BLE Server (Environmental Sensing Service)
Communication with Bluetooth Low Energy involves the use of the Generic Attribute Profile (GATT) to exchange data.
GATT defines the structure for organizing and exchanging information between devices with attributes like services and characteristics. In this framework, devices follow default standards such as Universally Unique Identifiers (UUIDs) to uniquely identify services and characteristics.
We have a tutorial explaining how to set the ESP32 as a Bluetooth device that exposes an environmental sensing device following the default GATT structure and UUIDs.
This is a great project to better understand how the GATT structure works and how to properly create BLE devices with the ESP32.
Web Bluetooth Technology with the ESP32
Web Bluetooth (also sometimes referred to as Web BLE) is a relatively recent technology that allows you to connect and control BLE-enabled devices, like the ESP32, directly from your web browser using JavaScript.
With Web BLE, you can create web applications that interact with your ESP32 devices via Bluetooth, enabling you to control GPIO pins, exchange data, and manage your devices remotely through a web interface (this means any device that supports a web browser like your computer or smartphone).
This cross-platform compatibility removes the need for users to download and install dedicated mobile apps, simplifying the user experience and reducing development efforts.
We have an in-depth tutorial explaining the principles of Web Bluetooth and how to create a Web Bluetooth App to exchange data with the ESP32 to get sensor readings and control outputs. Check the tutorial below:
Wrapping Up
In this comprehensive guide, we’ve provided all the information you need to master Bluetooth with the ESP32, whether it’s Bluetooth Classic or Bluetooth Low Energy. Additionally, we cover Web Bluetooth, a relatively recent technology that enables you to create a web app for controlling your devices via Bluetooth.
Feel free to bookmark this page so that you can easily revisit and reread the content whenever you need it in the future.
We hope you’ve found this article useful to learn more about Bluetooth with the ESP32. Are there any other topics related to Bluetooth that you would like to see covered here? Write a comment below.
Learn more about the ESP32 with our resources:
- Learn ESP32 with Arduino IDE (eBook)
- Build Web Servers with ESP32 and ESP8266 (eBook)
- Firebase Web App with ESP32 and ESP8266 (eBook)
- SMART HOME with Raspberry Pi, ESP32, and ESP8266
- Free ESP32 Projects and Tutorials…
Thanks for reading.
Hi, I know I’ve already asked about this, but I didn’t see mention of an issue I’m having with BLE on ESP32 on Arduino IDE, and this is supposed to be the ULTIMATE guide 😉
My issue is that my app behaves great, a BLE keyboard mimic works great IN SECLUSION… the moment I combine the BLE Keyboard mimic together with my (facial recognition) app the linker complains I’m out of IRAM (just by 116 bytes!) and I can’t find away around this … an article covering reduction of IRAM WITH EXAMPLES would be really handy, perhaps others are having a similar issue?
Hi.
Instead of the “regular” BLE library, you can use the NimBLE that uses the same methods but occupies much less space. https://github.com/h2zero/NimBLE-Arduino
I haven’t tried it myself , but heard very good feedback.
Regards,
Sara
A simple working example of BLE would be worth thousand words.
So far I have found no BT terminals for neither Windows nor Linux.
The testing of Rx/Tx must be done with Android Bluetooth terminal.