How To Interface DHT11 With NodeMcu ESP8266 and Sending It

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

How to interface DHT11 with NodeMcu ESP8266 and sending its Data to

Ubidots cloud
About Ubidots

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 was developed to deliver a secure, white-glove experience for
our users. Device friendly APIs (accessed over HTTP/MQTT/TCP/UDP protocols) provide 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 exists to empower your data from device to
visualization.

Because of different plans for different users high response rate, easy to use, fast services Ubidots is
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:-

1. 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.
Figure 1 Pricing for students and developers

2. 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

Figure 2 Plans for developers

3. For a 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
4. For industries:- Ubidots charge $499 USD per month and you can use up to 400 devices at a time
5. 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

About 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 .
Figure 3 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

Figure 4 . circuit diagram with dht11 and nodemcu

Figure 5 NodeMCU with DHT11

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
1. Open browser and search apps.ubidots.com and go

Figure 6. Write in browser apps.ubidots.com

2. When you open this link this type of page open

Figure 7. Error page


3. Now click on Advanced

4. After that click on Proceed to apps.ubidots.com (unsafe) in the tab

5. Now this type of tab opens in front of you


6. Now click on SIGN UP option

Figure 8. Signup page

7. 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 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
1. Open Arduino IDE and go to file and new.
Figure 9. Arduino IDE

2. Now go to browser and open the given link https://github.com/harshitjindal01/ubidots-


esp8266.git note:- please download the library only from here because it is updated according
to this blog.

3. Download the DHT library from https://github.com/adafruit/DHT-sensor-library


4. Download the zip file from the given links and now add library by the procedure given below.
5. Now open arduino open sketch >include library>add .ZIP library

Figure 10. add .ZIP library path

6. And now open the path where the library is downloaded and click on open the file
7. Now the library get installed in Arduino IDE automatically
8. Now paste the below given code in Arduino IDE

9. Change the token . get your token from going onto your Ubidots account. Click on your
username first at the right upper corner

Figure 11 click on your username like my is harshit240

10. After clicking some option open there click on API Credentials .

Figure 12. API credentials

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

12. 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);
8. Now, after sign up this type of page appears

#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 );
Figure 13. page after signup
client.add("MyTemperature",MyTemperature );
client.sendAll(true);
9. After successful creation of variables and device set your location by You can add a location to
yo
}
10.
} 11.

Code explanation

#include "DHT.h"
#define DHTPIN D1
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

 This lines are used to call 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

 This 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 feed in the device which receive the data with name MyHumidity
And MyTemperature

Now upload the code in NodeMcu .

Ubidots further setup

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

2. 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
Figure 14. allow location

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

Figure 15. tab after completing whole process


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

Figure 16. dashboard page

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

Figure 17. Metric tab after cliking on + to add widgets:


6. Now after clicking on Metric option click upon last value option

Figure 18. select last date and move on

7. After clicking on last value click upon ESP8266

Figure 19. ESP8266 tab

8. Now click on MyTemperature and click on finish


Figure 20. click on MyTemperature and finish

9. Now repeat the steps 16 to 19 after step 19 choose MyHumidity and finish.

Figure 21. choose MyHumidity now

10. Now the setup is complete and dashboard look alike the picture given below
Now run the code with all the setup.

Now you can download the android app from play store and see all the readings in your phone
also and do login from same details as here and check the data from your phone.

You might also like