# **Display Temperature and Humidity on ThingSpeak using Arduino and DHT11** Tutorial written by Madhavi Nair This tutorial shows how to sense and display temperature and humidity. The DHT11 sensor is interfaced to the popular Arduino Uno rev3 and data is then sent over internet via the Arduino Ethernet shield to ThingSpeak. ## Goal of the tutorial The goal of this tutorial is to showcase the ease in sensing temperature and humidity and sending it via internet to be displayed in real time on the web. The idea is made possible due to the versatility of the Arduino boards, its libraries and vast community contribution. ## Hardware required 1) Arduino Uno rev3 2) Arduino Ethernet Shield 3) DHT11 4) Breadboard and connecting wires ## Other things An account on https://thingspeak.com/ 1) Create a new channel in your account and set the fields to display the parameters. ## Connection Diagram Below is the connection diagram for reference. For ease of understanding the interface is as explained below. Pin 1 of the DHT11 pin is connected to A0 of the Arduino Uno. Pin 2 of the DHT11 pin is connected to Vcc (5V). Pin 3 of the DHT11 pin is connected to GND. The Arduino Ethernet board is mounted on top of the Arduino Uno rev3 via the header pins. ![](https://i.imgur.com/d1me7sG.jpg) Arduino UNO to be connected to the computer. Ethernet cable to be plugged into the Arduino Ethernet shield board. ![](https://i.imgur.com/BBV3C4F.png) ## Settings In secrets.h file you will have to fill in the following fields:- 1) SECRET_MAC (mentioned at the back of the Ethernet board) 2) SECRET_CH_ID (Can be found at ThingSpeak under Channel Settings) 3) SECRET_WRITE_APIKEY (Can be found at ThingSpeak under API Keys) In EthernetDisplay.ino file you will need to fill in the following details:- 1) IPAddress ip 2) IPAddress myDns ## Code The code here makes use of the popular libraries 1) DHT11 library 2) ThingSpeak library *To install the above libraries go to Tools/Manage Libraries. Search for the above mentioned libraries and install them.* 3) This piece of code is available in Arduino IDE in File/Examples/Thingspeak/ArduinoEthernet/Writemultiplefields. I have made minor modifications to the code and also incorporated the code for DHT11 interface. ```python= #include "ThingSpeak.h" #include <Ethernet.h> #include "secrets.h" #include <DHT.h> #include "DHT.h" #define DHTPIN A0 // Connected to pin A0 #define DHTTYPE DHT11 // we are using the DHT11 sensor DHT dht(DHTPIN, DHTTYPE); byte mac[] = SECRET_MAC; // Set the static IP address to use if the DHCP fails to assign IPAddress ip(XXX,XXX,XXX,XXX); IPAddress myDns(192,168,0,1); EthernetClient client; unsigned long myChannelNumber = SECRET_CH_ID; const char * myWriteAPIKey = SECRET_WRITE_APIKEY; // Initialize our values float number1 = 0; // assigned for temperature float number2 = 0; // humidity void setup() { Ethernet.init(10); // Most Arduino Ethernet hardware Serial.begin(115200); //Initialize serial dht.begin(); // start the Ethernet connection: Serial.println("Initialize Ethernet with DHCP:"); if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); // Check for Ethernet hardware present if (Ethernet.hardwareStatus() == EthernetNoHardware) { Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); while (true) { delay(1); // do nothing, no point running without Ethernet hardware } } if (Ethernet.linkStatus() == LinkOFF) { Serial.println("Ethernet cable is not connected."); } // try to congifure using IP address instead of DHCP: Ethernet.begin(mac, ip, myDns); } else { Serial.print(" DHCP assigned IP "); Serial.println(Ethernet.localIP()); } // give the Ethernet shield a second to initialize: delay(1000); ThingSpeak.begin(client); // Initialize ThingSpeak } void loop() { // set the fields with the values ThingSpeak.setField(1, number1); ThingSpeak.setField(2, number2); // write to the ThingSpeak channel int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); if(x == 200){ Serial.println("Channel update successful."); } else{ Serial.println("Problem updating channel. HTTP error code " + String(x)); } // Read values from DHT11 float h = dht.readHumidity(); float t = dht.readTemperature(); // Read temperature as Celsius (the default) // Printing the values in Serial Port Serial.print(t); Serial.print('\n'); Serial.print(h); Serial.print('\n'); number1 = t; number2 = h; delay(20000); // Wait 20 seconds to update the channel again } ```` ## Data as seen on the web ![](https://i.imgur.com/yHmFDWD.png)