Skip to content

Tutorial

ESP32 DHT11 + BMP280 Node-RED Dashboard over MQTT (Dashboard 2.0)

Show ESP32 DHT11 temperature/humidity and BMP280 pressure on a Node-RED Dashboard 2.0 page over MQTT: wiring, full sketch, function code, widgets and fixes.

  • 10 min read
  • Updated November 14, 2026
ESP32 DHT11 + BMP280 Node-RED Dashboard over MQTT (Dashboard 2.0)

Quick answer: wire a DHT11 to ESP32 GPIO4 and a BMP280 to I2C (SDA GPIO21, SCL GPIO22). Have the ESP32 publish one JSON message every 5 seconds to an MQTT topic such as solderhub/lab/esp32-01/telemetry. In Node-RED, use mqtt in → function (split into four values) → Dashboard 2.0 gauges and a chart, then open http://<node-red-host>:1880/dashboard. The full sketch, the function code and widget settings are below.

The two sensors do different jobs. The DHT11 gives temperature and humidity; the BMP280 gives air pressure and its own temperature, and it does not measure humidity (that's the BME280). This project shows all four values side by side, so you can see how the two temperature readings compare.

PartMeasuresRange / accuracy (datasheet)Interface
DHT11Temperature, humidity0–50 °C ±2 °C; 20–90 % RH ±5 %; 1 reading per second maxSingle-wire digital
BMP280Pressure, temperature300–1100 hPa ±1 hPa; temperature ±1 °CI2C (0x76 or 0x77) or SPI

Most tutorials still use the deprecated node-red-dashboard (the old /ui page). This one uses Dashboard 2.0 (@flowfuse/node-red-dashboard), the maintained replacement.

Parts and wiring

ESP32 pinDHT11 moduleBMP280 breakout
3V3VCC (+)VIN / VCC
GNDGND (−)GND
GPIO4DATA (OUT)–
GPIO21 (SDA)–SDA
GPIO22 (SCL)–SCL

Notes that save debugging time:

  • A bare 4-pin DHT11 needs a 10 kΩ pull-up resistor from DATA to 3V3; the common 3-pin modules already have one.
  • Power the BMP280 from 3V3. Some breakouts have a regulator and accept 5 V, but many purple 6-pin boards don't. If yours has SDO, tie it to GND for address 0x76 or to 3V3 for 0x77, and leave CSB high (or unconnected on most boards) for I2C mode.
  • Cheap boards sold as "BME280" are often BMP280s (no humidity). See BME280 vs BMP280 for how to tell them apart.

Arduino libraries (Library Manager): DHT sensor library for ESPx (DHTesp) by beegee-tokyo, Adafruit BMP280 Library (and Adafruit Unified Sensor if asked), and PubSubClient by Nick O'Leary.

1. Upload the ESP32 firmware

Replace the Wi-Fi, broker and MQTT user placeholders. The broker address must be the LAN IP of the machine running Mosquitto; 127.0.0.1 would point at the ESP32 itself. The sketch publishes every 5 seconds (well within the DHT11's one-reading-per-second limit), skips a sample rather than sending fake zeros if a sensor fails, and uses MQTT Last Will so Node-RED can show when the board goes offline.

sketch.ino
#include <WiFi.h>
#include <Wire.h>
#include <PubSubClient.h>
#include <DHTesp.h>
#include <Adafruit_BMP280.h>

const char* WIFI_SSID     = "REPLACE_WITH_WIFI";
const char* WIFI_PASSWORD = "REPLACE_WITH_PASSWORD";
const char* MQTT_HOST     = "192.168.1.50";      // broker's LAN IP
const char* MQTT_USER     = "esp32-01";          // "" if the broker allows anonymous
const char* MQTT_PASS     = "REPLACE_WITH_MQTT_PASSWORD";
const char* TOPIC_DATA    = "solderhub/lab/esp32-01/telemetry";
const char* TOPIC_STATUS  = "solderhub/lab/esp32-01/status";

const int DHT_PIN = 4;
const unsigned long SAMPLE_MS = 5000;

WiFiClient net;
PubSubClient mqtt(net);
DHTesp dht;
Adafruit_BMP280 bmp;
bool bmpReady = false;
unsigned long lastSample = 0, lastAttempt = 0;

void connectMqtt() {
  if (millis() - lastAttempt < 3000) return;
  lastAttempt = millis();
  if (mqtt.connect("solderhub-esp32-01", MQTT_USER, MQTT_PASS, TOPIC_STATUS, 1, true, "offline")) {
    mqtt.publish(TOPIC_STATUS, "online", true);
    Serial.println("MQTT connected");
  } else {
    Serial.printf("MQTT failed, rc=%d\n", mqtt.state());
  }
}

void setup() {
  Serial.begin(115200);
  dht.setup(DHT_PIN, DHTesp::DHT11);
  Wire.begin(21, 22);
  bmpReady = bmp.begin(0x76) || bmp.begin(0x77);
  if (!bmpReady) Serial.println("BMP280 not found: check wiring and address");

  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  mqtt.setServer(MQTT_HOST, 1883);
}

void loop() {
  if (WiFi.status() != WL_CONNECTED) return;
  if (!mqtt.connected()) { connectMqtt(); return; }
  mqtt.loop();

  if (millis() - lastSample < SAMPLE_MS) return;
  lastSample = millis();

  TempAndHumidity th = dht.getTempAndHumidity();
  float bmpT = bmpReady ? bmp.readTemperature() : NAN;
  float hPa  = bmpReady ? bmp.readPressure() / 100.0F : NAN;

  if (isnan(th.temperature) || isnan(th.humidity) || isnan(bmpT) || isnan(hPa)) {
    Serial.println("Sensor read failed, sample skipped");
    return;
  }

  char json[200];
  snprintf(json, sizeof(json),
    "{\"t_dht\":%.0f,\"rh\":%.0f,\"t_bmp\":%.1f,\"hpa\":%.1f,\"up\":%lu}",
    th.temperature, th.humidity, bmpT, hPa, millis() / 1000UL);
  mqtt.publish(TOPIC_DATA, json);
  Serial.println(json);
}

Open the Serial Monitor at 115200 baud. You should see MQTT connected and then a line like {"t_dht":24,"rh":51,"t_bmp":24.6,"hpa":1008.3,"up":35} every 5 seconds.

DHT11 values are printed as whole numbers on purpose: the sensor reports in 1 °C and 1 % steps, so decimals would suggest precision it doesn't have. Before building the flow, check the messages arrive at the broker:

terminal
mosquitto_sub -h 192.168.1.50 -u nodered -P 'YOUR_PASSWORD' -t 'solderhub/lab/esp32-01/#' -v

Pressure reads lower than your weather app? The BMP280 measures station pressure. Weather services report pressure corrected to sea level, which at 300 m altitude is about 35 hPa higher. Convert with P_sea = P / pow(1 - altitude_m / 44330.0, 5.255).

How the data flows

  1. The ESP32 reads both sensors every 5 seconds and publishes a single JSON message.
  2. Mosquitto passes it to every subscriber, including Node-RED.
  3. The function node checks every value is a real number in a plausible range, then splits the message into one message per widget.
  4. Dashboard 2.0 pushes the new values to every open browser over a WebSocket, so the page updates without refreshing.

One JSON message per sample (rather than one topic per value) keeps the readings from the same moment together and halves the number of MQTT messages. When you later log to a database, the whole sample can be written as one point.

2. Build the Node-RED flow

  1. Install @flowfuse/node-red-dashboard from Manage palette (setup details: Node-RED Dashboard 2.0 guide).
  2. Add an mqtt in node: your broker, topic solderhub/lab/esp32-01/telemetry, output a parsed JSON object.
  3. Add a function node named split readings. On its Setup tab set Outputs: 5, then paste:
script.js
const d = msg.payload;
const ok = (v, lo, hi) => typeof v === "number" && Number.isFinite(v) && v >= lo && v <= hi;
if (!d || !ok(d.t_dht, 0, 60) || !ok(d.rh, 0, 100) || !ok(d.t_bmp, -40, 85) || !ok(d.hpa, 300, 1100)) {
  node.warn("Rejected: " + JSON.stringify(d));
  return null;
}
const stamp = new Date().toLocaleTimeString();
node.status({ fill: "green", shape: "dot", text: "updated " + stamp });
return [
  { payload: d.t_dht, topic: "DHT11 °C" },
  { payload: d.rh,    topic: "Humidity %" },
  { payload: d.hpa,   topic: "Pressure hPa" },
  { payload: d.t_bmp, topic: "BMP280 °C" },
  { payload: "Last update: " + stamp }
];
  1. Add a second mqtt in node on solderhub/lab/esp32-01/status wired to a ui-text widget, so the dashboard says online or offline (the Last Will from the sketch).
Function outputWidgetSettings
1: DHT11 temperatureui-gauge0–50, unit °C
2: Humidityui-gauge0–100, unit %
3: Pressureui-gauge950–1050, unit hPa
1 and 4: both temperaturesui-chart (line)Series by msg.topic, x-axis time, keep 1 hour
5: last updateui-textLabel "Status"

3. Open and arrange the dashboard

Deploy, then open http://<node-red-host>:1880/dashboard. Put the three gauges in one group and the chart full-width underneath; Dashboard 2.0 lays groups out responsively, so the same page works on a phone.

A few touches make it trustworthy:

  • Show the update time. If the ESP32 stops publishing, the gauges keep their last value; the "Last update" text and online/offline status tell you whether the numbers are live.
  • Label the source, for example "DHT11 °C" and "BMP280 °C". The two temperatures commonly differ by 1–2 °C: the DHT11 is only ±2 °C, and the BMP280 warms slightly from its own circuitry.
  • Keep chart history short (an hour or a day). For weeks of history, log to a database instead: see Node-RED, InfluxDB and Grafana.

Troubleshooting

SymptomLikely causeFix
Serial: BMP280 not foundWrong address, wiring, or it's a different chipRun an I2C scanner; try 0x76/0x77; check SDA=21, SCL=22
BMP280 found but pressure is 0 or nonsenseIt's actually a BME280 or the wrong libraryBME280 chip ID is 0x60, BMP280 is 0x58; use the matching library
Sensor read failed every timeDHT11 on the wrong pin, no pull-up on a bare sensor, or read too oftenCheck GPIO4 and the 10 kΩ pull-up; don't read faster than once a second
MQTT failed, rc=-2Broker unreachable (wrong IP, firewall, Mosquitto listening on localhost only)See MQTT troubleshooting
rc=5Wrong MQTT user/passwordFix credentials, or create the user with mosquitto_passwd
Debug shows a string, function rejects everythingmqtt in output set to auto/stringSet output to a parsed JSON object
Dashboard page 404 at /uiThat's the old dashboard's addressDashboard 2.0 lives at /dashboard
Gauges stuck on old valuesESP32 offline; Last Will shows "offline"Check power and Wi-Fi; look at the status widget
Pressure ~30–100 hPa below the weather reportStation vs sea-level pressureApply the altitude correction above

FAQ

Can I use a DHT22 instead of a DHT11? Yes, and it's more accurate (about ±0.5 °C, ±2–5 % RH) with a wider range. Change DHTesp::DHT11 to DHTesp::DHT22 and print one decimal place.

Why use a BMP280 and a DHT11 instead of one BME280? A BME280 alone gives temperature, humidity and pressure, which is simpler and more accurate. This project uses the two cheap sensors many starter kits include; the flow works the same with a BME280.

Do I need a Raspberry Pi? No. Mosquitto and Node-RED run on any always-on computer, including Windows (install Node-RED on Windows).

Can I add more ESP32 boards? Yes. Give each a unique client ID and topic (esp32-02…), subscribe to solderhub/lab/+/telemetry, and use msg.topic in the function to tell them apart.

Check sensor plausibility before displaying it

A dashboard should make bad readings visible rather than turning them into convincing-looking gauges. The DHT11 and BMP280 have different measurement ranges, accuracy limits and failure modes. Validate each sensor independently before publishing the combined JSON message. If one sensor read fails, do not reuse an old value without marking it stale; publish a status field or omit the failed measurement and show a clear unavailable state in Node-RED.

For a DHT11, expect coarse resolution and relatively slow response. It is not a precision instrument, and readings can be affected by self-heating, airflow and placement. A BMP280 measures pressure and temperature; its temperature reading is primarily useful for compensating the pressure sensor and may differ from room temperature when the breakout is close to a warm microcontroller. Avoid presenting either sensor as calibrated without a reference comparison.

Useful dashboard checks include:

  • Display the unit next to every number: °C, %RH and hPa.
  • Show the last update time and an offline/stale indicator.
  • Keep a sensible number of decimal places; extra digits do not create extra accuracy.
  • Use a fixed gauge range appropriate to the application, and show out-of-range values as an error rather than clipping them silently.
  • Plot a time series so sudden jumps, flat lines and missing updates are easy to spot.

Verify the complete data path

Test the system in stages. First publish a known JSON payload from a computer to the broker and confirm that Node-RED parses it. Next disconnect the ESP32 and verify that the dashboard eventually indicates stale data. Reconnect it and confirm that the timestamp advances. Then simulate an invalid payload and ensure the validation branch prevents it from reaching the gauge or database.

Keep the broker, Node-RED editor and dashboard on a trusted network. Use unique MQTT credentials, limit topic permissions and protect the Node-RED editor with authentication. If the dashboard is accessible beyond the LAN, configure HTTPS and access control; a hidden URL is not authentication. Also remember that a dashboard chart's retained history depends on the nodes and storage configured in the flow. A chart widget alone is not a durable database, so use a time-series store if readings must survive restarts or be analysed later.

Continue learning

Related articles

All articles

Signal In

Built from what makers search for

The lookups piling up in SolderHub's search bar every day shape what we publish next — new component pages, board guides, and firmware notes, sent out as they go live.

By subscribing you agree to our Privacy Policy. Unsubscribe anytime.