What it shows
Factories and smart buildings send small readings from many sensors to one place. MQTT is the light-weight publish-subscribe protocol for this. The project builds three ESP32 nodes that publish readings to a broker on a laptop, with Node-RED showing live charts and alerts, and tests behaviour when a node drops off.
The science
In MQTT, clients publish messages to named topics such as lab/node1/temp and a broker forwards them to every client that subscribed. Quality of service levels 0, 1 and 2 give increasing delivery guarantees. A retained message gives a new subscriber the last value at once. A last-will message tells others when a node has died unexpectedly.
Materials
Cost: under Rs 5,000. Many items come from home or from waste; spare parts such as LEDs, motors and wire are in the store.
- Three ESP32 boards
- DHT22, BMP280 and an LDR with 10 kΩ resistor, one for each node
- A laptop running the free Mosquitto broker and Node-RED
- A Wi-Fi router
- A 5 V relay module and a 12 V LED strip as an actuator (low voltage only)
- Breadboards and USB power banks
Safety
For this project: Keep the broker on the local network and set a username and password. Relay switches only the 12 V strip. An adult must check wiring.
Never use mains electricity: power models with cells, batteries or a low-voltage adapter. Sharp and hot tools, flames and lab chemicals need an adult or your teacher beside you. Keep magnets, button cells and small parts away from young children, and wash your hands after making.
All the safety rulesStep by step
12 steps. Do them in order, and test each part before you go on to the next. Write what you notice in a notebook as you go.
Install Mosquitto and Node-RED on the laptop, create a password file and start the broker.
Plan the topic tree: lab/<node>/temperature, humidity, light, status and lab/actuator/strip.
Install the PubSubClient library and write the node sketch that connects to Wi-Fi and the broker.
Publish a reading every 15 seconds as a small JSON payload with the node name and a timestamp counter.
Set the last-will message to offline on the status topic and publish online with retain on connect.
Flash the sketch to three nodes with different names and sensors.
Build the Node-RED flow: MQTT input nodes, a function node to parse JSON, charts and gauges on the dashboard.
Add a rule so that when temperature is above 32 degrees an MQTT message turns the relay on and the strip lights as an alarm.
Test the loss of a node by unplugging it and check that the dashboard shows offline.
Measure the delay between a reading and its display with timestamps, and the message loss after switching the router off for a minute.
Compare QoS 0 and 1 for the strip command during the outage.
Write the report with architecture, topic tree, flows, timing results and security notes.
What you should see
The dashboard shows three nodes’ readings live with delays under a second, switches the strip on at the alarm threshold and marks a node offline within seconds of unplugging it.
Viva questions
A teacher or a judge will ask how it works. Try to answer each question before you open it, then compare.
1What is a broker?
A server that receives published messages and forwards them to the clients that subscribed to that topic.
2Why is MQTT popular in IoT?
It uses very small messages, works over weak links and needs little power.
3What is a retained message?
The last message on a topic that the broker stores and sends to every new subscriber.
4What does last will do?
It publishes a preset message if the client disconnects without saying goodbye.
Take it further
Store all readings in an InfluxDB or SQLite database and draw a week of data in a Grafana style chart.
Change one thing, measure what happens, and add a table or chart of your readings: that is what turns a model into your own investigation.
Free ebooks for this project
Hardware & repair
Computer Networking Study Book
The complete study notes, practice questions and glossary for Computer Networking
