Esp32 Ble Beacon Scanner — this detailed tutorial covers everything from hardware selection to complete working code, designed for Indian makers, students, and engineers.
Table of Contents
- What is Bluetooth Low Energy?
- Creating an ESP32 BLE Beacon
- Building a BLE Scanner
- Creating a GATT Server
- Recommended BLE Apps for Testing
- BLE Power Optimisation
- Frequently Asked Questions
What is Bluetooth Low Energy?
BLE (Bluetooth Low Energy) operates at 2.4 GHz like Classic Bluetooth but uses significantly less power — as low as 10 µA in sleep mode. The ESP32 supports BLE 4.2 with both Central (scanner) and Peripheral (beacon/server) roles. Unlike Bluetooth Classic’s SPP model, BLE uses a GATT (Generic Attribute Profile) architecture with Services and Characteristics. Each service has a UUID and contains one or more characteristics that hold data values. For example, a temperature sensor might expose a service with UUID 0x181A (Environmental Sensing) containing a temperature characteristic.
Creating an ESP32 BLE Beacon
An iBeacon broadcasts a UUID, Major, and Minor value that nearby devices can detect. This is useful for indoor positioning, museum guides, and proximity-triggered actions.
#include <BLEDevice.h>
#include <BLEBeacon.h>
void setup() {{
BLEDevice::init("");
BLEServer *pServer = BLEDevice::createServer();
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
BLEBeacon oBeacon = BLEBeacon();
oBeacon.setManufacturerId(0x4C00);
oBeacon.setProximityUUID(BLEUUID("12345678-1234-1234-1234-123456789012"));
oBeacon.setMajor(1);
oBeacon.setMinor(100);
BLEAdvertisementData oAdvertisementData;
oAdvertisementData.setFlags(0x04);
std::string strServiceData = "";
strServiceData += (char)26;
strServiceData += (char)0xFF;
strServiceData += oBeacon.getData();
oAdvertisementData.addData(strServiceData);
pAdvertising->setAdvertisementData(oAdvertisementData);
pAdvertising->start();
}}
void loop() {{
delay(1000);
}}
This beacon can be detected by any BLE scanner app on both Android and iOS — unlike Bluetooth Classic which does not work with iPhones.
Building a BLE Scanner
The ESP32 can scan for nearby BLE devices and report their names, RSSI (signal strength), and advertised data:
#include <BLEDevice.h>
#include <BLEScan.h>
BLEScan* pBLEScan;
class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {{
void onResult(BLEAdvertisedDevice advertisedDevice) {{
Serial.printf("Device: %s RSSI: %dn",
advertisedDevice.toString().c_str(),
advertisedDevice.getRSSI());
}}
}};
void setup() {{
Serial.begin(115200);
BLEDevice::init("");
pBLEScan = BLEDevice::getScan();
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(true);
pBLEScan->setInterval(100);
pBLEScan->setWindow(99);
}}
void loop() {{
Serial.println("Scanning...");
BLEScanResults results = pBLEScan->start(5, false);
Serial.printf("Found %d devicesn", results.getCount());
pBLEScan->clearResults();
delay(5000);
}}
Creating a GATT Server
A GATT server exposes data that BLE clients can read, write, or subscribe to with notifications. This is the foundation for custom BLE sensor devices. Create a service, add characteristics with properties (Read, Write, Notify), and set callbacks for client interactions. Popular use cases include custom sensor hubs, remote controls, and wearable devices that communicate with phone apps.
Recommended BLE Apps for Testing
Several free apps work excellently for testing ESP32 BLE projects:
- nRF Connect (Nordic Semiconductor) — the gold standard for BLE debugging on both Android and iOS
- LightBlue — simple and clean interface for iOS
- BLE Scanner — basic but effective Android app
nRF Connect lets you discover services, read/write characteristics, and subscribe to notifications — essential for debugging GATT servers.
BLE Power Optimisation
For battery-powered BLE beacons, reduce advertising interval to save power. A 1-second interval uses ~12 mA, while a 10-second interval drops to ~1.5 mA average. Combine with ESP32 deep sleep: wake up, advertise for 30 seconds, then sleep for 5 minutes. A 2000 mAh battery can power such a beacon for over a year. Use esp_deep_sleep_start() with a timer wakeup source.
Frequently Asked Questions
Can ESP32 BLE work with iPhones?
Yes, BLE works with both Android and iOS. This is the main advantage over Bluetooth Classic, which does not support SPP on iPhones. Use GATT services for cross-platform compatibility.
What is the range of ESP32 BLE?
Typical indoor range is 30-50 metres, and outdoor line-of-sight can reach 100+ metres. Range depends on advertising power level, which you can set from -12 dBm to +9 dBm using esp_ble_tx_power_set().
How many BLE connections can ESP32 handle simultaneously?
The ESP32 can maintain up to 9 simultaneous BLE connections as a central device and 3 connections as a GATT server. For most projects, 3-4 connections work reliably.
Conclusion
The ESP32 platform continues to impress with its versatility and value for money. This project demonstrates just one of hundreds of applications possible with affordable microcontrollers. Indian makers have a unique advantage — access to affordable components, a growing community, and endless real-world problems to solve with technology. Whether you are building this for learning, a college project, or a commercial product prototype, the fundamentals covered here will serve you well.
Ready to start building? Browse our ESP32 development boards at Zbotic for the best prices in India with fast shipping!
Add comment