Bluetooth LE scanner
List nearby Bluetooth LE devices with their signal strength every ten seconds: phones, watches, beacons and sensors.
Wiring
Nothing to wire. This one runs on the bare board.
Tested on this board
Not run on this board yet. Treat the wiring and code as a first draft.
Firmware, Arduino sketch for ESP32 Dev Module
#include <BLEDevice.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
BLEScan* scan;
void setup() {
Serial.begin(115200);
BLEDevice::init("");
scan = BLEDevice::getScan();
scan->setActiveScan(true); // ask devices for their names
scan->setInterval(100);
scan->setWindow(99);
}
void loop() {
BLEScanResults* found = scan->start(5, false); // scan for five seconds
int n = found->getCount();
Serial.printf("%d devices\n", n);
for (int i = 0; i < n; i++) {
BLEAdvertisedDevice d = found->getDevice(i);
Serial.printf("%s %4d dBm %s\n", d.getAddress().toString().c_str(), d.getRSSI(),
d.haveName() ? d.getName().c_str() : "(no name)");
}
scan->clearResults();
delay(5000);
}Wiring
Nothing to wire. This one runs on the bare board.
Tested on this board
Not run on this board yet. Treat the wiring and code as a first draft.
Firmware, Arduino sketch for ESP32S3 Dev Module
#include <BLEDevice.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
BLEScan* scan;
void setup() {
Serial.begin(115200);
BLEDevice::init("");
scan = BLEDevice::getScan();
scan->setActiveScan(true); // ask devices for their names
scan->setInterval(100);
scan->setWindow(99);
}
void loop() {
BLEScanResults* found = scan->start(5, false); // scan for five seconds
int n = found->getCount();
Serial.printf("%d devices\n", n);
for (int i = 0; i < n; i++) {
BLEAdvertisedDevice d = found->getDevice(i);
Serial.printf("%s %4d dBm %s\n", d.getAddress().toString().c_str(), d.getRSSI(),
d.haveName() ? d.getName().c_str() : "(no name)");
}
scan->clearResults();
delay(5000);
}Wiring
Nothing to wire. This one runs on the bare board.
Tested on this board
Not run on this board yet. Treat the wiring and code as a first draft.
Firmware, Arduino sketch for ESP32C3 Dev Module
#include <BLEDevice.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
BLEScan* scan;
void setup() {
Serial.begin(115200);
BLEDevice::init("");
scan = BLEDevice::getScan();
scan->setActiveScan(true); // ask devices for their names
scan->setInterval(100);
scan->setWindow(99);
}
void loop() {
BLEScanResults* found = scan->start(5, false); // scan for five seconds
int n = found->getCount();
Serial.printf("%d devices\n", n);
for (int i = 0; i < n; i++) {
BLEAdvertisedDevice d = found->getDevice(i);
Serial.printf("%s %4d dBm %s\n", d.getAddress().toString().c_str(), d.getRSSI(),
d.haveName() ? d.getName().c_str() : "(no name)");
}
scan->clearResults();
delay(5000);
}Parts
| Quantity | Part | Where to buy |
|---|---|---|
| 1× | ESP32 dev board | Buy at Amazon |
Amazon buy links may include an Associates tag, and this site may earn a commission from qualifying Amazon purchases at no extra cost to you. Adafruit links are direct.
Libraries
BLE (built in)
Load it
- In the Arduino IDE, install the esp32 board package and pick the board named above the sketch.
- Paste the sketch, choose the board's port and upload. Hold BOOT if the upload stalls at Connecting.
- Close the IDE's serial monitor, then open the bench here to watch the output.
Field notes
- Written for the 3.x Arduino core, where start() returns a pointer. On the older 2.x core, use BLEScanResults found = scan->start(5, false) and found.getCount() instead.
- The Bluetooth stack is large. If the classic ESP32 build says the sketch is too big, pick Tools, Partition Scheme, Huge APP.
- Phones and watches change their address every few minutes for privacy, so the same phone can appear more than once.
- The S3 and C3 only have Bluetooth LE. The classic ESP32 also has Classic Bluetooth, which this sketch does not scan.
Not tested yet
- Not tested on hardware yet. Compiles for every board listed with Arduino-ESP32 core 3.3.12.