Remote-controlled RGB mood light
Warm, cool, rainbow or breathing: cycle lighting moods from your sofa.
Shop by category
Shop all componentsMost smartwatches, earbuds, fitness bands and trackers advertise over Bluetooth LE. The ESP32 can scan for those advertisements and list the names and signal strength (RSSI) of the strongest. This is a good way to learn how BLE advertising works, to find where a sensor you built is broadcasting, or to estimate how close a device is. Many phones randomise their address, so the list shows the device's advertised name rather than a fixed identity. Scanning only reads what devices broadcast openly.
Do not use scan results to track people.
Tick anything you already have and the total updates.
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB power bank for walking around.
ble_scan.inoVerify & upload in Electrolark#include <BLEDevice.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
BLEScan* scan;
void setup() {
Wire.begin(21, 22);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
oled.setTextColor(WHITE);
BLEDevice::init("");
scan = BLEDevice::getScan();
scan->setActiveScan(true);
scan->setInterval(100);
scan->setWindow(99);
}
void loop() {
oled.clearDisplay(); oled.setCursor(0, 0); oled.print("Scanning..."); oled.display();
BLEScanResults* found = scan->start(4, false); // scan for 4 seconds
int n = found->getCount();
// find the strongest four
int best[4] = {-1, -1, -1, -1};
for (int k = 0; k < 4; k++) {
int idx = -1, bestRssi = -200;
for (int i = 0; i < n; i++) {
bool used = false;
for (int j = 0; j < k; j++) if (best[j] == i) used = true;
int r = found->getDevice(i).getRSSI();
if (!used && r > bestRssi) { bestRssi = r; idx = i; }
}
best[k] = idx;
}
oled.clearDisplay();
oled.setCursor(0, 0); oled.printf("%d devices", n);
for (int k = 0; k < 4 && best[k] >= 0; k++) {
BLEAdvertisedDevice d = found->getDevice(best[k]);
String name = d.haveName() ? String(d.getName().c_str()) : String("(no name)");
if (name.length() > 11) name = name.substring(0, 11);
oled.setCursor(0, 14 + k * 12);
oled.printf("%s %d", name.c_str(), d.getRSSI());
}
oled.display();
scan->clearResults();
delay(2000);
}
In ESP32 core 3.x the scan() call returns a pointer, as used here; in core 2.x use BLEScanResults found = scan->start(4, false) and found.getCount().
Many devices do not advertise a name. That is normal.
Increase the scan time, and turn Bluetooth on for the devices you want to see.
No. It lists open advertisements only, and modern phones use changing addresses for privacy.
Received signal strength in dBm; closer to 0 is stronger.
Listening to open BLE advertisements is normal; do not try to connect to devices you do not own.
4 parts: ESP32-WROOM-32 38-Pin Development Board, 0.96" OLED Display 128x64, Solderless Breadboard and Dupont Jumper Wires (40 pcs). On this page you can tick the parts you already have and add only the rest to your cart.
It is a beginner project and takes about 1 hour. The build on this page has 6 steps.
No. This page has the complete, tested code (ble_scan.ino).
About ₹595 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Scanning for BLE advertisements; Reading names and RSSI; How signal strength relates to distance.
Do not use scan results to track people.
Ideas that reuse this build: ESP32 BLE temperature beacon. They are listed under Take it further on this page.
Warm, cool, rainbow or breathing: cycle lighting moods from your sofa.
Press to roll: the pips tumble and slow down before landing on a number.
Wait for the light, hit the button: how many milliseconds can you beat?
A bright 4-digit clock that keeps time through power cuts.
Learning project. Check every circuit and the datasheet of each part before you power it up.