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.
You have to provide a name for your thing and later we will select a device and later we will create the variables.
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.
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.
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.
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.
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.
To display the sensor data we have added 2 gauge and named it according to sensor output parameter.
Connection
The connection is easy and can be done directly or using a breadboard.
Some Interesting Projects
- Interfacing 16×2 LCD with Raspberry Pi
- Weather Station with Raspberry Pi PICO and DHT11
- Controlling a servo motor using Raspberry Pi Pico
- Configuring BMP280 Sensor with Raspberry Pi
- Configuring Motion Sensor with Raspberry Pi Pico
- Weather Station with BMP280 Sensor and Raspberry Pi Pico
- IoT Pulse Oximeter Using NodeMCU MAX30100 & Blynk
- DIY Digital clock with RTC DS1307 and Raspberry Pi PICO
- IoT Security Camera using ESP32-Cam Blynk and PIR Sensor
- Reading built in Temperature sensor values of Raspberry Pi PICO
- ESP8266 based IoT Panic Alarm for Old Age People using Blynk
- How to send sensor data to Thingspeak using Raspberry Pi
- ESP32-CAM based Email Notification System
- Raspberry Pi Pico vs Arduino Which one to choose?
- ESP32 based Gas Leakage Detection using Email Notification
- IoT based Motion Detection Alarm using ESP8266 and Blynk
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.
If all the connection and configuration is correct then you will receive the sensor data in gauge widget in dashboard.
Along with the gauge you can add charts. These can track the data live and plot it easily.
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.
Conclusion
I have a problem saying that “msg was not declared in this scope”
kindly check the steps properly.