ESP8266 Wi-Fi transceiver is one of the most used module for IoT based Applications. To we will use this module to connect with ThingSpeak IoT cloud Platform.
In this project, we are going to send Temperature and Humidity sensor data to Thingspeak using DHT11. By this method we can monitor our DHT11 sensor’s temperature and humidity data over internet using ThingSpeak IOT server. And we can view the logged data and graph over time in its website. It is made using ESP8266 NodeMCU and DHT11 sensor. NodeMCU reads the current temperature and humidity from DHT11 and sends it to ThingSpeak server for live monitoring from anywhere in the world. We previously used ThingSpeak with Raspberry Pi and ESP32 to upload the data on cloud.
ThingSpeak is an open data platform for monitoring your data online. In Thingspeak channel you can set the data as private or public according to your choice. ThingSpeak takes minimum of 15 seconds to update your readings. Its a great and very easy to use platform for building IOT projects.
- DHT11 Temperature and Humidity Sensor
- Jumper Wires
Connect NodeMCU and DHT11 as mentioned below:
Step 1: ThingSpeak Setup for Temperature and Humidity Monitoring
For creating your channel on ThingSpeak you first need to sign up on ThingSpeak. In case if you already have account on ThingSpeak just sign in using your id and password.
For creating your account go to www.thinspeak.com
Click on signup if you don’t have account and if you already have account click on sign in.
After clicking on signup fill your details.
After this verify your E-mail id and click on continue.
Step 2: Create a Channel for Your Data
Once you Sign in after your account verification, Create a new channel by clicking “New Channel” button
After clicking on “New Channel”, enter the Name and Description of the data you want to upload on this channel. For example I am sending DHT11 sensor data (temperature and humidity), so I named it as “DHT11”.
Enter the name of your data ‘Temperature’ in Field1 and ‘Humidity’ in Field2. If you want to use more than one Field you can check the box next to Field option and enter the name and description of your data.
After this click on save channel button to save your details.
Step 3: API Key
To send data to ThingSpeak, we need an unique API key, which we will use later in our code to upload the Temperature and Humidity to ThingSpeak Website.
Click on “API Keys” button to get your unique API key for uploading DHT11 sensor data.
Now copy your “Write API Key”. We will use this API key in our code.
Programing NodeMCU with Arduino IDE
To program NodeMCU with Arduino IDE go to File–>Perferences–>Settings.
Enter http:// arduino.esp8266.com/stable/package_esp8266com_index.json into ‘Additional Board Manager URL’ field and click ‘Ok’.
Now go to Tools > Board > Boards Manager.
In Boards Manager window, Type esp in the search box, esp8266 will be listed there below. Now select latest version of board and click on install.
After installation is complete, go to Tools >Board >and select NodeMCU 1.0(ESP-12E Module). Now you can program NodeMCU with Arduino IDE.
Programming ESP8266 for uploading data to ThingSpeak
Complete code is given at the end of this tutorial. Upload it in ESP8266 NodeMCU. If you successfully upload your program, Serial monitor will look like this:
After this navigate to your Thingspeak page and open your channel in ThingSpeak and output will be shown as below.
Also check our all the ThingSpeak related tutorial here.
String apiKey = "Your API KEY"; // Enter your Write API key here
const char *ssid = "WiFi Name"; // Enter your WiFi Name
const char *pass = "WiFi Password"; // Enter your WiFi Password
const char* server = "api.thingspeak.com";
#define DHTPIN 4 // GPIO Pin where the dht11 is connected
DHT dht(DHTPIN, DHT11);
Serial.println("Connecting to ");
while (WiFi.status() != WL_CONNECTED)
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t))
Serial.println("Failed to read from DHT sensor!");
String postStr = apiKey;
postStr += String(t);
postStr += String(h);
postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
Serial.print(" degrees Celcius, Humidity: ");
Serial.println("%. Send to Thingspeak.");