Cloud weather logger with ThingSpeak
Build it step by step
0 of 5 doneMake a channel
Sign up free at thingspeak.com, create a channel with Field 1 "Temperature" and Field 2 "Humidity", and copy the Write API Key.
Wire the sensor
VCC to 3V3, GND to GND, DATA to D4.
Fill in the sketch
Your Wi-Fi name, password and the Write API Key.
Upload
Upload at 115200 baud and watch for "HTTP 200" with a rising entry number.
Watch the charts
Open the channel's Private View. A point appears every 20 s.
How do you build a cloud weather logger with ThingSpeak?
A NodeMCU sends temperature and humidity from a DHT11 to a free ThingSpeak channel every 20 seconds, where you see live charts. You need NodeMCU ESP8266 (CP2102), DHT11 temperature and humidity sensor, USB A to micro-USB cable (data), 5 V 2 A USB adapter and Jumper wires female to female (40 pcs). It takes 5 steps and about 60 minutes.
- Level
- Intermediate
- Time
- About 60 min
- Parts
- 5
Parts list
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| DHT11 module VCC / GND | NodeMCU 3V3 / GND | Sensor power |
| DHT11 module DATA | NodeMCU D4 (GPIO2) | Readings (the module has its own pull-up) |
Code
Arduino IDE with the ESP8266 board package, board "NodeMCU 1.0 (ESP-12E Module)". Install "DHT sensor library" and "Adafruit Unified Sensor" by Adafruit.
Runs on a virtual NodeMCU ESP8266 in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <DHT.h>
const char* SSID = "your-wifi";
const char* PASS = "your-password";
const char* KEY = "YOUR_WRITE_API_KEY"; // from the channel's API Keys tab
DHT dht(D4, DHT11);
WiFiClient client;
void setup() {
Serial.begin(115200);
dht.begin();
WiFi.begin(SSID, PASS);
while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); }
Serial.println(" connected");
}
void loop() {
float t = dht.readTemperature(), h = dht.readHumidity();
if (isnan(t) || isnan(h)) { Serial.println("DHT read failed"); delay(2000); return; }
HTTPClient http;
String url = String("http://api.thingspeak.com/update?api_key=") + KEY + "&field1=" + String(t, 1) + "&field2=" + String(h, 0);
http.begin(client, url);
int code = http.GET();
Serial.printf("T=%.1f H=%.0f -> HTTP %d, entry %s\n", t, h, code, http.getString().c_str());
http.end();
delay(20000); // the free plan accepts one update every 15 s
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual NodeMCU ESP8266 with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
.... connected
T=27.0 H=55 -> HTTP 200, entry {"ok":true,"note":"simulated response"}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Serial monitor | "connected", then one line every 20 s ending in HTTP 200 |
| Entry number | Goes up by one each time (0 means the update was refused) |
| Breathe on the sensor | Humidity rises by 10 to 30 % on the next point |
If it does not work
HTTP 200 but entry 0
Updates came faster than 15 s or the key is wrong. Use the Write key, not the Read key.
"DHT read failed"
Check DATA is on D4 and give the sensor 2 s between reads.
Negative HTTP code
No internet. Check the router and that the network is 2.4 GHz.
Keep the key private
Anyone with the Write key can post to your channel. Do not share the sketch with the key in it.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the cloud weather logger with ThingSpeak?
NodeMCU ESP8266 (CP2102), DHT11 temperature and humidity sensor, USB A to micro-USB cable (data), 5 V 2 A USB adapter and Jumper wires female to female (40 pcs).
How long does the cloud weather logger with ThingSpeak take to build?
About 60 minutes for a intermediate maker, in 5 steps.
How do I know the cloud weather logger with ThingSpeak works?
Serial monitor: "connected", then one line every 20 s ending in HTTP 200. Entry number: Goes up by one each time (0 means the update was refused). Breathe on the sensor: Humidity rises by 10 to 30 % on the next point.
HTTP 200 but entry 0: what should I check?
Updates came faster than 15 s or the key is wrong. Use the Write key, not the Read key.
DHT read failed: what should I check?
Check DATA is on D4 and give the sensor 2 s between reads.
Negative HTTP code: what should I check?
No internet. Check the router and that the network is 2.4 GHz.
Keep the key private: what should I check?
Anyone with the Write key can post to your channel. Do not share the sketch with the key in it.
