Startertutorials Blog
Tutorials and articles related to programming, computer science, technology and others.
Subscribe to Startertutorials.com's YouTube channel for different tutorial and lecture videos.

Categories: IoT Lab. No Comments on DHT11 Sensor with NodeMCU ESP8266
0
(0)

In this article we will learn how to implement DHT11 Sensor with NodeMCU ESP8266. If your are new to Internet of Things (IoT), learn about IoT by visiting our Internet of Things tutorial for beginners.

 

Aim of Experiment

To fetch humidity and temperature using DHT11 sensor


Subscribe to our monthly newsletter. Get notified about latest articles, offers and contests.


 

Components Required

  • NodeMCU – 1
  • DHT11 Sensor – 1
  • Breadboard – 1

 

Connections Diagram (Schematic)

DHT11 Sensor with NodeMCU ESP8266

 

Code (C++/Arduino IDE)

//Include DHT library
#include "DHT.h"
#define DHTTYPE DHT11

const int DHT_pin = D1;
DHT dht(DHT_pin, DHTTYPE);

void setup() {
  // put your setup code here, to run once:
  dht.begin();
  Serial.begin(9600);
  delay(500);
}

void loop() {
  // put your main code here, to run repeatedly:
  //Read the temperature
  float t = dht.readTemperature();
  //Read the humidity
  float h = dht.readHumidity();
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" centi, Humidity ");
  Serial.print(h);
  Serial.println("%");
  delay(1000);
}

 

Instructions

In case of error while compiling, download the zip file from the following GitHub link:

https://github.com/adafruit/Adafruit_Sensor

Then in Arduino go to Sketch -> Include Library -> Add .Zip Library

Navigate to the downloaded zip file and click OPEN.

 

Video Explanation

How useful was this post?

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Suryateja Pericherla

Suryateja Pericherla, at present is a Research Scholar (full-time Ph.D.) in the Dept. of Computer Science & Systems Engineering at Andhra University, Visakhapatnam. Previously worked as an Associate Professor in the Dept. of CSE at Vishnu Institute of Technology, India.

He has 11+ years of teaching experience and is an individual researcher whose research interests are Cloud Computing, Internet of Things, Computer Security, Network Security and Blockchain.

He is a member of professional societies like IEEE, ACM, CSI and ISCA. He published several research papers which are indexed by SCIE, WoS, Scopus, Springer and others.

Leave a Reply

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