Advertise a BLE Service
Expose your ESP32 so a phone can find it.
Advertise a BLE Service is a free Arduino & IoT Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Arduino & IoT Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Make Your Board Findable
Before a phone can connect, your ESP32 must announce itself. This shouting into the air is called advertising. 📣
What Advertising Sends
Advertising broadcasts tiny packets with your device name and what it offers, so nearby phones can list it without connecting yet.
Start with the Library
The Arduino core gives you a BLE library. Include it once, then everything for advertising and connecting becomes a few clean calls.
#include <BLEDevice.h>
#include <BLEServer.h>Name Your Device
First you initialize BLE and give your board a friendly name. That name is what users will tap in their phone's Bluetooth list.
BLEDevice::init("Smart-Sensor");Create a Server
Your board acts as a BLE server: it holds the data, and the phone is the client that asks for it. Create the server next.
BLEServer *server = BLEDevice::createServer();What a Service Is
A service is a labeled group of related data, like all the values for one sensor. A device can offer several services at once.
Services Need a UUID
Each service is identified by a UUID, a long unique code. The phone uses this exact id to find the right service among many.
BLEService *svc = server->createService("180F");Standard vs Custom UUIDs
Short UUIDs like 180F are official standard ones. For your own data, generate a long custom UUID so it never clashes with others.
Start the Service
Once the service is defined, you must start it. Until you do, the phone cannot actually use any of its data.
svc->start();Begin Advertising
Finally, tell the radio to advertise. Now the board broadcasts its name and service so phones nearby can discover it.
server->getAdvertising()->start();Find It on Your Phone
Open a scanner app like nRF Connect and you should see Smart-Sensor appear. Seeing your name means advertising works.
Quick Check
You wrote a service but the phone shows no data inside it.
Recap
Init BLE, name the board, make a server, add a service with a UUID, start it, then advertise. Now your device is discoverable. ✨
Frequently asked questions
Is the “Advertise a BLE Service” lesson free?
Yes — the full text of “Advertise a BLE Service” is free to read here on the web, and the Arduino & IoT Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Arduino & IoT Academy course, upgrade to CoddyKit PRO.
What will I learn in “Advertise a BLE Service”?
Expose your ESP32 so a phone can find it. You practise Arduino & IoT Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Arduino & IoT Academy?
No prior experience is required. Arduino & IoT Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Advertise a BLE Service” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Arduino & IoT Academy lesson?
Yes. Every Arduino & IoT Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Classic Bluetooth vs BLE
- Advertise a BLE Service
- Read & Write Characteristics
- Control an LED from a Phone App