Project Overview
BW16 (RTL8720DN) Dual-Band Wi-Fi Scanner: most maker boards only see 2.4 GHz. The BW16 is built on Realtek's RTL8720DN, which also scans the 5 GHz band. This sketch lists every access point around you with its band, channel, signal strength and security, then scores the channels and tells you the quietest one in each band, so you can move your router or your IoT devices off a crowded channel.
- Time: about 45 minutes
- Skill level: Beginner
- What you will build: A pocket dual-band Wi-Fi survey tool that refreshes every 10 seconds in the Serial Monitor, with signal bars, hidden-network detection and channel recommendations for 2.4 GHz and 5 GHz.
Parts List
From ShillehTek
- RTL8720DN BW16E dual-band Wi-Fi and BLE board (pre-soldered) - the RTL8720DN-based board used to scan both 2.4 GHz and 5 GHz networks.
External
- A USB-C data cable
- A computer with the Arduino IDE
Note: this scanner only listens. It reads the beacons that access points broadcast for everyone and never connects to, or interferes with, any network.
Step-by-Step Guide
Step 1 - Install the Realtek Ameba board package
Goal: Program the BW16 from the Arduino IDE.
What to do: In File > Preferences, add this URL to Additional Boards Manager URLs: https://github.com/ambiot/ambd_arduino/raw/master/Arduino_package/package_realtek.com_amebad_index.json. Open the Boards Manager, search for Realtek and install the Realtek Ameba Boards package. Then choose Tools > Board > Ameba ARM (32-bits) Boards > BW16(RTL8720DN) and the board's serial port.
Expected result: The BW16 appears in the board menu and the port shows up when you plug the board in.
Step 2 - Learn the upload procedure
Goal: Get code onto the board every time.
What to do: The RTL8720DN must be in download mode to accept a sketch. Boards with an auto-upload circuit can do this by themselves when you set Tools > Auto Upload Mode to Enable. If the IDE waits for the upload mode instead, do it by hand: hold BOOT, press and release EN, then release BOOT (Realtek's documentation calls these buttons Burn and RST). After uploading, press EN once to run the sketch.
Expected result: A test sketch uploads and runs after you press EN.
Step 3 - Upload the scanner
Goal: Scan both bands and report.
What to do: Upload this sketch and open the Serial Monitor at 115200 baud:
// BW16 (RTL8720DN) dual-band Wi-Fi scanner: every access point with band, channel, RSSI and security,
// plus a per-channel congestion score and the quietest channel suggestion for 2.4 GHz and 5 GHz.
// Board package: Realtek Ameba Boards (AmebaD); board: BW16(RTL8720DN).
#include <WiFi.h>
#include <wifi_conf.h>
#include <stdarg.h>
#define MAX_APS 64
#define SCAN_EVERY_MS 10000
struct AP {
char ssid[33];
uint8_t bssid[6];
int16_t rssi;
uint8_t channel;
uint32_t security;
};
static AP aps[MAX_APS];
static volatile int apCount = 0;
static volatile bool scanDone = false;
// Called by the Wi-Fi driver once per access point, then once more with scan_complete set
static rtw_result_t onScanResult(rtw_scan_handler_result_t* res) {
if (res->scan_complete != RTW_TRUE) {
rtw_scan_result_t* r = &res->ap_details;
if (apCount < MAX_APS) {
AP& a = aps[apCount];
int len = r->SSID.len > 32 ? 32 : r->SSID.len;
memcpy(a.ssid, r->SSID.val, len);
a.ssid[len] = 0;
memcpy(a.bssid, r->BSSID.octet, 6);
a.rssi = r->signal_strength;
a.channel = (uint8_t)r->channel;
a.security = (uint32_t)r->security;
apCount = apCount + 1;
}
} else {
scanDone = true;
}
return RTW_SUCCESS;
}
bool is5GHz(uint8_t ch) { return ch > 14; }
const char* securityName(uint32_t s) {
if (s == RTW_SECURITY_OPEN) return "open";
if (s == RTW_SECURITY_WEP_PSK) return "WEP";
if (s == RTW_SECURITY_WPA3_AES_PSK) return "WPA3";
if (s == RTW_SECURITY_WPA2_WPA3_MIXED) return "WPA2/3";
return "WPA/WPA2";
}
String bars(int16_t rssi) { // -90 dBm = 1 bar ... -40 dBm = 6 bars
int n = constrain((rssi + 100) / 10, 0, 6);
String s;
for (int i = 0; i < 6; i++) s += (i < n) ? '#' : '.';
return s;
}
int scan() {
apCount = 0;
scanDone = false;
if (wifi_scan_networks(onScanResult, NULL) != RTW_SUCCESS) return -1;
unsigned long t0 = millis();
while (!scanDone && millis() - t0 < 8000) delay(50); // a dual-band scan takes a few seconds
return apCount;
}
// Weight each AP by signal strength: a strong neighbour hurts more than a faint one
float weight(int16_t rssi) { return constrain((rssi + 95) / 10.0f, 0.1f, 6.0f); }
// Ameba's Serial has print/println; format text with snprintf and print floats with print(x, 1)
void serialf(const char* fmt, ...) {
char buf[160];
va_list args;
va_start(args, fmt);
vsnprintf(buf, sizeof buf, fmt, args);
va_end(args);
Serial.print(buf);
}
void report() {
int n = apCount;
serialf("\n%d access points\n", n);
Serial.println("band ch rssi signal security bssid ssid");
for (int i = 0; i < n; i++) {
const AP& a = aps[i];
serialf("%-7s %3u %4d %s %-8s %02X:%02X:%02X:%02X:%02X:%02X %s\n",
is5GHz(a.channel) ? "5 GHz" : "2.4 GHz", a.channel, a.rssi, bars(a.rssi).c_str(),
securityName(a.security), a.bssid[0], a.bssid[1], a.bssid[2], a.bssid[3],
a.bssid[4], a.bssid[5], a.ssid[0] ? a.ssid : "(hidden)");
}
// 2.4 GHz: a 20 MHz channel overlaps its neighbours up to 4 channels away, so score 1, 6 and 11
const uint8_t best24[] = {1, 6, 11};
float score24[3] = {0, 0, 0};
for (int i = 0; i < n; i++) {
if (is5GHz(aps[i].channel)) continue;
for (int k = 0; k < 3; k++) {
int d = abs((int)aps[i].channel - (int)best24[k]);
if (d <= 4) score24[k] += weight(aps[i].rssi) * (1.0f - d / 5.0f);
}
}
int k24 = 0;
for (int k = 1; k < 3; k++) if (score24[k] < score24[k24]) k24 = k;
Serial.print("2.4 GHz load:");
for (int k = 0; k < 3; k++) { serialf(" ch%u ", best24[k]); Serial.print(score24[k], 1); }
serialf(" -> quietest: channel %u\n", best24[k24]);
// 5 GHz: score each common 20 MHz channel (UNII-1 and UNII-3 need no radar checks)
const uint8_t ch5[] = {36, 40, 44, 48, 149, 153, 157, 161, 165};
float best = 1e9f; uint8_t bestCh = 36;
Serial.print("5 GHz load:");
for (uint8_t c : ch5) {
float s = 0;
for (int i = 0; i < n; i++) if (aps[i].channel == c) s += weight(aps[i].rssi);
serialf(" %u:", c); Serial.print(s, 1);
if (s < best) { best = s; bestCh = c; }
}
serialf(" -> quietest: channel %u\n", bestCh);
}
void setup() {
Serial.begin(115200);
if (WiFi.status() == WL_NO_SHIELD) { // also starts the Wi-Fi driver
Serial.println("Wi-Fi driver not available");
while (true) delay(1000);
}
Serial.println("BW16 dual-band scanner");
}
void loop() {
int n = scan();
if (n < 0) Serial.println("scan failed");
else report();
delay(SCAN_EVERY_MS);
}
The standard WiFi.scanNetworks() call does not report channels, so the sketch calls the Realtek driver's wifi_scan_networks() directly. The driver calls onScanResult() once for every access point it hears and once more when the scan is complete; the sketch copies the name, BSSID, RSSI, channel and security of each one. Channels 1 to 14 are 2.4 GHz and anything above 14 is 5 GHz.
Expected result: Every 10 seconds a fresh table prints, followed by a load score for each band.
Step 4 - Read the report
Goal: Understand each column and the recommendation.
What to do: Here is a typical report:
9 access points
band ch rssi signal security bssid ssid
2.4 GHz 6 -45 #####. WPA/WPA2 06:16:26:36:46:56 HomeNet
2.4 GHz 1 -70 ###... WPA/WPA2 01:11:21:31:41:51 Neighbor
2.4 GHz 11 -82 #..... open 0B:1B:2B:3B:4B:5B Cafe
2.4 GHz 3 -60 ####.. WPA2/3 03:13:23:33:43:53 Office-2G
5 GHz 36 -52 ####.. WPA/WPA2 24:34:44:54:64:74 HomeNet-5G
5 GHz 149 -75 ##.... WPA3 95:A5:B5:C5:D5:E5 Neighbor-5G
5 GHz 44 -88 #..... WPA/WPA2 2C:3C:4C:5C:6C:7C (hidden)
5 GHz 36 -66 ###... WPA/WPA2 24:34:44:54:64:74 Office-5G
2.4 GHz 14 -90 #..... open 0E:1E:2E:3E:4E:5E Ch14-JP
2.4 GHz load: ch1 4.6 ch6 6.4 ch11 1.5 -> quietest: channel 11
5 GHz load: 36:7.2 40:0.0 44:0.7 48:0.0 149:2.0 153:0.0 157:0.0 161:0.0 165:0.0 -> quietest: channel 40
Each # in the signal column is roughly 10 dB. Hidden networks show as (hidden). The load score weights every access point by its signal, so a strong neighbour counts more than a faint one. On 2.4 GHz a 20 MHz channel overlaps its neighbours up to four channels away, so the sketch only scores the non-overlapping channels 1, 6 and 11 and counts partial overlap. On 5 GHz the channels do not overlap at 20 MHz, so each one is scored on its own.
Expected result: You can see at a glance which channel each nearby network uses and which channel is the quietest.
Step 5 - Act on it
Goal: Improve your own Wi-Fi.
What to do: Set your router's 2.4 GHz radio to the recommended channel out of 1, 6 and 11. On 5 GHz the sketch looks at channels 36 to 48 and 149 to 165, which need no radar checks; check which channels your country allows before you change anything. Walk around with the board on a laptop or a power bank to find dead spots and the strongest access point in each room.
Expected result: Your network on a quieter channel, and a map of where coverage drops.
Conclusion
You turned the BW16 into a dual-band Wi-Fi scanner: the Realtek driver's scan callback reports every access point on 2.4 GHz and 5 GHz, and a simple weighted score points you to the quietest channel in each band.
Want the exact parts used in this build? Grab them from ShillehTek.com. If you want help customizing this project or building something for your product, check out our IoT consulting services.
Credits
This tutorial is based on Daphne on Hackster.io. The original Scan surrounding wifi hotspot project for Realtek Ameba boards by Daphne served as the reference for this ShillehTek version. The product photos are from the ShillehTek store. We thank them for their excellent work in the maker community.



