# Examinationsuppgift
Tutorial written by Mona Taji.
This tutorial shows how to connect a dht11 sensor and Arduino Ethernet, send data temp and humidity over to ThingSpeak(Platform).
The first part will show you how to get things up and running, the other part tried to explain why and what certain things of the code does.
# Objectives
Temperature and humidity is of interests in many situations. First of all, I want to explain what is humidity sensor.
The DHT11 or temperature and humidity sensor is a basic, low-cost digital . It uses a capacitive humidity sensor and a thermistor to measure the rounding air, and eject a digital signal on the data pin.
Although ,Humidity sensors vary widely in size and functionality.In this project I have an existing Arduino system setup it measuring humidity in my room and connect Arduino Ethernet device and by using ThingSpeak platform you can visualize, and analyze live data in cloud.
# Material needed

DHT11 Digital Temperature Humidity Sensor

Arduino (Computing Platform)

Arduino Ethernet
Also you need : Expansion board ,few connection cables and a breadboard kan be useful
# Computer setup
The Arduino Integrated Development Environment (IDE) is an official software (for Windows, macOS, Linux) that is written in functions from C and C++. It is used for writing, compiling and uploading the code in the Arduino Device.it easy to install and user friendly also this software that is an open source and available to install and start compiling the code. Because of those advantage I prefer to use Arduino IDE in my project.
# Putting everything together
The DHT11 contains 3 pins, which are listed in the table below(pins identification are from left to right):
Pin Identification and Configuration:
| PIN NAME | Description |
| -------- | -------- |
| VCC | Power supply 5.5V |
| DATA | Outputs both Temperature and Humidity through serial Data |
| Ground | Connected to the ground |
The first step the DHT11 of is connected to the expansion board. The dht11 is connected to pin 2, 5v and ground, all three next to each other. The board is connected to laptop and the we should to sure connection is correct and working . Then we can start to write code in Arduino IDE. After upload the code you can go to tools and check which port and board you are connected. Then go to tools serial monitor you can sure your code has output and work correctly.
The second step is connect the Ethernet device to Arduino, first of all we have to write mac address in back of Arduino Ethernet because we need to write those number to our code for configuration.
Then we can connect the two devices (Arduino and Arduino Ethernet), but be careful, we must sure all pins are in place The last part is to connect with router then we can go to next steps which it is coding.
The third part is connection to our platform(ThingSpeak).on this part we should install ThingSpeak library in Arduino IDE program. The instruction is go to toolsmanage libraries and find the ThingSpeak library and install.
The important part is we must show different data in Thnigspeak the we should follow the right instruction. The instruction is fileexamplesThingspeakArduino EthernetWrite Multiple fields.
The last part you can combine those two different code and create one code. Then it ready to upload and run your project.
Finally, we have to remember that copy APIKEY and ID form the ThnigSpeak to Secrets.h file in our program.


# Plattform
There are many platform exist to use and analyz data. But ThingSpeak is very easy to work and compatible to my project and software(Arduino IDE).
ThingSpeak server is an open data platform and an open-source IoT application ,API( application programming interface ) for the Internet of Things that enables you to collect, store, analyze, visualize, and act on data from sensors.
# The code
```
// include the libraries
#include "DHT.h"
#include "ThingSpeak.h"
#include <Ethernet.h>
#include "secrets.h"
#define Type DHT11 //const variable
byte mac[] = SECRET_MAC;
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,168,1,111);
IPAddress myDns(192, 168, 0, 1);
EthernetClient client;
unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;
// Initialize our values
int Pin=2; //connect to pin 2 in Arduino
DHT DHT1(Pin,Type); // create obj
float humidity;
float f;
float c;
int Time=500;
int delay_time=2000; //delay time to showing data
---
void setup() {
DHT1.begin();
delay(Time);
Ethernet.init(10); // Most Arduino Ethernet hardware
Serial.begin(115200); //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); // 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() {
humidity=HT.readHumidity();
c=DHT1.readTemperature(); //read temperature function
f=DHT1.readTemperature(true); // read temperature function if it was Fahrenheit
Serial.print("Humidity:"); // print Humidity word
Serial.print("Temerature :"); // print Temperature word
Serial.print(c); // print Temperature in centigrade
Serial.print("c");
Serial.print(f); // print Temperature in Fahrenheit
Serial.println("f");
delay(delay_time);
// set the fields with the values for ThingSpeak
ThingSpeak.setField(1, humidity);
ThingSpeak.setField(2, tempc);
// 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));
}
// change the values
delay(20000); // Wait 20 seconds to update the channel again
}`
```
"secrets.h"
// 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 {0xA8, 0x61, 0x0A, 0xAE, 0x71, 0x12}
#define SECRET_CH_ID 1249614 // replace 0000000 with your channel number
#define SECRET_WRITE_APIKEY "Q9LU3LN3J2KMHSW2" // replace XYZ with your channel write API Key
---
# Transmitting the data
After the code is uploaded in Arduino IDE data will be transfer to ThingSpeak platform that I tried to show you. The blow picture shows different graph for each minute.


# Presenting the data
According the below picture you can find different graphs that ThingSpeak create less than one min.




# Final thoughts
”Learning by Doing” as my teacher says always and I follow his instruction. Throughout this project, I have learned a lot about Arduino hardware and coding ,ThingSpeak . I got a better understanding on how things are run around me.
finally,The link below shows you this project.
[https://youtu.be/Qn0OZyC1Z1w](https://)