#thingspeak #DHT11 #DHT22 #Arduino Uno IoT <h1>Thingspeak cloud IoT platform , sensor DHT11 and Ethernet Shield</h1> <p>Tutorial written by Nataliya Lisjo, student ECUtbildning Software developer in Industrial IoT, december 2020</p> <p></p> <i>This tutorial shows how to connect Arduino Uno P3 to DHT11 and Ethernet Shield and send data of the temperature and humidity over internet to Thingspeak.com , useful for newstartar i IOT.</i> I will show you how to get things up and running. *image what expected in the result* ![](https://i.imgur.com/oFss5Ww.png) ThingsSpeaks picture update in real time <iframe width="450" height="260" style="border: 1px solid #cccccc;" src="https://thingspeak.com/channels/1244090/charts/1?bgcolor=%23ffffff&color=%23d62020&dynamic=true&results=60&type=line&update=15"></iframe> add code to your weside: ![](https://i.imgur.com/nQtlZEC.png) # *<h2>Hardware material needed</h2>* <p>Arduino UNO </p> <p>Arduino Ethernet Shield <p>Temperature and humidity sensor DHT11 or DHT22</p><p>Breadboard can be useful, but not absolutely necessary.</p> <h2> Arduino UNO </h2> ![](https://i.imgur.com/ACMDZGM.jpg) <h2>Arduino Ethernet Shield</h2> ![](https://i.imgur.com/ANlSYJb.jpg) <h2>Temperature and humidity sensor DHT11(3pin) and DHT22(4pin)</h2> <p>The DHT11 only worked with positive integers. The DHT22 supports decimals and negative values. There are two versions of the DHT11 and DHT22, 3pins or 4 pins, make sure you use correct datasheet. The sensor needs power, ground and a data pin to send sensor data. ![](https://i.imgur.com/pVQsrO3.jpg) <p> - VCC - red wire Connect to 3.3 - 5V power. Sometimes 3.3V power isn't enough,in this case try 5V power. - Signal-data out - yellow/white wire - Not used-Not connected - Ground - black wire </p> # *<h2>Schema </h2>* <p>Putting everything together. -put Arduino UNO and Arduino Ethernet Shield together pin with pin , be careful with them !!! ![](https://i.imgur.com/kFMxsI0.jpg) **The DHT11 connecting: - to pin 5 (white, yellow); - 5v (red) - to Arduino uno. - ground (black)- to Arduino uno; - The Arduino Uno is connected to the pc by USB cabel; - ethernet cabel </p> ![](https://i.imgur.com/53V5P3Q.jpg) ![](https://i.imgur.com/zDTbWTl.png) # *<h2>Computer setup</h2>* # <h2> Thingspeak.com -Cloud plattform</h2> <p> ThingSpeak is an IoT analytics platform service that allows you to aggregate, visualize, and analyze live data streams in the cloud. You can send data to ThingSpeak from your devices, create instant visualization of live data, and send alerts. Has free account with limited service available : * Messages 3,000,000; * Channels-4. Create Accout in ThingSpeak.com create Channel. It has own ID , which we will use in Code bellow ![](https://i.imgur.com/bvHfcX7.png) ![](https://i.imgur.com/F0L43pF.png) Also, you need to generete and note down your Write API Key from ThingSpeak Channel and paste it in the code.</p> ![](https://i.imgur.com/bZNpykk.png) # <h2>Download programm Arduino IDE 1.6.5 or higher</h2> from https://www.arduino.cc/en/software * control that you have right BOARD : Arduino UNO * SERIAL MONITOR -help you to see what happened in your device. ![](https://i.imgur.com/nlP2DvV.png) Install ThingSpeak library package in your Arduino IDE programm</p> ![](https://i.imgur.com/oHxbzAN.png) ![](https://i.imgur.com/bm35jRe.png) <p> You can find some code exemples in this Library , which connect Arduino och send data to Thingspeak platform. You can test your internet connection with them . For sensor DHL11, you must follow programm code below </p> ![](https://i.imgur.com/LJxvBvQ.png) <p>The code for connecting DHT11 Humidity Sensor with Ethernet Shield and ThingSpeak API is given below. You have to change the code in it : * add your Network’s MAC adress ; * add Channel ID from ThingSpeak; * add your Write API Key from ThingSpeak Channel and paste it in the code insted of XYZ.</p> ![](https://i.imgur.com/H4mfol5.png) # *<h2>Code</h2>* <p> This code combinated from DHT.h and Thingspeak.h library </p> ``` //write_DHT11 //Nataliya Lisjo//.Nat //Description: Writes values from sensor DHT11 to fields 1,2 in a single channel ThingSpeak update every 20 seconds. #include "ThingSpeak.h" #include "DHT.h" #include <Ethernet.h> #define DHTPIN 5 //your pin5 that you connected DHT #define DHTTYPE DHT11 byte mac[] = { 0x00, 0xA0, 0x0E, 0x00, 0xDF, 0x0E}; //your MAC adress from PC IPsettings unsigned long myChannelNumber = 1111111; //write your channel number const char * myWriteAPIKey = "XYZ"; //replace XYZ with your channels write API Key // Set the static IP address to use if the DHCP fails to assign IPAddress ip(192, 168, 0, 177); IPAddress myDns(192, 168, 0, 1); EthernetClient client; DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(115200); 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"); // try to congifure using IP address instead of DHCP: Ethernet.begin(mac, ip, myDns); } else { Serial.print(" DHCP assigned IP "); Serial.println(Ethernet.localIP()); } delay(1000); ThingSpeak.begin(client); // Initialize ThingSpeak } void loop() { float t = dht.readTemperature(); float h = dht.readHumidity(); // 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)); } //---------Print on seriall monitor------------------- Serial.println("======================================"); Serial.println("Weather condictions"); Serial.print("Temperature= "); Serial.print(t); Serial.println(" C"); Serial.print("Humidity= "); Serial.print(h); Serial.println(" %"); Serial.println(); // on ThingSpeak channel ThingSpeak.setField( 1, t); ThingSpeak.setField( 2, h ); delay(20000);//Wait 20 seconds to update } ``` # *<h2>Usfull information</h2>* ![](https://i.imgur.com/M0LylxU.png) Sometimes Arduino Ide programm has problem to find Board port . Install CH340G driver for COM port http://www.wch.cn/download/CH341SER_ZIP.html I ThingSpeak channal settings you can : * add channel location ; * add widgets - visualizate grafik; * take it to your webside. ![](https://i.imgur.com/MXYqZfc.png) IoT sends sensordata to the internet. We don't need to set up our own webserver. Right now you can find several cloud services. ThingSpeak.com only one of them. Hear is the list of other available: (https://dzone.com/articles/12-iot-platforms-for-building-iot-projects) <!-- hitwebcounter Code START --> <!-- hitwebcounter Code START --> <a href="https://www.hitwebcounter.com" target="_blank"> <img src="https://hitwebcounter.com/counter/counter.php?page=7722078&style=0038&nbdigits=7&type=page&initCount=1" title="Total Website Hits" Alt="Web Hits" border="0" /></a> <a href="https://info.flagcounter.com/LDNl"><img src="https://s11.flagcounter.com/count2/LDNl/bg_FFFFFF/txt_000000/border_CCCCCC/columns_2/maxflags_10/viewers_0/labels_0/pageviews_0/flags_0/percent_0/" alt="Flag Counter" border="0"></a>