Start your IoT journey by building a cloud-connected temperature and humidity monitor. This project uses the affordable ESP8266 to capture environmental data from a DHT11 sensor and push it to a live cloud dashboard. Perfect for monitoring your greenhouse, baby's room, or server rack from anywhere in the world.
In this tutorial, we leverage the power of ThingSpeak (or any similar cloud platform) to visualize our data. The ESP8266 (NodeMCU) connects to your home WiFi, reads the digital signal from a DHT11 sensor every 15 seconds, and sends an HTTP GET request to the cloud API.
This project covers the basics of HTTP communication, JSON data handling, and wireless sensor networking. By the end, you'll have a live graph of your room's conditions accessible via any web browser.
| Part Name | Qty |
|---|---|
| NodeMCU ESP8266 Board | 1 |
| DHT11 Temperature & Humidity Sensor | 1 |
| Micro USB Cable | 1 |
| Mini Breadboard & Jumper Wires | 1 set |
| DHT11 Pin | ESP8266 Pin | Function |
|---|---|---|
| VCC | 3.3V | Power |
| GND | GND | Ground |
| DATA | D2 (GPIO 4) | Serial Data Signal |
Note: If your DHT11 sensor module doesn't have a 10k resistor built-in, place one between VCC and DATA pins to pull the signal high.
#include <ESP8266WiFi.h>
#include <DHT.h>
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";
const char* host = "api.thingspeak.com";
String apiKey = "YOUR_API_KEY";
#define DHTPIN 4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
dht.begin();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) { delay(500); }
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) return;
WiFiClient client;
if (client.connect(host, 80)) {
String url = "/update?api_key=" + apiKey + "&field1=" + String(t) + "&field2=" + String(h);
client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");
}
delay(20000); // Wait 20 seconds between uploads
}