ThingSpeak is an IoT platform that helps us to collect sensor values from various nodes like we use NodeMcu and puts them in a graphical manner and provides many options like sending us email or SMS when if a certain condition is met.
In this tutorial, How to send DHT11 (Temperature and Humidity Sensor) data to Thingspeak.
CONNECTIONS :
ARDUINO DHT11
5v - 5v
Gnd - Gnd
D4 - Data pin
PROCEDURE :
- Create a account in Thingspeak.
- Click Newchannel and create a channel with two fields and save channel.
- Then in the tab API Keys we will find the Channel ID, Write api Key .
- Download the Thingspeak library from https://github.com/mathworks/thingspeak-arduino.
- Download the Dht library from https://github.com/adafruit/DHT-sensor-library.
- While compling if it shows Adafruit_Sensor.h missing download it from https://github.com/adafruit/Adafruit_Sensor.
- and paste it in the library folder of Arduino(It will be in C:\Program Files (x86)\Arduino\libraries).
Program for NodeMcu is given below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | #include <DHT.h> #include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ThingSpeak.h> #define DHTPIN D4 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); const char* ssid = "Username"; //Change with your Username const char* password = "Password"; // Change with your Password WiFiClient client; unsigned long myChannelNumber = ChannelId; //Your channel Id const char * myWriteAPIKey = "Your Wirite api key"; //Write api key uint8_t temperature, humidity; void setup() { Serial.begin(115200); dht.begin(); delay(10); // Connect to WiFi network Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); // Print the IP address Serial.println(WiFi.localIP()); ThingSpeak.begin(client); } void loop() { static boolean data_state = false; temperature = dht.readTemperature(); humidity = dht.readHumidity(); Serial.print("Temperature Value is :"); Serial.print(temperature); Serial.println("C"); Serial.print("Humidity Value is :"); Serial.print(humidity); Serial.println("%"); // Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different // pieces of information in a channel. Here, we write to field 1. if( data_state ) { ThingSpeak.writeField(myChannelNumber, 1, temperature, myWriteAPIKey); data_state = false; } else { ThingSpeak.writeField(myChannelNumber, 2, humidity, myWriteAPIKey); data_state = true; } delay(30000); // ThingSpeak will only accept updates every 15 seconds. } |
const char* ssid = "Username";
const char* password = "Password";
- Change the above lines with your Wi-Fi Username and Password.
- Make sure that you select the correct COM port.
unsigned long myChannelNumber = ChannelId;
const char * myWriteAPIKey = "Your Wirite api key";
- Change it with your Channel Id and Write api key.
- Then upload the program into NodeMcu
- Make sure that you provide a good Internet connection using the Wi-Fi.
See my vedio below to get a clear idea
- ThingSpeak will accecpt values only after a break of 15 seconds.
Data will be displayed like a graph shown below

ANDROID :
- Download Thingviewfree app from play store and install it.
- To see the channel you have to make the channel as public.
- To do so go to sharing tab and check the Share channel view with everyone in Channel sharing settings.
- Then open the app and follow the slideshow given below
Note:
To use ubidots platform which is more facilities than thingspeak check this
Thankyou
SHARE THIS!!!
1 Comment
Cleanmymac
(March 16, 2018 - 6:47 pm)This is good. Cheers!