E8-8ESP8266Beginner

ESP8266 Wi-Fi Signal Strength Bar: Find the Best Wi-Fi Spot at Home with a NodeMCU and 5 LEDs

See the signal strength of your router on a bar of five LEDs, like the Wi-Fi icon of a phone. The NodeMCU V3 joins your home Wi-Fi, measures the signal twice a second and lights one LED for every level reached: -90, -80, -70, -60 and -50 dBm. Run the board from a power bank and walk around the house: the more LEDs light up, the better the spot. The first LED blinks while the board is looking for the network. There is no web page. The ESP8266 only joins 2.4 GHz networks.

0.0(0)
ESP8266 Wi-Fi Signal Strength Bar: Find the Best Wi-Fi Spot at Home with a NodeMCU and 5 LEDs
Every project that goes online depends on signal; this one makes that signal visible. You learn to read how well the board hears the router as a number, to split that number into levels and to show it on an LED bar. You also see how smoothing jumpy readings keeps a display from flickering. The same method is behind every bar display, from battery level and loudness to temperature and fill level, and it helps you find the weak Wi-Fi corners of your home.

Video

Circuit Diagram

ESP8266 Wi-Fi Signal Strength Bar: Find the Best Wi-Fi Spot at Home with a NodeMCU and 5 LEDs - Circuit Diagram

Source Code

C++ (Arduino IDE)
1// ─────────────────────────────────────────
2//   BlueGrays · bluegrays.com
3//   ESP8266 Wi-Fi Signal Strength Bar: Find the Best Wi-Fi Spot at Home with a NodeMCU and 5 LEDs
4// ─────────────────────────────────────────
5// The NodeMCU joins your home Wi-Fi and shows the signal strength of the
6// router on a bar of five LEDs, like the Wi-Fi icon of a phone. Run the
7// board from a power bank and walk around the house: the more LEDs light
8// up, the better the spot. The first LED blinks while the board is still
9// looking for the network.
10//
11// Pins:
12//   D7 D6 D5 D2 D1 -> 220 ohm resistor -> anode of LED 1 to 5
13//   GND            -> cathodes of the five LEDs (minus rail)
14
15#include <ESP8266WiFi.h>
16
17// ============ WI-FI NETWORK ============
18// Write the name and password of your own network inside the quotes. The ESP8266 only joins 2.4 GHz
19// networks.
20const char *const WIFI_SSID = "YOUR_WIFI_NAME";
21const char *const WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";
22const unsigned long WIFI_HINT_MS = 20000; // Time until the hint (ms)
23
24// ============ PINS ============
25// The five LEDs of the bar from the first to the fifth. D3, D4 and D8 have a special job while the
26// board starts, so they are left out.
27const uint8_t BAR_PINS[] = {D7, D6, D5, D2, D1};
28const uint8_t BAR_COUNT = 5;
29
30// ============ SIGNAL LEVELS ============
31// Signal strength is measured in dBm and is a negative number: the closer to zero, the stronger.
32// Every level the signal reaches lights one more LED.
33const int LEVEL_DBM[] = {-90, -80, -70, -60, -50};
34const unsigned long MEASURE_MS = 500;     // ms
35
36float signalDbm = -100;                   // dBm
37unsigned long lastMeasure = 0;
38bool blinkOn = false;
39bool wifiUp = false;
40bool hintDone = false;
41
42// Lights the first LEDs of the bar and turns the rest off.
43void showBars(uint8_t count) {
44  for (uint8_t i = 0; i < BAR_COUNT; i++) {
45    digitalWrite(BAR_PINS[i], i < count ? HIGH : LOW);
46  }
47}
48
49// Runs twice a second without waiting. No connection: the first LED blinks. Connected: reads the
50// signal, smooths it so the bar does not flicker and lights one LED for every level reached.
51void measure() {
52  if (millis() - lastMeasure < MEASURE_MS) {
53    return;
54  }
55  lastMeasure = millis();
56  if (!wifiUp) {
57    blinkOn = !blinkOn;
58    showBars(blinkOn ? 1 : 0);
59    return;
60  }
61  int rssi = WiFi.RSSI();
62  // The new reading counts for 30 percent, the old average for 70 percent.
63  signalDbm = signalDbm * 0.7f + rssi * 0.3f;
64  int level = lround(signalDbm);
65  uint8_t bars = 0;
66  for (uint8_t i = 0; i < BAR_COUNT; i++) {
67    if (level >= LEVEL_DBM[i]) {
68      bars++;
69    }
70  }
71  showBars(bars);
72  Serial.print("Signal: ");
73  Serial.print(rssi);
74  Serial.print(" dBm  ");
75  Serial.print(bars);
76  Serial.println("/5");
77}
78
79// Watches the connection: reports when it is made and when it drops. The ESP8266 rejoins a lost
80// network by itself.
81void checkWifi() {
82  bool up = WiFi.status() == WL_CONNECTED;
83  if (up && !wifiUp) {
84    hintDone = true;
85    signalDbm = WiFi.RSSI();
86    Serial.println("Wi-Fi connected");
87  } else if (!up && wifiUp) {
88    Serial.println("Wi-Fi lost. Reconnecting");
89  }
90  wifiUp = up;
91
92  if (!up && !hintDone && millis() > WIFI_HINT_MS) {
93    hintDone = true;
94    Serial.println("Could not join the Wi-Fi");
95    Serial.println("Check the network name and password");
96    Serial.println("The ESP8266 only sees 2.4 GHz networks");
97  }
98}
99
100void setup() {
101  Serial.begin(115200);
102  for (uint8_t i = 0; i < BAR_COUNT; i++) {
103    pinMode(BAR_PINS[i], OUTPUT);
104  }
105  showBars(0);                            // Start with the LEDs off
106  Serial.println();
107  Serial.println("Wi-Fi signal bar");
108  if (strncmp(WIFI_SSID, "YOUR_", 5) == 0) {
109    Serial.println("Put your Wi-Fi name and password in the code");
110  }
111  Serial.println("Connecting to Wi-Fi");
112  // The board opens no network of its own, it joins yours
113  WiFi.mode(WIFI_STA);
114  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
115}
116
117// loop never waits: both jobs only look at the clock.
118void loop() {
119  checkWifi();
120  measure();
121}
122

FAQ

What is dBm and why is the number negative?

dBm is the unit of signal strength, and because the signal from a router is very weak the number is always negative. The closer to zero, the stronger: -50 is very good, -70 is fair and -85 is weak. Every drop of 10 dBm means a tenth of the power. The board reads the number with WiFi.RSSI; the code compares it with five levels and decides how many LEDs to light.

Why does the bar follow the signal a little late?

Because the code smooths the readings: each new reading counts for 30 percent and the old average for 70 percent. The raw signal moves a few dBm even when you stand still; without smoothing the last LED would keep blinking near a level. The price is a small delay: after you move, the bar settles in two or three seconds. Wait a few seconds when you measure a spot.

Why pins D1, D2, D5, D6 and D7?

Not every pin of the ESP8266 is spare. D3, D4 and D8 must sit at a certain level while the board starts, and an LED on them can keep the board from booting. D0 has limits of its own. That leaves five outputs without such limits: D1, D2, D5, D6 and D7. With a 220 Ω resistor each LED draws about 6 mA; even with all five on, the board stays within its limits.

What do I need to carry the board around the house?

Just a power bank and a micro USB cable. The code does not need a computer: once powered it joins the network by itself and starts showing the bar. Some power banks switch off when very little current is drawn; if yours does, try another model. With the Serial Monitor open you also see the dBm value of every reading.