Projects / Node-RED dashboard for sensors

Node-RED dashboard for sensors

Beginner2 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. Pi 4RASPBERR

    Set up the Pi

    Raspberry Pi OS, updated.

  2. Pi 4

    Install Mosquitto

    Add a user and password.

  3. Pi 4

    Install Node-RED

    Add the dashboard nodes.

  4. Pi 4ESP32

    Flash the ESP32 sketch

    With your placeholders filled in.

  5. Pi 4

    Build the flow

    MQTT in, JSON, gauge, chart.

  6. Pi 4

    Open the dashboard

    In a browser on your network.

  7. Pi 4

    Add an alert

    For temperature over a limit.

In short

How do you build a node-RED dashboard for sensors?

Node-RED on a Pi collects MQTT readings from ESP32 sensors and shows gauges and charts in a browser. You need Raspberry Pi 4 Model B (4 GB), SanDisk microSD card 32 GB (A1, Class 10), Raspberry Pi 27 W USB-C power supply, ESP32 DevKit V1, DHT22 Sensor and Resistor 10 kΩ. It takes 7 steps and about 120 minutes.

Level
Beginner
Time
About 120 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
DHT22 dataESP32 GPIO 4, with 10 k to 3V3Sensor signal
DHT22 VCC and GNDESP32 3V3 and GNDPower
ESP32Your Wi-Fi, same network as the PiSends readings
Raspberry PiPower supply, SD card, networkRuns Mosquitto and Node-RED

Code

Node-RED is a visual tool: you drag boxes onto a canvas and wire them together, so a reading can go from an MQTT message to a gauge on a web page without writing a web app. On the Pi, install Mosquitto (the MQTT broker) and Node-RED, add the node-red-dashboard package from the palette manager, and set a Mosquitto user and password with the mosquitto_passwd tool so only your devices can connect. In the flow, an MQTT in node subscribes to home/lab/dht22, a JSON node turns the text into an object, and two function or change nodes pick out temp and hum for a gauge and a chart. A switch node that compares the temperature with a limit can send an alert. This build uses plain MQTT without encryption, which is acceptable on a home network you control, but do not expose the broker to the internet, and never use your Wi-Fi password anywhere except the placeholder line. Give the Pi a fixed address in the router so the ESP32 can always find it. Arduino IDE with the ESP32 boards package 2.0.x, board "ESP32 Dev Module".

Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

// ESP32 publishes temperature and humidity to MQTT every 10 seconds for Node-RED.
// Libraries: PubSubClient, DHT sensor library. Fill in the placeholders; never commit real values.
#include <WiFi.h>
#include <PubSubClient.h>
#include <DHT.h>
const char* WIFI_SSID = "YOUR_WIFI_NAME";
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD";
const char* MQTT_HOST = "YOUR_PI_IP_ADDRESS";   // for example the Pi's address on your home network
const char* MQTT_USER = "YOUR_MQTT_USER";
const char* MQTT_PASS = "YOUR_MQTT_PASSWORD";
DHT dht(4, DHT22);
WiFiClient net;
PubSubClient mqtt(net);
void connectAll() {
  if (WiFi.status() != WL_CONNECTED) {
    WiFi.begin(WIFI_SSID, WIFI_PASS);
    while (WiFi.status() != WL_CONNECTED) delay(500);
  }
  while (!mqtt.connected()) {
    if (!mqtt.connect("esp32-lab", MQTT_USER, MQTT_PASS)) delay(2000);
  }
}
void setup() {
  dht.begin();
  mqtt.setServer(MQTT_HOST, 1883);
}
void loop() {
  connectAll();
  mqtt.loop();
  float t = dht.readTemperature(), h = dht.readHumidity();
  if (!isnan(t) && !isnan(h)) {
    char buf[80];
    snprintf(buf, sizeof(buf), "{\"temp\":%.1f,\"hum\":%.1f}", t, h);
    mqtt.publish("home/lab/dht22", buf);
  }
  delay(10000);
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
ESP32 runningMessages appear in the debug panel
DashboardGauges move every 10 seconds
Warm the sensorTemperature rises and the alert fires
Restart the PiEverything reconnects

If it does not work

Nothing arrives

Check the broker address, user and password.

Dashboard blank

Open the dashboard tab and deploy the flow.

Readings are NaN

Check the pull-up resistor and the data pin.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the node-RED dashboard for sensors?

Raspberry Pi 4 Model B (4 GB), SanDisk microSD card 32 GB (A1, Class 10), Raspberry Pi 27 W USB-C power supply, ESP32 DevKit V1, DHT22 Sensor and Resistor 10 kΩ.

How long does the node-RED dashboard for sensors take to build?

About 120 minutes for a beginner maker, in 7 steps.

How do I know the node-RED dashboard for sensors works?

ESP32 running: Messages appear in the debug panel. Dashboard: Gauges move every 10 seconds. Warm the sensor: Temperature rises and the alert fires.

Nothing arrives: what should I check?

Check the broker address, user and password.

Dashboard blank: what should I check?

Open the dashboard tab and deploy the flow.

Readings are NaN: what should I check?

Check the pull-up resistor and the data pin.