# Temperature and humidity check ### What are we going to do and why are we going to do it? We are going to ascertain the temperature and humidity in selected location by usin a DHT11 sensor. This is a simple guide that you can use to show the input from a DHT11 sensor from an Arduino UNO. We'll get the information through the Arduino UNO paired to an ethernet shield and publish the result on ThingSpeak.com. ### List of all the supplies you'll need: * Arduino UNO * Ethernet shield * Breadboard * Three power cords (any color would work but I'll recommend a black one for ground, a red one for plus and any another pretty color for signal) * DHT11 temperature and humidity sensor * Network cable * USB micro cable * Router * Last but not least: a computer ### Estimated time: Approximately 60 minutes total. Read the instructions to get an overview of the project: 10 minutes. Pick out the components: 10 minutes. Prepare the software: 20 minutes. Assamble the components: 10 minutes. Fix the code: 10 minutes. ### Step one: *Preparation of the hardware* Make sure you got all the supplies needed. These components is included in the Arduino UNO sterter kit but I'll link each component separately below: [:link:]https://www.electrokit.com/produkt/utvecklingskort-atmega328p-uno-kompatibelt-2/ [:link:]https://www.electrokit.com/produkt/ethernet-shield-byggsats/ [:link:]https://www.electrokit.com/produkt/kopplingsdack-840-anslutningar/ [:link:]https://www.electrokit.com/produkt/temp-fuktsensor-dht11/ [:link:]https://www.electrokit.com/produkt/kopplingstrad-byglar-for-kopplingsdack-mjuka-65st/ [:link:]https://www.electrokit.com/produkt/patchkabel-u-utp-cat6a-1m-gra/ [:link:]https://www.electrokit.com/produkt/usb-kabel-a-hane-micro-b-hane-15cm/ ### Step two: *Preparation of the software* Make sure you have Arduino IDE (Arduino 1.8.13) installed on your machine with following libraries included: "ThingSpeak.h", <Ethernet.h>, "DHT.h" and "Secret.h". Create an account at ThingSpeak.com to show your final results. Link to download Arduino IDE: [:link:]https://www.arduino.cc/en/software Link to GitHub. Download zipfile: [:link:]https://github.com/mathworks/thingspeak-arduino Link to ThingSpeak. Create an account and sign in: [:link:]https://thingspeak.com/login Go to your Arduino IDE environment. Click "Tools" -> "Manage Libraries" and search for dht and install DHT sensor library. Then go to "Sketch" and then "Include library" and "Add Zip Library". Then go to "File" -> "Example" -> "ThingSpeak" -> "ArduinoEthernet" -> "WriteMultipleFields". Click "Open". ### Step three: *Make the code useful* Now you got some code to work with! Go to the "Secret.h"-file and add your personal API-Key you get from ThingSpeak below the tab "API.Keys". Then get your channel number which stands below the name you created (in my case "Jessicas place"). To make the code work you'll have to #include DHT.h in your main file. This is because the standard code only will give us random numbers instead of the actual value. You also need to define the pins you'll be using like this: #define DHTPIN 2 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); 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); Also add you Arduino MAC address. I'll insert my modified code down below: ``` /* WriteMultipleFields Description: Writes values to fields 1,2,3 and 4 in a single ThingSpeak update every 20 seconds. Hardware: Arduino Ethernet !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! Note: - Requires the Ethernet library ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. For licensing information, see the accompanying license file. Copyright 2018, The MathWorks, Inc. */ // Modified by Jessica Thyselius 2020-12-02 #include "ThingSpeak.h" #include <Ethernet.h> #include "secrets.h" #include "DHT.h" #define DHTPIN 2 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); byte mac[] = SECRET_MAC; // 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; unsigned long myChannelNumber = SECRET_CH_ID; const char * myWriteAPIKey = SECRET_WRITE_APIKEY; // Initialize our values float temperature; float humidity; void setup() { Ethernet.init(10); // Most Arduino Ethernet hardware Serial.begin(9600); //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() { // reads temperature in celcius float temperature = dht.readTemperature(); // reads humidity in % float humidity = dht.readHumidity(); // 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)); } delay(20000); // Wait 20 seconds to update the channel again } ``` ### Step four: *Assemble the components* ![](https://i.imgur.com/xPib4qr.jpg) 1. Carefully attach the ethernet shield to your Arduino UNO. Beware of the metal pins so they don't bend. ![](https://i.imgur.com/13l9tfD.jpg) 2. Place the bread board on the right side of the Arduino UNO. 3. Attach the sensor to the bread board. (I choose to place it in line 10, 11 and 12.) ![](https://i.imgur.com/0dBffDd.jpg) 4. Attach the whatever-chosen-pretty-color-cable to digital port 2 on the Arduino UNO and then connect it to the sensor by the left metal pin. (My cable is green, see picture). ![](https://i.imgur.com/Ux2nbpy.jpg) 5. Plug in the red cable to port "5 V" on the Arduino UNO and then connect it to plus to the sensor, which is the middle metal pin. 6. Plug in the black cable to GND (Ground) socket and then connect it to ground on the sensor, which is the right metal pin. ![](https://i.imgur.com/eLsNipX.jpg) 7. Plug in the USB 3 cable to the Arduino UNO and then to your computer. 8. Plug in the network cable to the socket on the ethernet shield and then connect it to your router. ![](https://i.imgur.com/3g0Cg8R.jpg) ![](https://i.imgur.com/u55xT8Y.png) 9. Go to Arduino IDE and klick "upload". ### Wiring Diagram: ![](https://i.imgur.com/fXisnOu.jpg) 10. Go to ThingSpeak.com to see your result like this: (Make the page public if you want to share your output with others.) ![](https://i.imgur.com/An4Ji0W.png) Good luck!