Learning Goals 5 min
Cluster B's capstone: a wall-mounted live IoT dashboard for your room. Temperature, humidity, light, with historical charts and phone-app access. The polished combination of everything in L04-07..11. By the end of this lesson you will be able to:
- Wire 3 sensors (DHT11 for temp + humidity, LDR for light) to a Cloud-capable board.
- Define a Thing with at least 4 Properties (temperatureC, humidityPct, lightPct, uptime).
- Build a polished dashboard with gauges, charts, and at-a-glance value cards — ready to share publicly or via per-user invite.
Warm-Up 10 min
Hardware:
- Supported Cloud board (Nano ESP32, MKR WiFi 1010, UNO R4 WiFi).
- DHT11 (cheap, ±5% RH, ±2 °C). Or DHT22 / BME280 for higher precision.
- LDR voltage divider on A0.
- 10 kΩ resistor for the LDR divider.
- USB power supply for permanent install.
- (Optional) An OLED on I²C for local display in addition to the cloud.
Install libraries
If using DHT11 / DHT22: Library Manager → "DHT sensor library" (Adafruit). For DHT22 you may also want "Adafruit Unified Sensor".
New Concept · The polished IoT product 20 min
Architecture review
- Sensor reads happen at a slow rate (every 10–30 s — DHT11 is slow).
- Property assignments push to the cloud automatically.
- Dashboard shows current value (Gauge) + 24h history (Chart).
- Phone app reads the same dashboard remotely.
- Optional local OLED + LED for "at home, no internet" reliability.
Properties
| Property | Type | Update | Purpose |
|---|---|---|---|
| temperatureC | Temperature (float) | On Change | Room temp |
| humidityPct | RelativeHumidity (float) | On Change | Room humidity |
| lightPct | Percentage (float) | On Change | Brightness 0–100 |
| tempAlarmThreshold | Temperature (float) | READWRITE | Configurable hot-room alert |
| uptime | int | Periodically (60s) | Device alive indicator |
Dashboard layout
- Three big Gauges side-by-side: Temp, Humidity, Light.
- One Chart underneath spanning full width — Temperature over 24h.
- One Chart — Humidity over 24h.
- One Slider for tempAlarmThreshold (with the current threshold visible).
- One Value at the bottom-right — uptime.
Worked Example · The full build 30 min
Step 1 — wire
| Component | Pin |
|---|---|
| DHT11 data | D2 |
| DHT11 VCC, GND | 3V3, GND |
| LDR voltage divider (LDR + 10 kΩ to GND) | Midpoint → A0; LDR top → 3V3 |
Step 2 — create the Thing
Name: RoomMonitor. Attach device. Add the 5 properties from §3.
Step 3 — the sketch
#include "thingProperties.h"
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
const int LDR_PIN = A0;
const int LDR_DARK = 100;
const int LDR_BRIGHT = 900;
unsigned long lastSensorAt = 0;
const unsigned long SENSOR_PERIOD_MS = 15000;
void setup() {
Serial.begin(9600);
delay(1500);
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
dht.begin();
tempAlarmThreshold = 28.0; // default
}
void loop() {
ArduinoCloud.update();
unsigned long now = millis();
if (now - lastSensorAt >= SENSOR_PERIOD_MS) {
lastSensorAt = now;
float t = dht.readTemperature();
float h = dht.readHumidity();
if (!isnan(t)) temperatureC = t;
if (!isnan(h)) humidityPct = h;
int raw = analogRead(LDR_PIN);
raw = constrain(raw, LDR_DARK, LDR_BRIGHT);
lightPct = map(raw, LDR_DARK, LDR_BRIGHT, 0, 100);
uptime = now / 1000;
Serial.print("t="); Serial.print(temperatureC);
Serial.print(" h="); Serial.print(humidityPct);
Serial.print(" l="); Serial.println(lightPct);
// Local action on alarm
if (temperatureC > tempAlarmThreshold) {
Serial.println("HOT");
// Could also trigger a webhook here (L03-36 pattern).
}
}
}
void onTempAlarmThresholdChange() {
Serial.print("Threshold changed to ");
Serial.println(tempAlarmThreshold);
}Step 4 — dashboard build
Three Gauges + two Charts + Slider + Value, arranged as in §3. Save.
Step 5 — open the phone app
Arduino IoT Remote → RoomMonitor dashboard. Walk around the house. The values track the actual room temperature / humidity / light. Cover the LDR — lightPct drops. Breathe on the DHT11 (or use a hair dryer carefully) — temp + humidity react.
Step 6 — share publicly
Generate a read-only public link. This is your "live room monitor" URL. Bookmark on phone home screen.
Step 7 — leave it running for a day
USB-powered, on a shelf, plugged in. Come back later — the charts have a day's worth of data. Note overnight cooling, daytime warmth, the brightness spike when you turn on lights.
Basic 5 min
Goal: Change the sensor period to 5 s. Confirm the chart fills up faster. Note: keep at least 1 s between DHT11 reads.
The Serial Monitor should show something like this:
t=24.00 h=61.00 l=48.00 t=24.00 h=60.00 l=47.00 t=25.00 h=60.00 l=47.00
…one new line every 5 seconds.
1. Think first (on paper, no typing yet):
- Which line of the Worked Example decides how often the sensor block runs? What unit is its number in?
- At 15 s, how many readings go to the chart in one minute? How many at 5 s?
2. Code it. Open your Room Monitor sketch and make the change.
3. Upload and observe. Time ten lines in the Serial Monitor with a stopwatch, then look at the Chart.
It works if: ten lines take about 50 seconds (12 a minute, not 4), and the chart gains points about three times as fast.
Challenge 1 5 min
Goal: Add a BME280 (more accurate, supports barometric pressure) in place of the DHT11. Use the Adafruit_BME280 library. Add a fourth property: pressureHpa.
1. Think first (on paper, no typing yet):
- The BME280 talks I²C. Which two pins does that use on your board, and which address might it have?
- The library gives pressure in pascals. How many pascals are in one hectopascal?
- Which lines of the Worked Example belong only to the DHT11 and must go?
2. Code it. Install Adafruit BME280 from the Library Manager. Add pressureHpa (float, READ) on the Thing's page. Then change your Room Monitor sketch. Print a message if the sensor is not found.
3. Upload and observe. Watch the Serial Monitor and the Properties page. Breathe on the sensor.
It works if: pressureHpa reads about 950–1030 hPa (lower if you live high up), temperature and humidity still update, and breathing on the sensor raises the humidity.
Challenge 2 5 min
Goal: Send an IFTTT alert (L03-37 pattern) when temperatureC crosses tempAlarmThreshold. The IoT Cloud doesn't do IFTTT directly — wire it in your sketch's sensor block.
1. Think first (on paper, no typing yet):
- The room is hot for an hour. How many alerts should your phone get? So when exactly should the sketch send one?
- To spot the moment it becomes hot, what must the sketch remember from the last reading?
- Which helper from L03-36 sends the request, and what does it need?
2. Code it. Start from your Room Monitor sketch and add the alert inside the sensor block.
3. Upload and observe. Set the threshold slider just above the room temperature, then breathe on the DHT11 or hold it in your hand.
It works if: exactly one alert arrives when the room goes over the threshold, none while it stays hot, and another only after it has cooled below and gone over again.
Challenge 3 · Stop the flickering alarm 10 min
A classmate added an alarm LED on D4 to the room monitor. When the room sits near 28 °C, the LED flickers on and off every reading. Some readings also make the temperature jump to nan.
const int ALARM_LED_PIN = 4;
void checkAlarm() {
float t = dht.readTemperature();
temperatureC = t;
if (temperatureC > tempAlarmThreshold) {
digitalWrite(ALARM_LED_PIN, HIGH);
} else {
digitalWrite(ALARM_LED_PIN, LOW);
}
}- Fix the
nanproblem. A failed read must keep the last good value. - Add hysteresis: turn the LED on above the threshold, but only off below the threshold minus 1 °C.
- Call it from the sensor block of the Worked Example and test with your breath on the DHT11.
1. Think first (on paper, no typing yet): look up what readTemperature() gives back when a read fails, and how a sketch can test for it. Then draw a line from 26 °C to 30 °C with the threshold at 28. Mark where the LED turns on going up and where it turns off coming down. At 27.5 °C, can the sketch decide what to do from the temperature alone?
2. Code it in your Room Monitor sketch, following the three steps above.
3. Upload and observe. Set the threshold just above room temperature. Breathe on the DHT11, then let it cool, and watch the LED and the Serial Monitor.
It works if: the LED turns on above the threshold. It stays on until the room is a full degree below it.
Cluster B done. Cluster C (MQTT + Home Integration) starts in L04-13.
Recap 5 min
IoT Room Monitor combines Cluster B's ideas into a polished product: 3 sensors, 5 properties, gauges + charts + slider, public link + phone app. Code is ~50 lines; the cloud infrastructure carries everything else. This is the IoT pattern that scales — measure, push, visualise, alert. Tomorrow: a heavier-duty cousin called MQTT, which is what every "real" smart-home device uses under the hood.
- DHT11 / DHT22
- Cheap combined temperature + humidity sensors. DHT11 = ±2 °C, ±5% RH. DHT22 = ±0.5 °C, ±2% RH.
- Sensor period
- How often you read the sensor. Slow sensors (DHT, BME) have minimum periods.
- Calibration constants
- Measured values (LDR_DARK, LDR_BRIGHT) used in
map()to convert raw ADC readings to friendly units. - Threshold property (READWRITE)
- A configurable value (alarm threshold) that the user changes from the dashboard. Survives reboot if persisted; otherwise resets to a default on each boot.
- Kiosk mode
- Wall-mounted tablet showing dashboard fullscreen. Use a public read-only link.
- Once-per-event suppression
- Fire alert once on threshold crossing; don't fire again until recovery. From L03-36.
Extra Mission 5 min
Part 1 — Design a monitor for a different place
Pick a place that needs watching — a greenhouse, a pet's room, a garden shed, a fridge. On paper, design a monitor for it.
Your design must include:
- What it measures, and why each reading matters there.
- Every Property, with type, permission and update policy.
- One alarm, with its threshold and its hysteresis.
- A sketch of the dashboard layout.
Part 2 — Make it
Change the IoT Room Monitor to match your design, using the DHT11, LDR and LEDs you have. Leave it running for at least 24 hours.
Bring back next class: the sketch, a screenshot of the 24-hour chart, and a photo of the device in place.