Beginner guide to Arduino IoT cloud platform

This is a beginner guide tutorial which shows how to use the Arduino IoT cloud platform to display humidity and temperature sensor data on the web using Arduino IoT cloud platform. For this tutorial we will be using the DHT11 humidity and temperature sensor module and the NodeMCU ESP8266 WiFi module. This DHT11 sensor module is connected to the NodeMCU ESP8266 WiFi capable module on GPIO pin 13(D7). The data is read by the NodeMCU ESP8266 and then sent to the Arduino cloud where the humidity and sensor data are displayed on the web dashboard as shown below.

Arduino IoT platform showing dashboard

 The first thing we need to do is to connect the DHT11 sensor module to the NodeMCU. The following circuit drawing shows how to connect them together. The GPIO pin 13 or D7 is connected to the Data pin of the DHT11 and the Vcc and GND pins of both are interconnected.

NodeMCU DHT11 interfacing

Now the NodeMCU should be connected to the PC running the Arduino IoT cloud using the mini usb cable.

You should create an account on the Arduino IoT cloud and then sign in. For the first time user, you have to download the Arduino Cloud Agent application and install on your computer. This application is used to detect which hardware is connected to the PC USB like NodeMCU to configure it to connect the the Arduino IoT platform. Once you have download and run the application the next step is to create a thing.

On the Arduino Cloud click on the create a thing. Name the thing like DHT11. Then we have to add two variables for the cloud. These two variables are for temperature and humidity. To add variables click on the Add button and create two variables like dhttemp and dhthumid with float type, variable permission as read only and with variable update policy as onchange feature. 


The next step is to setup the device that is to be programmed and the WiFi network credentials. In the device section, click on the connect button in the Associated Device menu section.

add device Arduino IoT cloud

Since we will be using NodeMCU select the 3rd party device option.



Select ESP8266 and then search and set NodeMCU 1.0(ESP12E Module).

Provide some name like NodeMCU to your device.

Then Arduino IoT cloud will provided particular device ID and a secret key for authentication to the IoT platform. You can download the PDF and copy the Secret key which is needed in the next step where we have to provide network information.


 

The device connected information is then done.

Then on the Arduino cloud you should see the device configured.

Next we have to provide the WiFi credentials of your network and the secret key provided in the above step to allow the access of the data flow from the NodeMCU to the Arduino cloud IoT platform.


Provide your Wifi SSID and password and the secret key for your device provided in the earlier step as shown below.


The next step is to write the program. Click on the Sketch tab and then click on the open full editor.


Here we need to add DHT library from the library option.

Search for the term dht in the search box and then click on the include button to add the library to the sketch.


You will see the following code for DHT library added in the sketch.


Next add DHT object below the include and then add dht.begin() in the setup() function as illustrated below.


Within the loop() function add the following codes:

dhttemp = dht.readTemperature();

dhthumid = dht.readHumidity();


The complete code is provided below.


// DHT sensor library - Version: Latest 
#include <DHT.h>
#include <DHT_U.h>

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/00dbc2d2-0ee4-4578-9f55-086dc2a58ee0 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  float dhthumid;
  float dhttemp;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"

DHT dht(13,DHT11);

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 
  
  dht.begin();

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  delay(2000);
  
  dhttemp = dht.readTemperature();
  dhthumid = dht.readHumidity();
  
}

In the board and port selection box make sure you have set the correct board and port number.  


Note that you have to select the correct Flash size for NodeMCU as illustrated below.

The next step is to program the NodeMCU from the Arduino Cloud. Click on the upload button. After successful upload you should see message in the output window.

When you go back to the Arduino IoT cloud you should see that the device status is online which means the device is connected as shown below.


Next we have to make a dashboard which is the web interface which will show the temperature and humidity data on the gauge controls. Click on the dashboard and create a new one. Name the dashboard like DHT11 here.

Click on the edit menu and then for temperature add a gauge control and for humidity use percentage control as shown below.

For the temperature gauge type in some name like Temperature and click on the link variable button.

In the link variable window choose the dhttemp variable and click on the link variable button.


Similarly for the humidity percentage control click on the link variable and choose the dhthumid variable.



Now you should be seeing the temperature and humidity data displayed on the IoT dashboard as shown below.

So in this way you can use the Arduino IoT platform on cloud for displaying humidity and temperature values from DHT11 and using NodeMCU.

In this tutorial we have used the free Arduino IoT cloud platform which limits the devices connectivity to just two. Also the dashboard cannot be shared publicly in free plan. The are some disadvantages of using Arduino IoT platform. There are ways to create your own IoT platform using custom domain url and IoT application hosted from home. One way is to use the Node-Red as IoT platform. The tutorial  Node-Red ESP8266 MQTT Publish Example and Node-Red ESP8266 MQTT Subscribe Example shows how to make IoT application that shows humidity and temperature on the self hosted webpage and how to turn on/off a LED using a switch on self hosted webpage. The tutorial NodeMCU Node Red Industrial Iot platform and Node Red IoT with Arduino DHT11 are similar to this one except NodeRed IoT application framework is used.


Post a Comment

Previous Post Next Post