Skip to content

Tutorial

ESP32 DHT11 Dashboard with Blynk: Gauge and History Chart

Send DHT11 temperature and humidity from an ESP32 to Blynk 2.0. Configure two datastreams, build dashboard gauges and a history chart, use a timer instead of flooding the cloud, and troubleshoot missing readings.

ESP32 DHT11 Dashboard with Blynk: Gauge and History Chart

ESP32 DHT11 Dashboard with Blynk: Gauge and History Chart

This project publishes temperature and relative humidity from a DHT11 to Blynk 2.0. The dashboard displays current values and a history chart, giving you a practical sensor-telemetry example rather than only remote control.

Model each measurement explicitly: temperature in degrees Celsius and humidity in percent. DHT11 is a basic sensor, so don't display excessive decimal precision or treat readings as laboratory calibration. Verify wiring and the installed library APIs before relying on the data.

Hardware and datastreams

You need an ESP32 development board, DHT11 sensor/module, jumpers, Arduino IDE, DHT sensor library and Blynk library. Connect DATA to GPIO 4 for this example. Check whether your breakout has a pull-up resistor; a bare sensor may need one, and its supply voltage depends on the sensor/module.

In Blynk.Console create:

  • V1 — Temperature C, numeric with a suitable range for your application.
  • V2 — Humidity %, numeric with a range from 0 to 100.

Create gauges for each datastream. Configure a chart according to the current Blynk widget options; chart retention and features may depend on current plan limits, so confirm official docs before promising a duration.

1. Upload the sketch

Install the DHT sensor library and Blynk library from Arduino IDE Library Manager. Replace all placeholders locally and use your actual template ID and token. BlynkTimer schedules updates; the code does not call virtualWrite continuously on every loop pass.

sketch.ino
#define BLYNK_TEMPLATE_ID   "REPLACE_WITH_TEMPLATE_ID"
#define BLYNK_TEMPLATE_NAME "ESP32 DHT11"
#define BLYNK_AUTH_TOKEN    "REPLACE_WITH_DEVICE_AUTH_TOKEN"

#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>

#define DHT_PIN 4
#define DHT_TYPE DHT11

char ssid[] = "REPLACE_WITH_WIFI";
char pass[] = "REPLACE_WITH_WIFI_PASSWORD";

DHT dht(DHT_PIN, DHT_TYPE);
BlynkTimer timer;

void sendSensorData() {
  const float humidity = dht.readHumidity();
  const float temperatureC = dht.readTemperature();

  if (isnan(humidity) || isnan(temperatureC)) {
    Serial.println("DHT11 read failed; sample skipped.");
    return;
  }

  Blynk.virtualWrite(V1, temperatureC);
  Blynk.virtualWrite(V2, humidity);
  Serial.printf("Temperature: %.1f C, humidity: %.1f %%\n",
    temperatureC, humidity);
}

void setup() {
  Serial.begin(115200);
  dht.begin();
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  timer.setInterval(2500L, sendSensorData);
}

void loop() {
  Blynk.run();
  timer.run();
}

2. Build the dashboard and history chart

Add a gauge for V1 labelled Temperature (°C). Add another for V2 labelled Relative humidity (%). Set ranges appropriate to your use case; widget range is a presentation choice, not a sensor accuracy statement.

Add a chart widget using the datastreams and history settings supported by your current Blynk account. Start by proving live updates work before debugging history. Blynk's guide to displaying sensor data explains the general data path.

3. Respect the sensor update rate

The example samples about every 2.5 seconds, a conservative interval for a DHT11. If an update fails, it skips the upload and logs an error. That is preferable to publishing zero, which can look like a valid measurement. In a more complete dashboard, show last-update time and validity/availability so missing updates do not appear fresh.

Do not use Blynk.virtualWrite on every pass through loop. Use a timer or meaningful value-change strategy, and check current service policies before setting production write rates.

Troubleshooting

Device offline: verify Wi-Fi, template ID, token, library and device configuration.

Sensor returns NaN: check pin, supply, ground, data wiring, pull-up and sampling interval.

Gauge shows the wrong value: confirm widget/datastream mapping, labels, units and range.

No chart history: first prove live uploads work, then inspect current chart setup and account capabilities.

Too many cloud writes: check that updates are timed rather than sent continuously.

7. Validate the DHT11 reading before publishing it

A dashboard can only be as reliable as the measurement arriving at it. The DHT11 is inexpensive and easy to use, but it has relatively coarse resolution and slower response than many modern digital sensors. Treat its output as an approximate environmental reading, not a precision instrument. Before debugging the Blynk chart, run a standalone sensor test and print the temperature and humidity to the serial monitor. Confirm the sensor model, DATA pin, power, ground, and pull-up arrangement. DHT modules do not all use the same connector order, so check the markings on the actual breakout rather than assuming left-to-right pin order.

Take readings at a sensible interval. Polling a DHT11 too quickly can return errors or repeated values; use the timing recommended by the sensor library and datasheet, and start with a gap of at least a couple of seconds. Catch sensor exceptions so a failed sample does not crash the whole application. Decide explicitly what the dashboard should do when a sample fails: keep the last valid value with a visible stale indicator, or show an unavailable state. Do not replace failed readings with zero, because zero can look like a genuine temperature or humidity measurement. If readings jump unexpectedly, compare with another thermometer/hygrometer and check whether the sensor is near a warm regulator, direct sunlight, a fan, or a source of moisture.

8. Build the Blynk datastreams carefully

In Blynk Console, open the template used by the device and create datastreams that match the values sent by the firmware. A typical arrangement uses one virtual pin for temperature and another for humidity, with numeric data types and sensible minimum and maximum display ranges. The exact menu labels can vary by Blynk version, but the key requirements do not: the firmware's virtual pin, the template's datastream, and the widget's data source must agree. If the code writes temperature to V0 while the gauge listens to V2, the dashboard may remain blank even though Wi-Fi is connected.

Choose units and precision that match the sensor's actual capability. Showing many decimal places does not make a DHT11 more accurate. A gauge is useful for a current value; a history chart is useful for trends, but the chart must be linked to a datastream that records history and must have enough elapsed time to show meaningful variation. Confirm whether the selected Blynk plan or current console settings support the desired history features. Keep datastream names descriptive, such as temperature_c and humidity_pct, and avoid reusing one virtual pin for unrelated measurements. After changing a datastream, save the template and ensure the device is using that template before testing again.

9. Separate connection failures from dashboard failures

Use a layered test sequence instead of changing the sensor, Wi-Fi, and Blynk settings at once. First, print sensor values locally. Second, confirm the ESP32 joins the correct 2.4 GHz Wi-Fi network and prints a valid local IP address. Third, confirm that the Blynk library reports a successful cloud connection. Fourth, print a short diagnostic immediately before each virtual-pin write. Finally, inspect the matching datastream and widget in the console. These steps distinguish a sensor fault from a network problem or a dashboard configuration mismatch.

If the device connects and then repeatedly disconnects, check signal strength, router stability, power quality, and whether the sketch blocks for too long during sensor reads or delays. Avoid long blocking loops that prevent the Blynk library from servicing its connection. Use the library's recommended connection-maintenance function in the main loop and keep the sampling interval controlled with a timer based on millis() where practical. Do not call cloud writes continuously at the fastest possible loop rate; send updates at a reasonable interval and within the platform's current limits. If the serial log reports authentication or template errors, verify the device's template assignment and credentials. Never post a real device token in a screenshot or public code sample.

10. Make history charts useful and honest

A history chart is most valuable when samples arrive at a consistent interval and the data source is configured to retain them. Decide whether you need minute-by-minute trends, hourly changes, or a longer environmental record. A room monitor might send a sample every 10–30 seconds for a live gauge while a slower reporting interval can be enough for long-term comfort trends; choose a rate that matches the application and the service's current limits. More frequent updates use more network traffic and can make a graph look noisy without adding meaningful information.

Interpret the graph in context. A sudden temperature change may indicate a real environmental event, sensor placement, or a bad sample. Humidity can respond slowly, and the sensor may lag behind rapid changes in the room. Label axes and units, use a suitable time window, and avoid drawing conclusions from a short flat chart immediately after setup. Verify that the dashboard's history feature is enabled for the datastream and that the widget uses the correct source. If a chart remains empty while a gauge updates, inspect history settings and the selected widget rather than assuming the sensor stopped working. For more durable records or analysis, consider periodically exporting data to a storage service designed for long-term time series.

11. Power, enclosure, and deployment checklist

A desk prototype may work over USB but fail when moved into an enclosure or powered from a different supply. The ESP32 can draw brief current peaks when its radio transmits, so use a stable supply with adequate current capability and good wiring. Keep sensor wiring away from noisy motor, relay, and switching-power leads. If the project is powered by a battery, account for regulator efficiency and Wi-Fi duty cycle rather than estimating battery life from the sensor's current alone. Do not connect a bare DHT11 data output to a GPIO if the module drives the line above the ESP32's permitted input voltage.

Before leaving the monitor running, verify all of the following: the sensor is mounted away from heat sources; the dashboard labels show the correct units; readings continue after a router reconnect; failed samples do not become fake zeroes; the device token is not in a public repository; and the power supply remains stable during Wi-Fi activity. If the monitor is installed in a shared space, explain what it measures and avoid presenting it as a calibrated safety instrument. The goal is a dependable hobby dashboard: it should show plausible current readings, make stale data obvious, and provide enough diagnostics to identify whether a failure originates at the sensor, network, cloud service, or widget configuration.

12. Example sampling pattern for a stable dashboard

If your existing sketch reads the sensor and writes to Blynk inside every pass through loop(), move the sampling schedule to a timer so the code has predictable behavior. For example, use millis() to check whether the sampling interval has elapsed, then perform one read and update both datastreams. Keep the Blynk connection-maintenance call running on every loop pass, as recommended by the library version you installed. This avoids a long fixed delay that can starve network processing. A simple pattern is:

sketch.ino
unsigned long lastSample = 0;
const unsigned long sampleInterval = 5000;

void loop() {
  Blynk.run();
  const unsigned long now = millis();
  if (now - lastSample >= sampleInterval) {
    lastSample = now;
    // Read the sensor here, handle errors, then write valid values.
  }
}

This is a scheduling pattern, not a complete replacement sketch: initialize Blynk and the sensor in setup(), and implement the sensor-specific read and error handling in the marked section. Unsigned subtraction handles the normal millis() rollover safely when used this way. Choose an interval appropriate to the sensor and service limits; a DHT11 does not need rapid polling. If you add more sensors, avoid making each sensor read block the main loop for a long time.

13. Final validation checklist

Before calling the project complete, confirm that the serial monitor prints plausible readings, the ESP32 reconnects after a Wi-Fi interruption, and the Blynk device is associated with the intended template. Verify the temperature and humidity datastreams independently, then confirm that the gauge and history chart each reference the correct datastream. Check the displayed units, range, and decimal precision. Leave the device running long enough to confirm that history points continue to arrive, and deliberately disconnect the network once to observe how the firmware recovers.

Keep credentials private, record the sensor model and firmware/library versions, and document which GPIO is used for DATA. If the dashboard shows stale values, make that state visible instead of treating the last successful sample as current forever. If the chart is blank but the gauge updates, inspect the history configuration and time window. If both widgets are blank, move backward through the diagnostic layers: datastream mapping, Blynk connection, Wi-Fi, then local sensor reading. This structured process prevents a cloud dashboard issue from being mistaken for a wiring fault and gives you a repeatable method for future ESP32 telemetry projects.

Continue learning

Related articles

All articles

Signal In

Built from what makers search for

The lookups piling up in SolderHub's search bar every day shape what we publish next — new component pages, board guides, and firmware notes, sent out as they go live.

By subscribing you agree to our Privacy Policy. Unsubscribe anytime.