ESP32 BLE | Quick & Easy Steps to Use with Arduino IDE


In this blog, we’ll walk through the quick and easy steps to get started with Arduino IDE for programming the ESP32 BLE functionality. If you're new to Arduino IDE or ESP32 BLE, don’t worry — this guide will cover everything from setup to writing a simple ESP32 BLE application.
ESP32 BLE

Introduction

The ESP32 is a powerful microcontroller that integrates Bluetooth Low Energy (BLE) and Wi-Fi capabilities, making it ideal for Internet of Things (IoT) projects. The ESP32 BLE is one of its popular features, and incorporating it into your project can enable a wide range of applications, from remote control systems to sensor data transmission, and much more.

Installing the Arduino IDE to Develop ESP32

If you haven't installed the Arduino IDE yet, head over to the official Arduino website to download and install the latest version. The Arduino IDE is a cross-platform tool, compatible with Windows, macOS, and Linux.

Configuring Arduino IDE to Support ESP32

1. Open the Arduino IDE and select Arduino > Preferences (for macOS).

2. In the Additional Boards Manager URLs field, add the following URL:

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

* If you already have other URLs in the field, you can add this URL after them, separated by commas.

3. Click OK to save the settings.
Arduino IDE

Installing ESP32 Board Support

1. Open the Arduino IDE and go to Tools > Board > Board Manager.
2. In the search box, type ESP32, find "esp32" by Espressif Systems, and click Install.

Selecting the ESP32 Development Board

After installation, go to Tools > Board and select ESP32 Dev Module from the list. This is a commonly used ESP32 board model.

Basic ESP32 BLE Sketch

Now it’s time to upload a basic BLE sketch to your ESP32 to verify everything is set up properly.

1. Open a new sketch in the Arduino IDE.

2. Copy and paste the following code, which demonstrates how to set up a simple BLE server:
1. This code creates a BLE server that advertises a service and a characteristic.

2. The SERVICE_UUID and CHARACTERISTIC_UUID are unique identifiers for your service and characteristic. These are used by clients to interact with the server.

BLE Server (Server) | BLE Client (Client)

RoleBLE 伺服器 (Server)BLE 客戶端 (Client)
FunctionProvides services and characteristics, waits for client requestsInitiates connection, reads/writes characteristics, subscribes to notifications
Request InitiationPassive, waits for client actionsActive, initiates requests and connections
Data StorageStores characteristic data, provides functionalityReads/Modifies data provided by the server
Typical DevicesSmart bulbs, sensors, monitoring devices, etc.Smartphones, tablets, etc.
Connection ModeBroadcasts and waits for connectionScans and selects available servers to connect

Uploading the Program to ESP32

1. Connect the ESP32 development board to your computer using a USB data cable.

2. In the Arduino IDE, go to Tools > Port and select the correct port (for example, it is usually COM3 on Windows and /dev/ttyUSB0 on Linux/macOS).

3. Click the Upload button to upload the program to the ESP32.

Results

Once the upload is successful, the ESP32 will start advertising its BLE service.

1. Open a BLE scanner app on your smartphone (e.g., nRFConnect for Mobile).

2. Scan for available BLE devices and you should see ESP32_BLE_Server.

3. Connect to the ESP32, and you should be able to see the Hello BLE message from the characteristic.

Conclusion

Using Arduino IDE with the ESP32 for BLE projects is an easy and powerful way to get started with Bluetooth Low Energy. By following these simple steps, you can set up the environment, upload a basic ESP32 BLE sketch, and even test the connection using a smartphone app. From here, you can extend your project by exploring more complex BLE interactions, like connecting multiple devices or controlling IoT hardware.

Happy coding and exploring with ESP32 BLE!