Production Monitoring Dashboard and Alarms
Connect the machine monitor to Adafruit IO, a free cloud IoT platform, and build a dashboard with gauges, a temperature chart, a status display with three alarm levels and a remote fan switch.
- Duration
- 90 minutes
- IoT layer
- Platform and application layer: cloud dashboard
- Libraries
DHT sensor library for ESPxPubSubClient- Internet connection required
- Internet connection required
What you will learn
- Explain the role of an IoT platform and of dashboards in production monitoring
- Create data feeds and dashboard blocks on a cloud IoT platform
- Connect the ESP32 to the platform with authenticated MQTT
- Implement graded alarm levels with automatic protection and manual override
- Respect a platform’s data limits and keep access keys private
Open in Wokwi
No installation, no hardware. Open a new ESP32 project in the free Wokwi simulator, then:
- Paste sketch.ino into the sketch.ino tab and replace the whole content of the diagram.json tab with our diagram.json.
- Add the libraries: open the Library Manager tab and add each library from libraries.txt (or create a libraries.txt file and paste the list).
- Press the green Start button and watch the Serial Monitor.
Wiring
The same circuit is used in all three exercises. The diagram.json file below builds it in Wokwi for you.
| Component (Wokwi part) | Component pin | ESP32 pin | Role in the scenario |
|---|---|---|---|
| DHT22 temperature/humidity sensor | VCC / SDA / GND | 3V3 / GPIO 15 / GND | Motor temperature |
| Potentiometer | VCC / SIG / GND | 3V3 / GPIO 34 / GND | Machine vibration level (0–100 %) |
| Red LED + 220 Ω resistor | Anode (via resistor) / Cathode | GPIO 2 / GND | Alarm lamp |
| Relay module | VCC / IN / GND | 5V / GPIO 5 / GND | Cooling fan switch |
Step by Step
Operators and maintenance technicians need to see the condition of every machine at a glance and act before a failure happens. In this exercise your machine monitor gets a real control-room screen:
- the ESP32 sends temperature, vibration and a status to Adafruit IO, a free cloud IoT platform,
- a dashboard shows gauges, a temperature history chart, the status and a fan switch,
- the device calculates three alarm levels — OK, WARNING, ALARM — protects the machine automatically and still accepts manual commands.
This covers the platform and application layers of IoT — the last step from sensor to decision.
Create the feeds and the dashboard on Adafruit IO
Create a free account at io.adafruit.com (or use the class account your teacher prepared). The free plan allows 30 data points per minute, 10 feeds and 5 dashboards — enough for this exercise.
- Open Feeds and create four feeds:
temperature,vibration,status,fan. - Open Dashboards, create a new dashboard (for example “Line 1”) and add these blocks:
| Dashboard block | Feed | Settings |
|---|---|---|
| Gauge | temperature | Min 0, max 60, label “Motor temperature °C” |
| Line chart | temperature | History 1 hour |
| Gauge | vibration | Min 0, max 100, label “Vibration %” |
| Text | status | Shows OK / WARNING / ALARM |
| Toggle | fan | On text “ON”, off text “OFF” |
- Click the key icon (“My Key”) and note your username and your Active Key.
Prepare the Wokwi project
Use the same circuit again (copy your earlier project or paste our diagram.json), paste the new sketch.ino and make sure DHT sensor library for ESPx and PubSubClient are installed.
Enter your own account data:
const char* AIO_USERNAME = "your_username";
const char* AIO_KEY = "your_aio_key";Understand the code
Feeds are MQTT topics. On Adafruit IO every feed has the topic username/feeds/feed-key:
String base = String(AIO_USERNAME) + "/feeds/";
feedTemp = base + "temperature";Authenticated connection. Unlike the public broker in Exercise 2, Adafruit IO only accepts a connection with your username and key:
mqtt.connect("smartvet-esp32", AIO_USERNAME, AIO_KEY)Graded alarm levels. The status starts as OK and is raised step by step:
String status = "OK";
if (data.temperature > TEMP_WARNING) status = "WARNING"; // above 30 °C
if (data.temperature > TEMP_ALARM || vibration > VIB_ALARM) status = "ALARM"; // above 35 °C or 70 %Protection plus override. The fan runs if the operator switched it on or the motor is in danger — the automatic protection cannot be switched off from the dashboard:
bool fanOn = manualFan || data.temperature > TEMP_ALARM;Data limits. The program publishes every 10 seconds: 3 values × 6 per minute = 18 data points per minute, safely below the free limit of 30.
Run and test
Start the simulation and keep the dashboard open next to Wokwi. The dashboard updates every 10 seconds, so be patient after each change.
| Test | Temperature | Vibration | Expected status | Expected fan |
|---|---|---|---|---|
| Normal | 24 °C | 20 % | OK | OFF |
| Warm motor | 32 °C | 20 % | WARNING | OFF |
| Hot motor | 38 °C | 20 % | ALARM | ON (automatic) |
| High vibration | 24 °C | 85 % | ALARM | OFF |
| Manual override | 24 °C | 20 % | OK | ON — after you switch the toggle ON |
Watch the gauges move, the line chart draw the temperature history and the status text change. Switch the fan from the dashboard and check the Serial Monitor: Dashboard command: fan ON.
Challenge tasks
- Remote limit: add a fifth feed
templimitand a slider block, so that the alarm limit can be changed from the dashboard. Subscribe to it in the same way as the fan feed. - Read the trend: use the line chart to describe the temperature over 10 minutes. When would you plan maintenance?
- Optional: create an Adafruit IO Action that sends an e-mail when the status feed equals
ALARM. - Present: show your dashboard to another pair as if they were the maintenance team. What do they need to know in 30 seconds?
Find the bug
Run each faulty line, read the Serial Monitor and the Monitor page on Adafruit IO, explain the cause and correct it.
Fault 1
if (millis() - lastPublish >= 1000) {Fault 2
const char* AIO_KEY = "wrong_key";Show the explanation (try first!)
- Fault 1: publishing every second sends 3 × 60 = 180 data points per minute — six times the free limit. Adafruit IO throttles the account and drops data; the dashboard freezes.
- Fault 2: with a wrong key the platform refuses the connection. The Serial Monitor repeats
failed, state=5, which means “not authorised”.
Reflect
- How does a dashboard change the work of operators and maintenance technicians?
- What is the difference between reacting to an alarm and predicting a failure? Which data would you need for predictive maintenance?
- What risks arise if an access key is published on the internet?
You have now built a complete IoT system for smart production — device, connectivity, platform and application. Next comes the Module 2 Mini Competition, where you design your own solution.
Code
/*
SmartVET – Module 2 – Exercise 3
Production monitoring dashboard and alarms with Adafruit IO (free account)
Board: ESP32 DevKit (Wokwi simulator or real board)
Libraries: "DHT sensor library for ESPx" (DHTesp), "PubSubClient"
License: CC BY-NC-SA 4.0 – SmartVET Erasmus+ project 2025-1-PL01-KA210-VET-000351305
*/
#include <WiFi.h>
#include <PubSubClient.h>
#include "DHTesp.h"
const char* WIFI_SSID = "Wokwi-GUEST";
const char* WIFI_PASS = "";
// ---- Adafruit IO account (io.adafruit.com → "My Key") – keep the key private ----
const char* AIO_SERVER = "io.adafruit.com";
const int AIO_PORT = 1883;
const char* AIO_USERNAME = "your_username";
const char* AIO_KEY = "your_aio_key";
const int DHT_PIN = 15, POT_PIN = 34, LED_ALARM = 2, RELAY_FAN = 5;
// ---- alarm thresholds ----
const float TEMP_WARNING = 30.0, TEMP_ALARM = 35.0;
const int VIB_ALARM = 70;
DHTesp dht;
WiFiClient wifiClient;
PubSubClient mqtt(wifiClient);
String feedTemp, feedVib, feedStatus, feedFan;
bool manualFan = false; // set from the dashboard toggle
unsigned long lastPublish = 0;
void onMessage(char* topic, byte* payload, unsigned int length) {
String msg;
for (unsigned int i = 0; i < length; i++) msg += (char)payload[i];
if (String(topic) == feedFan) manualFan = (msg == "ON");
Serial.printf("Dashboard command: fan %s\n", msg.c_str());
}
void connectMQTT() {
while (!mqtt.connected()) {
Serial.print("Connecting to Adafruit IO... ");
if (mqtt.connect("smartvet-esp32", AIO_USERNAME, AIO_KEY)) {
Serial.println("connected");
mqtt.subscribe(feedFan.c_str());
} else {
Serial.printf("failed, state=%d – retrying in 5 s\n", mqtt.state()); // 5 = wrong username or key
delay(5000);
}
}
}
void setup() {
Serial.begin(115200);
dht.setup(DHT_PIN, DHTesp::DHT22);
pinMode(LED_ALARM, OUTPUT);
pinMode(RELAY_FAN, OUTPUT);
String base = String(AIO_USERNAME) + "/feeds/";
feedTemp = base + "temperature";
feedVib = base + "vibration";
feedStatus = base + "status";
feedFan = base + "fan";
WiFi.begin(WIFI_SSID, WIFI_PASS, 6);
while (WiFi.status() != WL_CONNECTED) delay(250);
mqtt.setServer(AIO_SERVER, AIO_PORT);
mqtt.setCallback(onMessage);
}
void loop() {
if (!mqtt.connected()) connectMQTT();
mqtt.loop();
if (millis() - lastPublish >= 10000) { // every 10 s: 3 values = 18 data points per minute (free limit: 30)
lastPublish = millis();
TempAndHumidity data = dht.getTempAndHumidity();
int vibration = map(analogRead(POT_PIN), 0, 4095, 0, 100);
String status = "OK";
if (data.temperature > TEMP_WARNING) status = "WARNING";
if (data.temperature > TEMP_ALARM || vibration > VIB_ALARM) status = "ALARM";
bool fanOn = manualFan || data.temperature > TEMP_ALARM; // automatic protection + manual override
digitalWrite(RELAY_FAN, fanOn ? HIGH : LOW);
digitalWrite(LED_ALARM, status == "ALARM" ? HIGH : LOW);
mqtt.publish(feedTemp.c_str(), String(data.temperature, 1).c_str());
mqtt.publish(feedVib.c_str(), String(vibration).c_str());
mqtt.publish(feedStatus.c_str(), status.c_str());
Serial.printf("%.1f C | vibration %d %% | %s | fan %s\n",
data.temperature, vibration, status.c_str(), fanOn ? "ON" : "OFF");
}
}{
"version": 1,
"author": "SmartVET – Bilnet Schools Balıkesir",
"editor": "wokwi",
"parts": [
{"type": "board-esp32-devkit-c-v4", "id": "esp", "top": 0, "left": 0, "attrs": {}},
{"type": "wokwi-dht22", "id": "dht1", "top": -96, "left": 196, "attrs": {"temperature": "24", "humidity": "40"}},
{"type": "wokwi-potentiometer", "id": "pot1", "top": 40, "left": -170, "attrs": {}},
{"type": "wokwi-resistor", "id": "r1", "top": 150, "left": 190, "attrs": {"value": "220"}},
{"type": "wokwi-led", "id": "led1", "top": 100, "left": 300, "attrs": {"color": "red"}},
{"type": "wokwi-relay-module", "id": "relay1", "top": 230, "left": 190, "attrs": {}}
],
"connections": [
["esp:TX", "$serialMonitor:RX", "", []],
["esp:RX", "$serialMonitor:TX", "", []],
["dht1:VCC", "esp:3V3", "red", []],
["dht1:SDA", "esp:15", "green", []],
["dht1:GND", "esp:GND.2", "black", []],
["pot1:VCC", "esp:3V3", "red", []],
["pot1:SIG", "esp:34", "blue", []],
["pot1:GND", "esp:GND.1", "black", []],
["esp:2", "r1:1", "orange", []],
["r1:2", "led1:A", "orange", []],
["led1:C", "esp:GND.2", "black", []],
["relay1:VCC", "esp:5V", "red", []],
["relay1:IN", "esp:5", "violet", []],
["relay1:GND", "esp:GND.3", "black", []]
],
"dependencies": {}
}DHT sensor library for ESPx
PubSubClientThis code has not yet been verified in Wokwi or on real hardware. Please report any problems.
Troubleshooting
The Serial Monitor shows “failed, state=5 – retrying in 5 s”.
State 5 means “not authorised”: the username or the key is wrong. Copy both again from the key icon (“My Key”) on io.adafruit.com. The username is case-sensitive. If you generated a new key, the old one no longer works. (State 4, bad username/password, has the same cause.)
Values arrive for a while, then the dashboard stops updating.
You probably exceeded the free limit of 30 data points per minute — for example by publishing every second. Adafruit IO then throttles your account and drops data for a while. Publish every 10 seconds (3 values = 18 per minute) and wait a minute. The “Monitor” page on io.adafruit.com shows these errors.
The ESP32 publishes, but a feed on the dashboard stays empty.
The topic uses the feed key, not the feed name: username/feeds/temperature. If you named a feed “Motor Temp”, its key is “motor-temp”. Open the feed on io.adafruit.com, check its key and use exactly that key in the program.
The fan toggle on the dashboard does nothing.
The toggle block must be connected to the feed “fan” and send exactly ON and OFF (check “Button On Text” and “Button Off Text” in the block settings). Also check that the Serial Monitor printed “connected” — the ESP32 subscribes to the fan feed only after a successful connection.
The status gauge shows nothing.
The status feed contains text (OK, WARNING, ALARM), not numbers. Show it with a Text block, not a Gauge.
I accidentally shared my project with the key inside.
Anyone with the key can write to your feeds. Go to io.adafruit.com, open the key dialog and generate a new key — the old one stops working immediately. Then paste the new key into your program. Before you share a Wokwi project, replace the key with "your_aio_key".
Optional real hardware
You do not need any of this — the whole exercise runs in Wokwi. If your school has ESP32 boards, these are the parts for the same circuit.
| Part | Qty | Note |
|---|---|---|
ESP32 DevKit (ESP32-DevKitC V4 or similar)From exercise #1 | 1 | Its GPIO pins use 3.3V logic and are not 5V tolerant. Power the sensors from the 3V3 pin. |
USB cable (data capable; micro-USB or USB-C depending on the board)From exercise #1 | 1 | Charge-only cables carry no data — if the board does not show up on the computer, try another cable first. |
Breadboard (830 tie points)From exercise #1 | 1 | The ESP32 DevKit is wide; use a full-size breadboard so that free rows remain on both sides. |
Jumper wires male-male (at least 15)From exercise #1 | 1 | |
DHT22 (AM2302) temperature & humidity sensorFrom exercise #1 | 1 | Measures the motor temperature in our scenario. Powered from 3V3, its data line is 3.3V too — safe. Wait at least 2 seconds between readings. |
10 kΩ potentiometerFrom exercise #1 | 1 | Stands in for the machine’s vibration level. Outer legs to 3V3 and GND — NOT 5V — middle leg to GPIO 34. |
5 mm red LEDFrom exercise #1 | 1 | The alarm lamp. Long leg (anode) to the resistor, short leg (cathode) to GND. |
220 Ω resistorFrom exercise #1 | 1 | Limits the LED current. At 3.3V it gives about 5–6 mA — bright enough and safe for the pin. |
5V 1-channel relay moduleCautionFrom exercise #1 | 1 | Switches the cooling fan. Connect VCC to the 5V pin. Most 5V relay modules work with the ESP32’s 3.3V signal, but some do not trigger — then use a 3.3V-compatible module or a transistor driver. NEVER switch mains voltage (230V) in class. |
