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.
Home » Computer Science » IoT Lab » DHT11 Sensor with NodeMCU ESP8266
Suryateja Pericherla 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

 

Components Required

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

 

Connections Diagram (Schematic)

DHT11 Sensor with NodeMCU ESP8266

 


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


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?

Leave a Reply

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

Facebook
Twitter
Pinterest
Youtube
Instagram
Blogarama - Blog Directory