In this project, we will use a DHT11 Temperature and Humidity sensor and display the values on the Arduino IoT Cloud. The project is simple and it won’t take very long to build.
Step 1: Wire the circuitPlace the Board and the sensor on the breadboard.
Now connect the jumper wires to the DHT11 sensor. If you look closely on the sensor the 3 pins are marked, telling you where each pin should be connected. The pin marked + should be connected to the 5V pin on the Arduino, – should be connected to ground, s is the signal pin, and should be connected to digital pin 7 on your Arduino board.
To get started with this step, you will need some very basic knowledge of the Arduino IoT Cloud service. If you have built any previous project using the service, then don’t worry, you know all that you need to know.
If you are new to the Arduino IoT Cloud, then take some time to read through the Getting started page and you will be good to go. There are also a bunch of tutorials available if needed.
In the cloud, you need to create a new Thing, then configure your device and network.
You should then add two “Read Only”, Float Variables named “temperature” and “humidity”
Now, you will need to create a Dashboard to see your values from your DTH11 sensor. Go to the Dashboards section, and build a new Dashboard.
Inside, create two widgets: percentage and gauge. Then you need to link them:
- Gauge -> temperature variable
- Percentage -> humidity variable
They will for now be empty, since we have not yet uploaded the sketch to our board, which we will do in the next step.
Step 3: CodeThe code for this project is very simple, we just need to read the values from the sensor, and tie them to the variables that we just linked to widgets in the previous step.
The DHT11 sensor requires a library to be used, so we’ll add that in the beginning of the code as well. Once the library is added we also need to declare which pin on the Arduino board it is connected to, in our case, it is pin 7.
If you don’t want the code run through, you can find the full code at the end of this step.
We do all this in two lines of code in the Thing -> Code tab, you should include the DHT11’s library directly beneath the inclusion of the "thingProperties.h" file.
#include <EduIntro.h>
DHT11 dht11(D7);
The only other thing you need to do is to read the data from the sensor. Do this by adding these lines of code inside the loop function.
dht11.update();
temperature = dht11.readCelsius();
humidity = dht11.readHumidity()
The full sketch can be found below, at the end of the page.
ConclusionOnce you have uploaded the sketch, you can see the readings update live on the Dashboard page, in your browser, or in the Arduino IoT Cloud Remote app on your phone.
Enjoy your simple IoT-device!
Comments
Please log in or sign up to comment.