Interfacing DHT11 with NodeMcu ESP8266 and using Ubidots Cloud

In this tutorial, we discuss how to Interface DHT11 with NodeMcu ESP8266 and Sending its Data to Ubidots Cloud. Ubidots is an IoT(Internet of Things) data analytics and visualization company. We turn sensor data into information that matters for business-decisions, machine-to-machine interactions, educational research, and increase economization of global resources. Ubidots exists as an easy and affordable means to integrate the power of the IoT into your business or research.

Ubidots technology and engineering stack were developed to deliver a secure, white-glove experience for our users. Device friendly APIs (accessed over HTTP/MQTT/TCP/UDP protocols) provides a simple and secure connection for sending and retrieving data to and from our cloud service in real-time. Ubidots’ time-series backend services are performance optimized for IoT data storage, computation, and retrieval. Our application enablement platform supports interactive, real-time data visualization (widgets), and an IoT App Builder that allows developers to extend the platform with their own HTML/JS code for private customization when desired. Ubidots exist to empower your data from the device to visualization. Because of different plans for different users’ high response rates, easy to use, fast services Ubidots are widely used by developers and industries.

Features of Ubidots

  • Reasonably priced
  • Can send up to 20 -30 values per second 
  • Can be used with any IoT tool like Raspberry Pi, NodeMcu etc.
  • Works on rest api.

Ubidots plans for users

  • For students: – Ubidots provides free 5000 credits point and after consumption of 5000 credits you can purchase 1000 credits for 5$ for only one device.
Pricing students and developers.png

Fig1: Pricing for Students and Developers

  • For developers:-  Ubidots provides a trial for 30 days and later on 20 USD per month with some advance features and up to 10 devices at a time.
Plans for Developers.png

Plans for Developers

  • For an IoT lab:- for IoT lab in colleges or training Ubidots charge  $99 USD per month and you can use up to 60 devices at a time.
  • In industries:- Ubidots charge $499 USD per month and you can use up to 400 devices at a time.
  • For large scale:- for a large scale usage  Ubidots charge $ 2499 USD per month and you can use up to 5000 devices at a time. 

DHT11 Sensor

The DHT11 is a basic, ultra low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and spits out a digital signal on the data pin (no analog input pins needed). It’s fairly simple to use but requires careful timing to grab data. The only real downside of this sensor is you can only get new data from it once every 2 seconds, so when using our library, sensor readings can be up to 2 seconds old.

Pin Diagram DHT11.png

Pin Diagram DHT11

Components Required

  • DHT 11  sensor module (costs around $3 USD)
  • NodeMcu ESP8266 (costs around $6 USD)
  • Jumper wires

Software Required

  • Arduino IDE

Libraries Required

  • DHT.H
  • UbidotsMicroESP8266.h

The procedure to downloading the libraries is given in coding section.

Circuit Diagram

If you are new to Node Mcu – Click Here

DHT11 Interfacing NodeMCU.png

Interfacing DHT11 with Nodemcu

Nodemcu DHT11.jpg

Now after making circuit it’s time to setup ubidots account. Creating ubidots account is very simple easy and just takes only few steps.

Creating Ubidots Account

  • Open browser and search  apps.ubidots.com  and go.
Write in browser apps ubidots.png
  • When you open this link this type of page gets open.
Error Page.png

Error Page

  • Now click on Advanced.
Click Advanced.png
  • After that click on Proceed to apps.ubidots.com (unsafe) in the tab.
  • This type of tab opens in front of you.
Ubidots tab.png
  • Click on SIGN UP option.
Sign up option.png
  • Now SIGN UP. You can also sign up using your Twitter,  Github,  Google, or Facebook account. Fill all the details mentioned in the form and click on the signup.
  • At username place any username for example – xyzio
  • Please give your any mail id in email for example – xyz.gmail.com
  • Now enter any password of your choice and signup.

Now ,Ubidots setup is complete  let’s move on to the coding part all the left part for ubidots setup should be only done after successfully run of code.

Coding

Open Arduino IDE and go to file and new.

Arduino IDE.png
  • Note:- please download the library only from here because it is updated according to this blog.
  • Download the DHT library 
  • Download the zip file from the given links and now add the library by the procedure given below.

Now open arduino open sketch >include library>add .ZIP library

Add ZIP Library Path.png
  • And now open the path where the library is downloaded and click on open the file
  • Now the library gets install in Arduino IDE automatically
  • Now paste the below-given code in Arduino IDE.
  • Change the token. get your token from going onto your Ubidots account. Click on your username first at the right upper corner.
User Name.png

After clicking some option open there click on API Credentials .

API credentials.png

After clicking on API credentials copy your default token from there and replace the given token in code.

Default Token.png

Also change wifi name and password in code with your wifi name and password. Please write the wifi name and password in double cots.

.

Code

#include “DHT.h” 

#define DHTPIN D1

#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

#include “UbidotsMicroESP8266.h”

#define TOKEN  “A1E-kjeI6pKCeYOn6SFBDEBBiRezl68lxU”  // Put here your Ubidots TOKEN

#define WIFISSID “Nokia 3.1” // Put here your wifi name here

#define PASSWORD “”  // Put here your wifi password here my wifi is open put your 

Ubidots client(TOKEN);

unsigned long lastMillis = 0;

void setup(){

    Serial.begin(115200);

    dht.begin();

    delay(10);

    client.wifiConnection(WIFISSID, PASSWORD);

}

void loop(){

    if (millis() – lastMillis > 10000) {  ///every 10S

      float MyHumidity = dht.readHumidity();

      float MyTemperature = dht.readTemperature();

            lastMillis = millis();

            client.add(“MyHumidity”,MyHumidity );

            client.add(“MyTemperature”,MyTemperature );

            client.sendAll(true);

            }

}

Code Explanation

#include “DHT.h” 

#define DHTPIN D1

#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

  • These lines are used to call the library for DHT11 sensor and type of DHT sensor we are using and on which pin DHT is connecting to the NodeMcu.

#include “UbidotsMicroESP8266.h”

#define TOKEN  “A1E-kjeI6pKCeYOn6SFBDEBBiRezl68lxU”  // Put here your Ubidots TOKEN

  • The lines are used to call ubidots library for ESP8266 and get access to your account using token its save our token in the string  Token.

#define WIFISSID “Nokia 3.1” 

#define PASSWORD “” 

  • These lines are used for connecting our wifi to ESP8266.

client.add(“MyHumidity”,MyHumidity );

client.add(“MyTemperature”,MyTemperature )

client.sendAll(true);

  • The above lines create the feed in the device which receives the data with name MyHumidity and MyTemperature. Now upload the code in NodeMcu.

Ubidots Further Setup

After running the code go to ubidots and click on Devices u will see this block with tag ESP8266 DATA there.

ESP8266 Data block.png

Now click on ESP8266 DATA block and click You can add a location to your Device by clicking here  on this line on the upper side and allow location.

Allow Location.png

After clicking on allow location . just simply tap on your city ,town or village.

Tab after done.png

Now click on dashboard and then click on  +  icon button to add widget.

Dashboard Page.png

After clicking on add button press on Metric  tab as shown in photo.

Metric Tab.png

Now after clicking on Metric option click upon last value option

Last Date move on.png

After clicking on last value click upon ESP8266.

ESP8266 TAB.png

Now click on MyTemperature and click on finish.

My temperature finish.png

Repeat the steps 16 to 19 after step 19 choose MyHumidity and finish.

My Humidity now.png

Finally, the setup is complete and dashboard look alike the picture given below.

Run the code with all the setup.

Now you can download the Android app from the play store and see all the readings on your phone also and do login from the same details as here and check the data from your phone. I hope you are clear about the article. If any queries, please feel free to comment below.

Author Name – Harshit Jindal

Spread knowledge

Leave a Comment

Your email address will not be published. Required fields are marked *