ESP32 - Classic Bluetooth and Bluetooth Low Energy

Overview

This tutorial demonstrates how to implement wireless communication between the ESP32 and the DIYables Bluetooth App using either Classic Bluetooth or Bluetooth Low Energy (BLE). The ESP32 features integrated Bluetooth capabilities, eliminating the need for external Bluetooth modules.

The ESP32 provides native support for both Classic Bluetooth and BLE protocols, enabling direct connectivity to the DIYables Bluetooth App on Android and iOS devices without additional hardware requirements.

Key Information: The ESP32 supports dual Bluetooth modes — both Classic Bluetooth and BLE (Bluetooth Low Energy). The DIYables Bluetooth App provides full support for Classic Bluetooth and BLE on Android platforms, with BLE support on iOS. Users can select the appropriate protocol based on their platform requirements and project specifications.

ESP32 Bluetooth Tutorial - Classic Bluetooth and BLE with DIYables Bluetooth App

Features

  • Dual Protocol Support: Implements both Classic Bluetooth and BLE protocols for maximum compatibility
  • Wireless Range: Provides wireless communication up to 10 metres
  • Multi-Platform Compatibility: Supports both Android and iOS operating systems
  • Flexible Connection Methods: Classic Bluetooth uses traditional pairing; BLE offers automatic connection
  • Comprehensive Widget Library: Includes sliders, joystick, monitor, plotter, gauge, temperature display, chat, table, rotator, and additional interface components
  • Power Efficiency Options: BLE mode optimized for low-power applications; Classic Bluetooth provides broader device compatibility
  • Simple Integration: Single library installation manages all communication protocols

Hardware Used In This Tutorial

1×ESP-WROOM-32 Dev Module
1×Alternatively, ESP32 Uno-form board
1×Alternatively, ESP32 S3 Uno-form board
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×Recommended: Screw Terminal Expansion Board for ESP32
1×Recommended: Breakout Expansion Board for ESP32
1×Recommended: Power Splitter for ESP32

Or you can buy the following kits:

1×DIYables ESP32 Starter Kit (ESP32 included)
1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links in this section are Amazon affiliate links, meaning we may earn a commission at no additional cost to you if you make a purchase through them. Additionally, some links direct you to products from our own brand, DIYables .

Software Setup

Quick Instructions

Follow these procedures to configure the development environment:

  • For initial ESP32 setup, consult the ESP32 getting started guide.
  • Connect the ESP32 board to the computer via USB cable.
  • Launch the Arduino IDE.
  • Select the ESP32 board and corresponding COM port.

Install Board Core

  • Navigate to Tools Board Boards Manager...
  • Search for "esp32"
  • Install esp32 by Espressif Systems

Install DIYables Bluetooth Library

  • Access the Libraries icon in the Arduino IDE left sidebar.
  • Search for "DIYables Bluetooth" and locate the DIYables Bluetooth library by DIYables
  • Click Install to add the library
ESP32 DIYables Bluetooth library
  • When prompted, install the required library dependencies
  • Click Install All to complete the installation.
ESP32 DIYables Bluetooth dependency

Mobile App

  • Install the DIYables Bluetooth App: Android | iOS

Platform Compatibility: The DIYables Bluetooth App supports both Classic Bluetooth and BLE on Android platforms, with BLE support on iOS. The ESP32's dual-mode capability allows protocol selection based on platform requirements. Android devices support both Classic Bluetooth and BLE modes. iOS devices require BLE mode. BLE connections establish automatically without manual pairing procedures.

  • Launch the DIYables Bluetooth App
  • Grant the following permissions when requested:
    • Nearby Devices permission (Android 12+) / Bluetooth permission (iOS) - Required for Bluetooth device scanning and connection
    • Location permission (Android 11 and below only) - Required by Android system for Bluetooth device scanning
  • Verify Bluetooth is enabled in device settings
  • Tap the Connect button on the home screen to initiate device scanning.
DIYables Bluetooth App - Home Screen with Scan Button
  • Select the ESP32 device from the scan results to establish connection.

Examples

The ESP32 supports both Classic Bluetooth and BLE protocols. Select the appropriate implementation based on project requirements. All examples are compatible with ESP32 hardware.

Classic Bluetooth Examples (Android Only) and BLE Examples (Android & iOS)

Troubleshooting

SymptomProbable CauseResolution
Device not visible during app scanningIncorrect Bluetooth mode or firmware not runningVerify code uses correct Bluetooth mode (Classic or BLE) and ESP32 is executing
SerialBT.begin() or BLE.begin() failsBoard core or library incompatibilityInstall ESP32 board core by Espressif Systems via Boards Manager
Connection established but no data transferOutdated DIYables libraryUpdate DIYables Bluetooth library to latest version via Library Manager
Compile error BluetoothSerial.h or BLEDevice.h not foundDIYables Bluetooth library not installedInstall DIYables Bluetooth library via Library Manager
Compile errors related to board selectionIncorrect board selected or core missingSelect ESP32 board and install esp32 core by Espressif Systems
Connection drops immediately after establishmentInterference or power supply issuesEnsure stable USB power supply and maintain device proximity within 10 metres
Classic Bluetooth fails on iOSiOS does not support Classic Bluetooth profileUse BLE mode for iOS device compatibility

Notes

  • For ESP32 implementation, use Esp32Bluetooth_ examples for Classic Bluetooth or Esp32BLE_ examples for BLE. ArduinoBLE_ examples are designed for different hardware platforms (e.g., Arduino Uno R4).
  • Classic Bluetooth requires manual pairing through device Bluetooth settings prior to app connection (Android only).
  • BLE establishes automatic connections without manual pairing procedures and supports both Android and iOS platforms.
  • Maintain continuous power supply (USB or external) to ensure persistent Bluetooth advertisement and device discoverability.
  • IOS compatibility requires BLE mode as iOS does not support Classic Bluetooth for accessory devices.

※ OUR MESSAGES