ESP8266 Nodemcu Temperature Monitoring Using DHT11 on a Local Webserver | Get Room Temperature & Humidity on Your Browser

Hi guys today we will making a humidity & temperature monitoring system using ESP 8266 NODEMCU & DHT11 temperature sensor. Temperature and humidity will obtained from DHT11 Sensor & it can be seen on a browser which webpage will be managed by esp 8266 by hosting it on a local Webserver.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Things You Need

Step 2: Circuit

The circuit is very easy connect everything According as shown in schmatics

Step 3: Get the Libraries

Open your Arduino IDE and go to Sketch > Include Library > Manage Libraries. The Library Manager should open.

Search for “DHT” on the Search box and install the DHT library from Adafruit.

After installing the DHT library from Adafruit, type “Adafruit Unified Sensor” in the search box. Scroll all the way down to find the library and install it.

After installing the libraries, restart your Arduino IDE.

Step 4: Code

After doing above things upload the following code to ESP8266 nodemcu ( please select proper port & board ) & before uploading the code please put ssid & password of your wifi in the code :

// Including the ESP8266 WiFi library
#include "DHT.h"

// Uncomment one of the lines below for whatever DHT sensor type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321

// Replace with your network details
const char* ssid = "YOUR_NETWORK_NAME";
const char* password = "YOUR_NETWORK_PASSWORD";

// Web Server on port 80
WiFiServer server(80);

// DHT Sensor
const int DHTPin = 5;
// Initialize DHT sensor.

// Temporary variables
static char celsiusTemp[7];
static char fahrenheitTemp[7];
static char humidityTemp[7];

// only runs once on boot
void setup() {
// Initializing serial port for debugging purposes


// Connecting to WiFi network
Serial.print("Connecting to ");

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
Serial.println("WiFi connected");

// Starting the web server
Serial.println("Web server running. Waiting for the ESP IP...");

// Printing the ESP IP address

// runs over and over again
void loop() {
// Listenning for new clients
WiFiClient client = server.available();

if (client) {
Serial.println("New client");
// bolean to locate when the http request ends
boolean blank_line = true;
while (client.connected()) {
if (client.available()) {
char c =;

if (c == '\n' && blank_line) {
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
strcpy(fahrenheitTemp, "Failed");
strcpy(humidityTemp, "Failed");
// Computes temperature values in Celsius + Fahrenheit and Humidity
float hic = dht.computeHeatIndex(t, h, false);
dtostrf(hic, 6, 2, celsiusTemp);
float hif = dht.computeHeatIndex(f, h);
dtostrf(hif, 6, 2, fahrenheitTemp);
dtostrf(h, 6, 2, humidityTemp);
// You can delete the following Serial.print's, it's just for debugging purposes
Serial.print("Humidity: ");
Serial.print(" %\t Temperature: ");
Serial.print(" *C ");
Serial.print(" *F\t Heat index: ");
Serial.print(" *C ");
Serial.print(" *F");
Serial.print("Humidity: ");
Serial.print(" %\t Temperature: ");
Serial.print(" *C ");
Serial.print(" *F\t Heat index: ");
Serial.print(" *C ");
Serial.println(" *F");
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
// your actual web page that displays temperature and humidity

Step 5: Get the IP

You view the temperature & humidity we need to get the IP of webpage. So for that make sure your esp8266 is connected to your PC and then open the serial monitor and on the serial monitor you can see the IP of your ESP8266 webserver webpage.

Step 6: Check Your Temperature & Humidity on the Browser

So after getting the IP of your ESP8266 nodemcu , just open browser in PC or Mobile but make sure your PC/mobile is connected with same network as your Nodemcu/ESP8266 and then go to your browser ( if you are using mobile please use default browser i.e. for Android use chrome ) and then type the IP we got in previous step and the local webpage will b display with humidity & temperature as mine shown in image.
So have fun making your room temperature & humidity monitor.

Be the First to Share


    • CNC Contest

      CNC Contest
    • Make it Move

      Make it Move
    • Teacher Contest

      Teacher Contest