Back to Advanced Projects

☁️ MQTT IoT Sensor Dashboard

Publish live sensor data over MQTT and visualise it in a cloud dashboard.

📋 Overview

MQTT (Message Queuing Telemetry Transport) is the dominant IoT protocol — lightweight, low-bandwidth, and pub/sub based. This project connects an ESP32 sensor node to an MQTT broker (either a free cloud broker like HiveMQ or a local Mosquitto instance), where Node-RED subscribes and renders a live dashboard.

What you'll learn: MQTT pub/sub topology, QoS levels, topic namespacing, JSON payload formatting, connecting to public/private brokers with TLS, and building Node-RED flows with gauge and chart widgets.

Estimated time: 2–3 hours. Difficulty: ⭐⭐⭐ Intermediate.

🧩 Components Needed

ComponentSpecificationQtyNotes
ESP32 Development BoardWiFi1Publisher node
DHT22 SensorDigital, 1-Wire1Temp + humidity source
BMP180 SensorI2C barometric1Pressure + altitude
PC or Raspberry PiNode-RED + Mosquitto1MQTT broker + dashboard

📖 Step-by-Step Tutorial

1

Install Mosquitto Broker

On a PC or Pi, install Mosquitto: sudo apt install mosquitto mosquitto-clients. Start with sudo systemctl start mosquitto.
2

Install Node-RED

Install Node-RED globally: npm install -g --unsafe-perm node-red. Add the node-red-dashboard palette for GUI widgets.
3

Wire Sensors to ESP32

DHT22 DATA → GPIO 4. BMP180 SDA → GPIO 21, SCL → GPIO 22. Both share the 3.3V rail.
4

Install PubSubClient Library

Install PubSubClient by Nick O'Leary. It implements MQTT client for Arduino-based platforms.
5

Build Node-RED Flow

Create MQTT-in nodes subscribed to voltx/sensors/temperature and voltx/sensors/pressure. Connect to gauge and chart widgets on the dashboard tab.
💡
Use JSON payloads ({"value": 23.5, "unit": "C"}) instead of plain numbers. This makes your MQTT topics self-describing and much easier to parse in Node-RED, Grafana, or any future subscriber.

💻 Code / Configuration

mqtt_dashboard.ino
INO
// MQTT IoT Dashboard - Volt X
#include <WiFi.h>
#include <PubSubClient.h>
#include <DHT.h>
#include <ArduinoJson.h>

const char* ssid       = "YOUR_WIFI_SSID";
const char* password   = "YOUR_WIFI_PASSWORD";
const char* mqttServer = "broker.hivemq.com"; // Free public broker
const int   mqttPort   = 1883;
const char* clientId   = "voltx-esp32-node";

#define DHT_PIN  4
#define DHT_TYPE DHT22

DHT dht(DHT_PIN, DHT_TYPE);
WiFiClient espClient;
PubSubClient mqtt(espClient);

void connectMQTT() {
  while (!mqtt.connected()) {
    Serial.print("Connecting MQTT...");
    if (mqtt.connect(clientId)) {
      Serial.println("connected");
      mqtt.subscribe("voltx/commands"); // Listen for remote commands

Reviews & Ratings

0 reviews
5★
0
4★
0
3★
0
2★
0
1★
0
...

Loading reviews...