Build a live climate dashboard with Arduino Cloud

The DHT11 measures temperature and humidity, and Arduino Cloud shows them on gauges and live charts that you can check from your phone anywhere.
  • Level:Intermediate
  • Duration: 50 min
  • Ages 11+
  • Platform: ESP32

Tools for this lesson

Helpful for this build. Open a tool to see tips and more projects that use it.

Build a live climate dashboard with Arduino Cloud – EEMENTOR STEM™ lesson

How warm is your room at night? Does the bathroom get very humid after a shower? In this lesson the ESP32 measures temperature and humidity every few seconds and sends them to Arduino Cloud, where you see them on gauges and on a live chart. Because the readings go through the internet, you can check your room from school or from a holiday.

What you'll learn

  • How to send sensor readings to Arduino Cloud
  • Why read-only variables and a publish interval save data
  • How to use the Temperature sensor variable type
  • How to show history on a chart widget

What you need

  • ESP32 board, expansion board and USB cable (ESP32 IoT Starter Kit)
  • DHT11 temperature and humidity sensor (ESP32 IoT Starter Kit)
  • An Arduino Cloud account and the ESP32 device from lesson 1
  • A 2.4 GHz Wi-Fi network
  • The printed parts from the 3D printing box below (sensor house), or the cardboard version described there
  • Breadboard and jumper wires (ESP32 IoT Starter Kit)

Wiring

Breadboard wiring diagram: Build a live climate dashboard with Arduino Cloud
Breadboard view. Check each connection against the wiring table below.
From To
DHT11 S (data) ESP32 GPIO 27
DHT11 + 3V3
DHT11 − GND

Sensor modules from different makers can label and order their pins differently. Always follow the labels printed on your module.

Set up Arduino Cloud

In Arduino Cloud, open Things, create a new Thing called Climate, link it to your ESP32 device and fill in its network settings. Then add these variables. Lesson 1 of this path shows each step with pictures in words.

Variable Type Permission Update
temperature Temperature sensor (°C) Read only Every 10 s
humidity Floating point number Read only Every 10 s

Open Dashboards, create a dashboard and add two Gauges and a Chart (temperature), each linked to its variable. The same dashboard appears in the free Arduino IoT Remote app on your phone.

Each Thing needs its own device. To keep within the free plan, you can move your ESP32 from the Cloud Lamp Thing to this one: open the old Thing and click Detach, then pick the device in the new Thing.

The sketch

Arduino Cloud writes the sketch's first version for you, with a thingProperties.h tab that lists your variables and a Secret tab with your Wi-Fi details and device key. In the Thing, open the Sketch tab, click Open full editor, replace the main sketch with the code below and upload. Leave the other tabs as they are.

In the Arduino Cloud editor, open Libraries and add the DHT sensor library by Adafruit.

#include "thingProperties.h"
#include <DHT.h>

const int DHT_PIN = 27;
DHT dht(DHT_PIN, DHT11);
unsigned long lastRead = 0;

void setup() {
  Serial.begin(115200);
  delay(1500);
  dht.begin();

  initProperties();
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  setDebugMessageLevel(2);          // connection messages in the Serial Monitor
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  if (millis() - lastRead >= 5000) {        // the DHT11 needs a rest between readings
    lastRead = millis();
    float t = dht.readTemperature();
    float h = dht.readHumidity();
    if (isnan(t) || isnan(h)) {
      Serial.println("No reading from the DHT11");
      return;
    }
    temperature = t;                          // the cloud sends it every 10 s
    humidity = h;
    Serial.printf("%.1f C, %.0f %%\n", t, h);
  }
}

For reference, this is the thingProperties.h that Arduino Cloud creates from the variables above. Yours has your own device ID, and may use an older but equally valid style such as addProperty(led, READWRITE, ON_CHANGE, onLedChange).

// Code generated by Arduino Cloud (yours has your own device ID)
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>

const char DEVICE_LOGIN_NAME[] = "YOUR_DEVICE_ID";
const char SSID[] = SECRET_SSID;              // from the Secret tab
const char PASS[] = SECRET_OPTIONAL_PASS;
const char DEVICE_KEY[] = SECRET_DEVICE_KEY;



CloudTemperatureSensor temperature;
float humidity;

void initProperties() {
  ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
  ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
  ArduinoCloud.addProperty(temperature, Permission::Read).publishEvery(10);
  ArduinoCloud.addProperty(humidity, Permission::Read).publishEvery(10);
}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

How it works

The sketch reads the sensor every five seconds and simply assigns the result to the cloud variables. It doesn't send anything itself: ArduinoCloud.update() notices that the variables changed and sends them, at most once every 10 seconds because of the publishEvery(10) update policy. That keeps the data small and the dashboard calm.

Read only means the dashboard can show these variables but not change them; only the ESP32 can. Temperature sensor is a floating-point number with a unit attached, so widgets know to show °C.

The free plan keeps one day of history for the chart. Leave it running overnight and look at the chart in the morning: when was your room coldest?

Try this next

  • Add a third variable with the "feels like" heat index: dht.computeHeatIndex(t, h, false).
  • Add a Status widget that turns red when the humidity is above 70 %.
  • Put the sensor house outside a window for an outdoor reading.

Troubleshooting

  • The device stays "Offline": open the Serial Monitor at 115200 baud. Check the Wi-Fi name and password in the Secret tab (2.4 GHz only) and that the secret device key is the one you saved when you added the device.
  • Compile error about a variable: the variable names in the sketch must match the ones in your Thing exactly, including capital letters. Rename the Thing's variable or the sketch's to match.
  • "No reading from the DHT11": check its data wire on GPIO 27 and + on 3V3.
  • The temperature is a few degrees too high: the sensor is too close to the ESP32 or in the sun. Move the house away.
  • A printed part is too tight or too loose: printers differ by a few tenths of a millimetre. Sand or file a tight hole, and fix a loose part with a drop of hot glue or a strip of tape.

Build it yourself

Everything used in this lesson comes in one kit, with parts tested by our engineers.

ESP32 IoT Starter Kit | Arduino IDE Compatible | Free Tutorials $57.00

Shop the kit