Getting Started with Arduino IoT cloud using NodeMCU and DHT11

Getting Started with Arduino IoT cloud using NodeMCU and DHT11

This is the era of cloud technologies. There are many cloud service providers available in the market. Recently Arduino has also came up with Arduino cloud platform for IoT related projects. Today we will be Getting Started with Arduino IoT cloud using NodeMCU and DHT11 sensor.

Working on cloud IoT platform provides good flexibility to access sensors data an monitor them using custom dashboards. Arduino is one of the most favorite platform for all electronics hobbyist and professionals. With time Arduino has come up with many products and a very supportive multipurpose IDE. In this article we will see how to build an IoT project using Arduino Cloud.

Requirements

  • DHT11 Sensor x 1
  • ESP8266 NodeMCU x 1
  • Computer/laptop
  • Data cable
  • Jumper cables

Creating an account in Arduino IDE

First e have to create an account in Arduino Cloud in order to use it. Use your email address to register and then login.

Initial Setup

After logging in you have to create your first thing. A thing is nothing but the piece of hardware which will communicate with cloud. By default it will open Things tab and later on we will proceed with other tabs like Dashboard, Devices, Integration and templates.

Getting Started with Arduino IoT cloud using NodeMCU and DHT11

You have to provide a name for your thing and later we will select a device and later we will create the variables.

Getting Started with Arduino IoT cloud using NodeMCU and DHT11

Now we will setup device by selecting the proper device. As we are using ESP8266 NodeMCU, we have to select Setup a 3rd Party Device.

Getting Started with Arduino IoT cloud using NodeMCU and DHT11

We have to select the proper device time. For NodeMCU we have to select ESP8266.

Under ESP8266 we have to select the model from the drop down menu. We have to select NodeMCU 1.0 and proceed with continue.

Getting Started with Arduino IoT cloud using NodeMCU and DHT11

Its time to provide a proper name for your device and click on next.

And finally you will get a Device ID along with Secret Key. Copy and keep this secret key safe.

Now check the check box as shown below and click on continue.

To connect the devices we have to enter the network details along with the secret key to configure it.

Getting Started with Arduino IoT cloud using NodeMCU and DHT11

Finally we are all set and your device setup is complete.

Configuring Variables

After configuring the device, now its time to setup the variables. Since we are using DHT11 temperature and humidity sensor, hence we have to configure 2 variables. We have type relative and search for CloudRelativeHumidity. Select Variable Permission as Read Only and Variable Update Policy as Periodically. The time interval set is 4 second and we are done setting up out first variable.

Click on Add Variable.

Similarly have to do the same for temperature variable. We have to search for temperature and click on CloudTemperatureSensor and click on Save.

Once we have added the Variable, they will be listed as shown below.

Getting Started with Arduino IoT cloud using NodeMCU and DHT11

For compiling the code and uploading it directly form cloud we have to install an agent. This step is optional and can be skipped.

Download the create agent installer and you have to install it.

Configuring Dashboard

We will move to Dashboards tab to create a new dashboard to display the sensor data. Before setting up the dashboard, we have to link the variables.

Here we will add the widgets and link it with existing temperature and humidity variable.

Below process to link the variables.

Getting Started with Arduino IoT cloud using NodeMCU and DHT11

To display the sensor data we have added 2 gauge and named it according to sensor output parameter.

Getting Started with Arduino IoT cloud using NodeMCU and DHT11

Connection

The connection is easy and can be done directly or using a breadboard.

Some Interesting Projects

Uploading Code

You can upload the code in Nodemcu. Download the file from the below link. Use the online editor to upload the code or use the local Arduino IDE to upload the code.


/*
Sketch generated by the Arduino IoT Cloud Thing "Temperature and humidity monitoring"
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing

CloudRelativeHumidity humidity;
String msg;
CloudTemperatureSensor temperature;

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"
#include "DHT.h"
#define DHTpin 2 // D4 on the nodemcu ESP8266
#define DHTTYPE DHT11
DHT dht(DHTpin,DHTTYPE);

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);

// 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
dht_sensor_getdata();
}

void onHumidityChange() {
// Do something

}

void onMsgChange() {
// Do something
}
void dht_sensor_getdata()
{
float hm= dht.readHumidity();
Serial.print("Humidity ");
Serial.println(hm);
float temp=dht.readTemperature();
Serial.print("Temperature ");
Serial.println(temp);
humidity=hm;
temperature=temp;
msg="Temperature = " + String (temperature)+" Humidity = " + String(humidity);
}

Building & Testing

Connect the DHT11 sensor with NodeMCU as per the connection diagram. Now connect the micro usb cable with computer to upload the code.

Getting Started with Arduino IoT cloud using NodeMCU and DHT11

If all the connection and configuration is correct then you will receive the sensor data in gauge widget in dashboard.

Getting Started with Arduino IoT cloud using NodeMCU and DHT11

Along with the gauge you can add charts. These can track the data live and plot it easily.

Getting Started with Arduino IoT cloud using NodeMCU and DHT11

Also Arduino cloud has android and iOS apps for smartphones. You can download it as per you platform and monitor the same data as shown below.

Similarly charts and live monitoring is also available.

Getting Started with Arduino IoT cloud using NodeMCU and DHT11

Conclusion

 

2 thoughts on “Getting Started with Arduino IoT cloud using NodeMCU and DHT11”

Leave a Comment