Mission Briefing
By the end of this mission, you will be able to:
Explain what Bluetooth Low Energy (BLE) is and why it's used in small devices
Initialize the ESP32's BLE hardware in code
Scan for and count nearby BLE devices using the Serial Monitor
Let's Get Started
Right now, all around you, invisible wireless signals are floating through the air — headphones talking to phones, fitness trackers talking to apps, smart bulbs waiting for commands. Nearly all of them use Bluetooth Low Energy, or BLE. Today your ESP32 gets its first taste of that invisible world by learning to listen for it.
Robo says: "I can't see WiFi routers or Bluetooth speakers with my eyes, but I CAN listen for their radio signals — today I learn how!"
What Makes BLE Different?
Classic Bluetooth (the kind used for wireless speakers and headphones) is built for continuous, high-bandwidth audio streaming, which uses a fair amount of power. BLE was designed for the opposite goal: sending small bits of data very efficiently, using a tiny fraction of the power. This is exactly why BLE shows up in things that run for months or years on a coin-cell battery, like fitness trackers and smart locks.
Scanning: Listening Before Talking
Before your ESP32 can connect to or control anything over BLE, it needs to know what's nearby. Scanning means listening for other BLE devices that are broadcasting ("advertising") their presence, and counting or listing what's found — like turning on a radio and slowly tuning across stations to see what's out there.
Equipment
- ESP32
- USB cable for programming
Activity
Scan for nearby BLE devices and print the number found to the Serial Monitor every 5 seconds.
Code
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
int scanTime = 5; // seconds
BLEScan* pBLEScan;
void setup() {
Serial.begin(115200);
BLEDevice::init("");
pBLEScan = BLEDevice::getScan();
pBLEScan->setActiveScan(true);
}
void loop() {
Serial.println("Scanning...");
BLEScanResults foundDevices = pBLEScan->start(scanTime);
Serial.print("Devices found: ");
Serial.println(foundDevices.getCount());
pBLEScan->clearResults();
delay(5000);
}Did You Know?
- • BLE was specifically designed so a device like a heart-rate monitor could run for over a YEAR on a single tiny coin-cell battery — something that would be completely impossible using classic Bluetooth's power-hungry continuous streaming.
🔧 Try It Yourself
Run the scan near several BLE devices (phones, headphones, smartwatches) and watch the device count change. Try walking to a different room and rescanning.
• Device count near lots of gadgets:
• Device count in a quieter room:
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
int scanTime = 5; // seconds
BLEScan* pBLEScan;
void setup() {
Serial.begin(115200);
BLEDevice::init("");
pBLEScan = BLEDevice::getScan();
pBLEScan->setActiveScan(true);
}
void loop() {
Serial.println("Scanning...");
BLEScanResults foundDevices = pBLEScan->start(scanTime);
Serial.print("Devices found: ");
Serial.println(foundDevices.getCount());
pBLEScan->clearResults();
delay(5000);
}Think About It
🤔 Discuss With a Partner or Write Your Answer
Why do you think BLE devices need to periodically "advertise" their presence instead of just staying silent until someone tries to connect?
Quick Recap: Fill In The Blanks
1. BLE stands for Bluetooth Low __________.
2. BLE is designed to use much less __________ than classic Bluetooth.
3. __________ means listening for nearby BLE devices that are broadcasting their presence.
4. BLEDevice::init() must be called before your ESP32 can __________ for other devices.
Match It!
Draw a line (or write the matching letter in the blank) to connect each word to its meaning.
Check Your Understanding
I can explain what Bluetooth Low Energy (BLE) is and why it's used in small devices
I can initialize the ESP32's BLE hardware in code
I can scan for and count nearby BLE devices using the Serial Monitor
Quiz Time!
Question 1: What is BLE primarily optimized for?
🔍 Reveal answer (drag-select the blank space):
Question 2: What does pBLEScan->start(scanTime) do?
🔍 Reveal answer (drag-select the blank space):
Question 3: Why can BLE devices run for a long time on tiny batteries?
🔍 Reveal answer (drag-select the blank space):
Challenge Zone
🏆 Level Up
Modify the code to print not just the COUNT of devices found, but also each device's advertised name (if available) using foundDevices.getDevice(i).getName(), looping through all found devices.
Robot Journal
List three BLE-powered devices you personally use or have seen (headphones, smartwatch, fitness tracker, smart lock). How does knowing they all use low-power wireless signals change how you think about them?
Lesson Wrap-up
🤖 Robo Says
Robo says: "Now I can hear the invisible wireless world around me! Next, let's flip the script — I'll become the one broadcasting data for OTHERS to find."