Contents
Introduction
When we connect any sensor to nodemcu we can easily read its value not only that we can also display it value in serial monitor or in any display unit. Today in this blog we will see how we can store the data of sensor connected to nodemcu in thingspeak cloud.
Components Required
- Nodemcu
- Dht11 temperature and humidity sensor
- jumpers wire
- bread board
Connection Diagram

Library Required For this Project
- DHT11 Library
- THINGSPEAK Library
How to Install DHT11 Library
To install the library go to the Sketch > Include Library > Manage Libraries.

type ‘DHT sensor’ in the search bar. There should be a couple entries. Look for DHT sensor library by Adafruit. Click on that entry, and then select Install.

How To Install Things Speak Library
To install the library go to the Sketch > Include Library > Manage Libraries.

type ‘Thingspeak’ in the search bar. There should be a couple entries. Look for Thingspeak by Mathworks. Click on that entry, and then select Install.

How to use Thingspeak
First of all you need to create a thingspeak account from https://thingspeak.com/ then you can log in your thingspeak account then go to channel ,my channel and create a channel as you want.
It is clearly explained in video section
Coding
#include <ESP8266WiFi.h>
#include <DHT.h>
#include <ThingSpeak.h>
const char *ssid = "black hat";
const char *pass = "rabin@1234";
DHT dht(D5, DHT11);
WiFiClient client;
long myChannelNumber = 1115593;
const char myWriteAPIKey[] = "4W0SZYJQK8UFX7QM";
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
WiFi.begin(ssid, pass);
while(WiFi.status() != WL_CONNECTED)
{
delay(200);
Serial.print("..");
}
Serial.println();
Serial.println("NodeMCU is connected!");
Serial.println(WiFi.localIP());
dht.begin();
ThingSpeak.begin(client);
}
void loop() {
// put your main code here, to run repeatedly:
float h = dht.readHumidity();
float t = dht.readTemperature();
Serial.println("Temperature: " + (String) t);
Serial.println("Humidity: " + (String) h);
ThingSpeak.writeField(myChannelNumber, 1, t, myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber, 2, h, myWriteAPIKey);
delay(2000);
}
YOUTUBE LINK