ESP32 with Bluetooth and Bluetooth Low Energy: The Ultimate Guide

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.

ESP32 with Bluetooth and Bluetooth Low Energy The Ultimate Guide

In this tutorial, we’ll cover the following topics:

What is Bluetooth?

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

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 ClassicBluetooth Low Energy (BLE)
Power ConsumptionHigher power consumptionLow power consumption
Data Transfer RateHigher data transfer ratesLower data transfer rates
RangeLonger rangeShorter range
Application ExamplesAudio streaming, file transferIoT devices, wearables, smart home
Data TransferSerial 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.

ESP32 Bluetooth Classic and Android Smartphone BT

We have a detailed tutorial explaining how to exchange data with the ESP32 via Bluetooth Classic. Check the link below:

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.

BLE Client Server Server Advertising

We have a tutorial explaining how to set one ESP32 board as a client and another as a server to exchange data.

ESP32 BLE Server and Client BLuetooth Low Energy Arduino IDE

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.

GATT Hierarchy ESP32 BLE Server Client Example

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.

ESP32 BLE Peripheral (Server): Environmental Sensing Service

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

Explaining Web Bluetooth with ESP32

This cross-platform compatibility removes the need for users to download and install dedicated mobile apps, simplifying the user experience and reducing development efforts.

Web Bluetooth with the ESP32 Getting Started Guide

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:

Thanks for reading.



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

3 thoughts on “ESP32 with Bluetooth and Bluetooth Low Energy: The Ultimate Guide”

  1. 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?

    Reply
  2. 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.

    Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.