<h1>DHT Temperature reading to internet.</h1>
<p>Hello everyone, this is a guide on how to build, code and send data to the internet with an <b>Arduino Uno</b> using a DHT11 sensor.
This tutorial is made by Johan.A </p>
<a href="https://github.com/j-azon">J-Azon github</a>
<h2> Components </h2>
<p>
<b>Three</b> Cables.(Black, Red and Yellow)<br>
<b>One</b> resistance(100OHm "Brown - Black - Brown - Gold").<br>
<b>One</b> Breadboard.<br>
<b>One</b> Arduino Uno with Ethernet shield.<br>
<b>One</b> DHT11 Sensor(3-pin).<br>
</p>

<p>In my case i will use a Black(ground), Red(5v) and Yellow(Datareader) cable.<br>
The resistance I will use for this build is a Brown,Black,Brown and Gold wich is 100Ohm.<br>
The blue square is the 3-Pin Dht 11 sensor.</p>
<h3>
The build
</h3>

<p>
As you can see the Yellow cable is connected to the left pin of the DHT to digital pin 7 on the arduino(This is for reading the DATA)<br>
The Red cable is connected to the middle pin of the DHT to "5V" on the Arduino(This is for giving power to the DHT)<br>
The Black cable is connected to a resistance from the right pin and then to the GND on the same side as "5V - Red cable" (This way we use the resistance before grounding the negative pole.)<br>
<br>
<h3>
Connecting the pieces
</h3>
<p>
We will begin with putting the DHT on the breadboard.<br>
Next we have to put a 100Ohm resistance from the right pin on the the DHT, and connect it a bit right on the dashboard for easier access.<br><br>
Now we will take the Black cable and connect it to the same line as the Resistance and to the GND on the arduino, as shown in the picture above.<br><br>
Connect the Red cable to the middle pin of the DHT and to the "5V" outlet on the arduino, also as shown in the picture above. <br><br>
Finally we will connect the Yellow cable to the Digital pin 7 of the arduino and to the LEFT pin of the DHT, also as shown in the picture above. <br>
</p>
<h4>
Managing libraries
</h4>
<p>
So for this build we will use two specific libraries, DHT and ThingSpeak. To get these two we need to access our libraries.
To do so we need to press <b>"Tools" -> "Manage libraries"(or press CTRL + SHIFT + i on the keyboard to use to quick command).</b>
</p>

<p>
When we have opened the window to install libraries we will search for DHT and chose the one as shown in the picture(The one made by <b>"Adafruit"</b>).
Just press install and it will place it self in the right folders.
</p>

<p>
For the next one we will need is the ThingSpeak one, like before open "manage libraries" then search for "ThingSpeak" and install the one made by <b>"MathWorks"</b>.
Just press install and it will place it self in the right folders.
</p>
<h4>
The Code
</h4>
<p>
This is for the "Main.ino" file.
</p>
```
/*
dhtonline.ino
Description: Writes a value to a channel on ThingSpeak every 20 seconds.
Hardware: Arduino Ethernet, Ethernet Cable, 3 cables, 1 DHT and 1 resistance of 100ohm
!!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!!
Note:
- Requires the Ethernet library*/
#include "ThingSpeak.h" // required for online server
#include <Ethernet.h> // required for Ethernet shield
#include "DHT.h" // required for DHT sensor
#include "secrets.h" // required to put in "ip/DNS"
#define DHTPIN 7 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 11
byte mac[] = SECRET_MAC;
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(xx, xx, xx, xx); //Set your ipv4 address
IPAddress myDns(xx, xx, xx, xx); //Set your DNS server address
//!!-REMEMBER DO NOT SHARE YOUR IP, DNS OR API KEY-!!
EthernetClient Client;
DHT dht(DHTPIN, DHTTYPE);
unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;
int number = 0;
void setup() {
Serial.begin(9600);
Serial.println(F("DHTxx test!"));
dht.begin(); // Initialize DHT
Ethernet.init(10); // Most Arduino Ethernet hardware
Serial.begin(9600); //Initialize serial
// 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); // does nothing because there is 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() {
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
// Writes pieces of information in a channel to ThingSpeak.
// There are up to 8 fields in a channel, allowing you to store up to 8 different values.
int x = ThingSpeak.writeField(myChannelNumber, 1, t, myWriteAPIKey);
if(x == 200){
Serial.println("Channel update successful.");
}
else{
Serial.println("Problem updating channel. HTTP error code " + String(x));
}
// change the value
number++;
if(number > 99){
number = 0;
}
delay(20000); // Waits 20 seconds to update the channel again
}
```
<p>
This is for the "Secrets.h" file
</p>
```
// Use this file to store all of the private credentials
// and connection details
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
#define SECRET_MAC {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
#define SECRET_CH_ID 0000000 // replace 0000000 with your channel number
#define SECRET_WRITE_APIKEY "XYZ" // replace XYZ with your channel write API Key
```
<h5>
Finding your IP, DNS and API key
</h5>
<p>
To find your IP and DNS i want you to press <b>"Windows + r"</b> and then type in <b>"CMD"</b> after you have gotten the Command prompt window open you just type in <b>"ipconfig/all"</b><br>
Here you will find mostly all the Addresses in your internet.<br><br>
Write the IPv4 Address into <b>"IPadress ip"</b><br>
Write the DNS Server address into <b>"IPadress DNS"</b><br>
</p>
<p>
To get your Channel ID and API Write Key, Go into <b><a href="https://thingspeak.com">ThingSpeak.com</a></b> and create an account.<br>
After that you will want to create a new <b>Channel</b>, from here we can enter <b>API Keys</b>.<br><br>
Your channel ID can be found on the top of the screen wich says <b>"Channel ID:0000000"</b> copy this ID number and put it in the <b>"Secrets.h"</b> in the row "#define SECRET_CH_ID 0000000"
and copy the <b>"Write API Key"</b> and place it in "#define SECRET_WRITE_APIKEY "XYZ - HERE""<br>
</p>
<h6>
Finished!
</h6>
<p>
Now all you need to do is upload the code to the Arduino, plug in power and Ethernet and it will start sending the data to your newly made Channel on ThingSpeak.<br><br>
This is how it can look after a little tidying up!<br>

I hope this tutorial was helpful for those of you who wants to create a Digital Thermometer.
Thank you for following this tutorial and good luck! (:<br>
<a href="https://github.com/J-Azon">This is the link for my github aswell!</a>
</p>