ESP32 IoT Projects: From a Single Sensor to a Live Dashboard
An IoT project is a loop: sense, publish, act. Build it in that order and every project you attempt afterwards has the same shape.
What makes a project IoT rather than merely connected
Plenty of projects have a radio and none of them are IoT. The thing that makes a build an IoT project is that a reading leaves the device and changes something somewhere else: a chart updates, a message arrives on a phone, another machine reacts. The sensor and the radio are just the parts you can point at.
That gives you a fixed three-part shape to plan around. Sense: read a real quantity with a sensor and turn it into a number. Publish: send that number somewhere a program will receive it. Act: do something because of what came back. Get the first two right on a bench with a laptop on the same network and the third part is usually a small addition. Most beginner failures happen in the middle part, because people treat the network as if it were a wire. It is not. It drops, it delays, it delivers twice, and it disappears when the router reboots. Any project worth doing in a classroom has to survive that, which is why reconnection logic is not an optional extra here.
Choosing how the data travels
Three transports cover almost every classroom IoT project. MQTT is a publish and subscribe broker: your device publishes to a topic such as classroom/temp/node3, and anything subscribed to that topic receives the message. It handles reconnects and offline buffering, which is why it is the usual choice for sensor data. WebSockets keep a connection open and push updates, which suits a live dashboard. Plain HTTP is a request and response, and it suits a camera uploading a snapshot to a server.
Payload format matters more than people expect. A JSON message with named fields, a device identifier and a timestamp can be read by a spreadsheet, a dashboard and a Python script without anybody writing a parser three times. A bare number with no units is a number you will misread within a week. The third decision is power. A node that stays connected and sends every second will flatten a battery in days. A node that wakes, reads, publishes and sleeps can last months, because the radio only draws current during the transmit. Deep sleep is the single biggest battery win available to an ESP32, and it costs one line of code to measure the difference.
Step by step
-
Get one node talking to a broker
Publish a fixed value to a topic and read it back on a phone or a second laptop. Do this before adding any sensor, so a network problem never looks like a sensor problem.
-
Replace the fixed value with a real reading
Swap in a temperature sensor and publish the reading with a unit, a node ID and a timestamp in the payload. Compare two nodes side by side.
-
Log a week of readings
Store the payload stream in a file or a database and plot it. A temperature graph with a visible daily cycle is a genuinely satisfying result for very little code.
-
Make the publishing survive a dropped link
Turn off the access point for a minute and watch the node fail. Then add a reconnect loop with a backoff delay and watch it recover on its own.
-
Add deep sleep between readings
Wake on a timer, read, publish, sleep. Compare the average current draw before and after with a USB power meter or a multimeter in series.
-
Close the loop with an action
Let the server command a relay, a light or a fan based on a threshold, so the project becomes sense, publish, act. This is the step that turns a monitor into a system.
What you'll need
| Item | Qty | Why |
|---|---|---|
| ESP32 DevKit board | 2 | Two nodes let you build a real path from sensor to broker to actuator instead of a loopback test. |
| DHT22 temperature and humidity sensor | 2 | Slow, digital and cheap. The right first sensor because the interesting part is the network, not the measurement. |
| Relay module, 5 V, opto-isolated | 1 | Lets the server command a real load and close the sense-publish-act loop safely. |
| Breadboard and jumper wires | 1 set | Two nodes plus a relay needs more than a single strip, and rewiring should not require a soldering iron. |
| 5 V, 2 A USB power supply | 1 | The supply for the node that drives a relay, kept separate from the sensor node so a switching transient cannot reset it. |
| MicroSD card module | 1 | Local buffering so readings survive a network outage and upload later. |
Practise it before you build it
Every step above has a matching circuit in the ThinkEdge Learn simulator. The simulator runs a real
Arduino sketch against a modified-nodal-analysis solver, so digitalWrite actually drives the
LED on screen and the readings change when you change the wiring — no hardware, no burnt components.
In factories, conveyor belts carry products past a sensor that counts them. A simple "break-beam" sensor (a light source + photodetector) registers each object as it passes. In this project, you'll simulate the conveyor with your hand: every time you press the button (mimicking a product passing the sensor), the counter increments and the LED blinks. Add a buzzer to beep once for every 10 items. This is the same logic as a people counter at a door, a coin counter at a bank, or a bottle counter on a bottling line.
The Mega has 4 hardware serial ports (Serial, Serial1, Serial2, Serial3). That means you can talk to 4 different devices at the SAME time — like a GPS, a Bluetooth module, an XBee radio, and the USB. Use 3 of those ports to read 3 different sensors in parallel and stream their data to the Serial Monitor as a CSV row every second. This is the foundation of every real Arduino data logger.
The DHT11 is a small blue module that measures temperature (0-50°C) and humidity (20-90%). Inside it has a tiny microcontroller, a humidity sensor, and a thermistor. It speaks a custom one-wire protocol that the Adafruit DHT library decodes for you. You just call dht.readTemperature() and you get a number back.
Combine a PIR motion sensor with a slide switch (arm/disarm) and a buzzer. This is the same logic as a real home alarm: you arm the system when you leave, and if anything moves while it is armed, it sounds the alarm. We also use millis() to keep the alarm sounding for a fixed time even if the motion stops.
Mount an HC-SR04 ultrasonic sensor on top of a servo. Sweep the servo from 0° to 180° and back, and at each step measure the distance. Print the results to the Serial Monitor as "angle,distance" pairs. Open the Serial Plotter in the Arduino IDE to see a live radar-like graph of the room. With Processing on your computer, you can build a full visual radar.
An Arduino pin is not a power supply. Each GPIO pin is rated to source at most about 20 mA — that is the limit for one pin, and the whole chip together is limited to roughly 40 mA. A 5 V relay coil needs about 50 mA to pull its contacts closed, which is more than twice what a single pin will give. Wire the pin straight to the coil and you do not get a working relay; you get a pin running hot, a supply sagging under USB, and contacts that only just close. The fix is an NPN transistor. The pin drives the transistor's base through a resistor — only a few milliamps — and the transistor switches the full coil current. The relay then does the one thing it is genuinely better at than a transistor: its coil, carrying 50 mA, pulls a set of metal contacts that carry a completely separate circuit. Nothing in that second circuit ever touches the Arduino. That is galvanic isolation, and it is the reason the relay has survived fifty years of transistors — you can switch a high-voltage load from a 5 V logic signal without the two ever meeting.
Common questions
Which IoT projects are easiest for beginners?
Start with temperature reporting every five minutes. It has one sensor, one output, and a graph at the end, and it can be built entirely on the breadboard in a single session. The conveyor counter is a good second build because it adds a stateful input and a count you can verify by hand.
Do I need a paid cloud service for an IoT project?
No. A broker such as Mosquitto runs on a laptop or on a Raspberry Pi and costs nothing, and it is a better teaching setup because students can see the topic traffic themselves. If you do use a hosted broker, the free tiers are enough for a class-sized number of nodes sending a reading every minute.
How long should a battery-powered IoT node last?
With deep sleep and a reading every 15 minutes, a 2000 mAh cell comfortably runs for a year, and often far longer. Continuous Wi-Fi with a reading every second drains the same cell in a day or two. The measurement worth doing in class is the current draw in each mode, because it turns the choice into arithmetic rather than opinion.
Related guides
Try the full simulator with your class
103 guided circuit projects, 21 lessons and an in-browser Arduino simulator. The first 15 projects are free, no account needed. NCERT Science mapping on 47 projects, with Arabic and English copy in the regional builds.