Introduction: ESP8266 and Visuino: DHT11 Temperature and Humidity Web Server

ESP8266 modules are great low cost stand alone controllers with built in Wi-Fi, and I already made a number of Instructables about them.

DTH11/DTH21/DTH22 and AM2301are very popular combined Temperature and Humidity Arduino sensors, and I made a number of Instructables with them too, including an Instructable on Remote Thermometer and Humidity Sensor with 2 ESP8266 connected together on their own private Wi-Fi network.

In this Instructable I will show you how you can make a Temperature and Humidity Web Server with ESP8266 and DHT11 and connect to it on your existing Wi-Fi network from multiple devices with a web browser.

Step 1: Components

  1. OneNodeMCU ESP8266 board (I used NodeMCU 0.9 version, but any other, or even stand alone ESP-12 or ESP-01 will work)
  2. One DHT11 Sensor module I got from this cheap 37 sensors set
  3. 3 Female-Female jumper wires

Step 2: Connect the DHT11 to the NodeMCU ESP8266 Module

  1. Connect Power(Red wire), Ground(Black wire), and Data(Gray wire) to the DHT11 Module (Picture 1 shows 2 different types of DHT11 sensor modules. As you can see the pins may differ, so connect carefully!)
  2. Connect the other end of the Ground wire(Black wire) to the Ground pin of the ESP8266 module (Picture 2)
  3. Connect the other end of the Power wire(Red wire) to the 3.3V Power pin of the ESP8266 module (Picture 2)
  4. Connect the other end of the Data wire(Gray wire) to the Digital pin 2 of the ESP8266 module (Picture 3)
  5. Picture 4 shows where are the Ground, 3.3V Power, and Digital 2 pins of the NodeMCU 0.9

Step 3: Start Visuino, and Select the ESP8266 Board Type

To start programming the Arduino, you will need to have the Arduino IDE installed from here: http://www.arduino.cc.

Please be aware that there are some critical bugs in Arduino IDE 1.6.6.

Make sure that you install 1.6.7 or higher, otherwise this Instructable will not work!

If you have not done follow the steps in this Instructable to setup the Arduino IDE to program ESP 8266!

The Visuino: https://www.visuino.com also needs to be installed.

  1. Start Visuinoas shown in the first picture
  2. Click on the "Tools" button on the Arduino component (Picture 1) in Visuino
  3. When the dialog appears, select "NodeMCU ESP-12" as shown on Picture 2

Step 4: In Visuino: Set a Host Name and Access Point

First we need to configure the module to connect to existing Access Point and to assign HostName to it so we can discover it on the network.

  1. In the Object Inspector, expand the “Modules” property, then the “WiFi” sub property
  2. In the Object Inspector set the value of the "HostName" property to "dht11server" (Picture 1)
  3. In the Object Inspector, expand the “AccessPoints” sub property of the “WiFi”, and click on the "..." button next to its value (Picture 2)
  4. In the "AccessPoins" editor, select “WiFi Access Point” in the right view, and then click on the "+" button on the left to add the access point (Picture 2)
  5. In the Object Inspector, set the value of the "SSID" property to the SSID of your Wi-Fi Hotspot(Access Point) (Picture 4)
  6. If your Wi-Fi Hotspot(Access Point) requires password, In the Object Inspector, set the password in the value of the "Password" property (Picture 4)
  7. Close the "AccessPoints" dialog

Step 5: In Visuino: Add a TCP/IP Server Socket for the Communication

Next we need to add an TCP/IP Server socket for the communication.

  1. In the Object Inspector, click on the "..." button next to the value of the "Sockets" sub property of the WiFi (Picture 1)
  2. In the Sockets editor select “TCP/IP Server”, and then click on the "+" button (Picture 2) to add one (Picture 3)
  3. Close the "Sockets" dialog

Step 6: In Visuino: Add DTH11 and Formatted Text Component With 2 Analog Channels

To control and read the Temperature and Humidity from the DHT11 we need to add component for it in Visuino.

We also need to generate the web page from the data. The page is just an HTML text document, so we can use Formatted Text component to generate it.

  1. Type "dht" in the Filter box of the Component Toolbox then select the "Humidity and Thermometer DHT11/21/22/AM2301" component (Picture 1), and drop it in the design area
  2. Type "form" in the Filter box of the Component Toolbox then select the "Formatted Text" component (Picture 2), and drop it in the design area
  3. Click on the "Tools" button of the FormattedText1 component (Picture 3)
  4. In the Elements editor, select the Analog Element on the right, and click 2 times on the "+" button on the left (Picture 4), to add 2 of them (Picture 5)
  5. Close the "Elements" editor

Step 7: In Visuino: Set Formatted Text for the Server Response

We need to specify the HTML text that will be generated when a web client connects to the server.

We will specify the connection to close after the data i sent, and also will instruct the browser to reconnect(Refresh) after 5 seconds by adding "Refresh: 5" to the document. This way the web page will refresh every 5 seconds.

  1. In the Design Area, select the FormattedText1 component (Picture 1)
  2. In the Object Inspector select the "Text" property, and click on the "..." button next to its value (Picture 1)
  3. In the "Text" editor type:
    "HTTP/1.1 200 OK"
    "Content-Type: text/html"
    "Connection: close"
    "Refresh: 5"
    ""
    "<!DOCTYPE HTML>"
    "<html>"
    "<body>"
    "Temperature: %0"
    "Humidity: %1"
    "</body>"
    "</html>"

    (Picture 2)

    The %0 will be replaced with the value from AnalogElement1, and %1 will be replaced with the value from AnalogElement2
  4. Click on the OK button to close the dialog

Step 8: In Visuino: Connect the DHT11 Component

  1. Connect the "Temperature" output pin of the HumidityThermometer1 component to the "In" pin of the AnalogElement1 of the FormattedText1 component (Picture 1)
  2. Connect the "Humidity" output pin of the HumidityThermometer1 component to the "In" pin of the AnalogElement2 of the FormattedText1 component (Picture 2)
  3. Connect the "Sensor" pin of the HumidityThermometer1 component to the "Digital" input pin of the "Digital[ 2 ]" channel of the Arduino component(Picture 3)

Step 9: In Visuino: Add and Connect Edge Detect Component

We need to send the HTML text every time there is a new connection. To do that we will use Detect Edge component to detect the changing from False to True of the Connected pin of the TCP/IP Server Socket.

  1. Type "detect" in the Filter box of the Component Toolbox then select the "Detect Edge" component (Picture 1), and drop it in the design area
  2. Connect the “Connected” pin of the “Modules.WiFi.Sockets.TCPServer1” of the “NodeMCU ESP-12” component, to the “In” pin of the DetectEdge1 component (Picture 2)
  3. Connect the "Out" pin of the DetectEdge1 component to the "Clock" input pin of the FormattedText1 component (Picture 3)

Step 10: In Visuino: Connect the Formatted Text Component, and Add and Connect Delay Component

  1. Connect the “Out” pin of the FormattedText1 component to the “In” pin of the "Modules.WiFi.Sockets.TCPServer1” of the “NodeMCU ESP-12” component (Picture 1)
  2. Type "delay" in the Filter box of the Component Toolbox then select the "Delay" component (Picture 2), and drop it in the design area
  3. Connect the “Out” pin of the FormattedText1 component to the “In” pin of the Delay1 component (Picture 3)
  4. Connect the “Out” pin of the Delay1 component to the “Disconnect” input pin of the "Modules.WiFi.Sockets.TCPServer1” of the “NodeMCU ESP-12” component (Picture 4)

The Delay component will disconnect the socket shortly after the text has been sent.

Step 11: Generate, Compile, and Upload the Arduino Code

  1. In Visuino, Press F9 or click on the button shown on Picture 1 to generate the Arduino code, and open the Arduino IDE
  2. Connect theNodeMCU module with USB cable to the computer
  3. Select the board type and serial port as I have shown you in this Instructable
  4. In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 2)

Step 12: And Play...

Congratulations! You have made a Wi-Fi Temperature and Humidity Web Server.

On Picture 1 and in the Video you can see the connected and powered up project. I used a small USB Power Bank to power the module.

Make sure in the project on Step 4 you have entered the correct SSID and Password for your Wi-Fi hotspot!

If you open a web browser on your computer or mobile device, and type:

dht11server./

And press Enter, you will see the temperature and humidity measured by the module.The reading will refresh every 5 seconds as specified in Step 7 .

Make sure to add the Dot at the end of the name, otherwise Windows will not be able to resolve the domain name!

On Picture 2 you can see the complete Visuino diagram.

Also attached is the Visuino project, that I created for this Instructable. You can download and open it in Visuino: https://www.visuino.com

To run the attached project, you will need to set the SSID and Password for your Wi-Fi Hotspot as shown on Step 4!

Comments

author
justinmatthewtacogue21 (author)2017-04-08

Hi, i am currently receiving this error whenever I am accessing dht11server./

This site can’t be reached

dht11server.’s server DNS address could not be found.

Can you please help me resolved this issue. Thank you so much!

author
vaxus made it! (author)2016-10-10

Great Instructable!!! Worked from the first shoot!!! Thanks a lot.

Notes: I did not manage to connect with the "server name" in local network, but worked fine with IP address. Need to assign a fix IP and already have access to it from external network over port-forwarding setup on router.

p.s. next step is to add a timestamp into the webpage... working on that myself with module DS1302)

20161011_004255.jpg
author
BoianM (author)vaxus2016-10-10

Congratulations! Looks great :-)
Good luck adding the clock :-) Should be easy.

author
IshuJ1 (author)2016-02-16

Thank you for great videos , but i am facing problems to create server and i am using a proxy internet connection . please solve my problem.
This is .... I need your help with the following problem:the device which needs to connect via a proxy to the internet. I can't set a proxy at the device directly.

author
BoianM (author)IshuJ12016-02-16

I have not experimented with setting proxy yet :-( . Will see if I can find some time to play with it, and will let you know if I find a solution.

author
IshuJ1 (author)BoianM2016-02-16

thank u , and i will be in touch.

author
MatheusR14 (author)IshuJ12016-07-08

Hi! You solved this problem?

author
IshuJ1 (author)MatheusR142016-08-18

sorry for the late reply, but i am really stuck i could not solve the problem.
Do you have some idea about this ? If you have please help .

author
GabrielE22 (author)2016-06-08

nodemcu-12, dht11, arduino 1.6.9
It worked perfect, thanks!

author
BoianM (author)GabrielE222016-06-08

Great! Enjoy :-)

author
vmusica (author)2016-03-17

I'm getting problem wit Visuino, or better, Arduino IDE on verifying:
In file included from C:\Users\Mušice\Documents\Visuino\Generated\Generated.ino:16:0:

E:\Our Documents\Documents\Arduino\libraries\Mitov/Mitov_FormattedSerial.h:18:8: error: 'SerialConfig' does not name a type

const SerialConfig CSerialInits[] =

^

In file included from C:\Users\Mušice\Documents\Visuino\Generated\Generated.ino:16:0:

E:\Our Documents\Documents\Arduino\libraries\Mitov/Mitov_FormattedSerial.h: In member function 'virtual void Mitov::SerialPort<T_SERIAL_TYPE, T_SERIAL>::StartPort()':

E:\Our Documents\Documents\Arduino\libraries\Mitov/Mitov_FormattedSerial.h:123:40: error: 'CSerialInits' was not declared in this scope

T_SERIAL->begin( inherited::Speed, CSerialInits[ AIndex ], SERIAL_FULL );

^

E:\Our Documents\Documents\Arduino\libraries\Mitov/Mitov_FormattedSerial.h:126:40: error: 'CSerialInits' was not declared in this scope

T_SERIAL->begin( inherited::Speed, CSerialInits[ AIndex ], SERIAL_RX_ONLY );

^

E:\Our Documents\Documents\Arduino\libraries\Mitov/Mitov_FormattedSerial.h:129:40: error: 'CSerialInits' was not declared in this scope

T_SERIAL->begin( inherited::Speed, CSerialInits[ AIndex ], SERIAL_TX_ONLY );

^

exit status 1

Error compiling.

What can I do to fix this?

author
BoianM (author)vmusica2016-03-17

This is because you use the staging version 2.1.0 of the ESP8266 Arduino support. They changed some definitions in the "stable" release, and Visuino was updated accordingly.
Uninstall the "staging" version following these instructions, and install the "stable" version and it will work.
Follow this instructable:
https://www.instructables.com/id/Setting-Up-the-Arduino-IDE-to-Program-ESP8266/
and install the official 2.1.0.
The best procedure is:
1. Remove the version you have from the board manager
2. Go to : C:\Users\[USERNAME]\AppData\Local\Arduino15\packages
3. Delete the esp8266 folder there
4. Install the official 2.1.0 version following the Instructable
5. I just updated Visuino to the latest changes they did in the official 2.1.0 so update the Visuino to 7.7.0.69 - https://www.visuino.com/download

This should work. I just tested today with the official ESP 2.1.0 and it all seems to work fine.

author
vmusica (author)BoianM2016-03-17

Thank You, problem solved :-)

author
tarun2010karak (author)2016-02-27

After generating the code in Arduino IDE 1.6.7 why this error is coming ? plz help..

In file included from C:\Users\tarun\Documents\Visuino\Generated\Generated.ino:13:0:

C:\Users\tarun\Documents\Arduino\libraries\Mitov/Mitov_ESP8266_WiFi.h: In member function 'virtual void Mitov::ESP8266WiFiModule::StartEthernet()':

C:\Users\tarun\Documents\Arduino\libraries\Mitov/Mitov_ESP8266_WiFi.h:437:9: error: 'class ESP8266WiFiClass' has no member named 'setAutoReconnect'

WiFi.setAutoReconnect( AutoReconnect );

^

C:\Users\tarun\Documents\Arduino\libraries\Mitov/Mitov_ESP8266_WiFi.h: In member function 'virtual void Mitov::ESP8266WiFiModule::SystemLoopBegin(long unsigned int)':

C:\Users\tarun\Documents\Arduino\libraries\Mitov/Mitov_ESP8266_WiFi.h:457:45: error: 'class ESP8266WiFiClass' has no member named 'isConnected'

RemoteConnectedOutputPin.SetValue( WiFi.isConnected(), true );

^

C:\Users\tarun\Documents\Arduino\libraries\Mitov/Mitov_ESP8266_WiFi.h: In member function 'virtual void Mitov::ESP8266ModuleReconnectOperation::DoClock(void*)':

C:\Users\tarun\Documents\Arduino\libraries\Mitov/Mitov_ESP8266_WiFi.h:543:9: error: 'class ESP8266WiFiClass' has no member named 'reconnect'

WiFi.reconnect();

^

C:\Users\tarun\Documents\Visuino\Generated\Generated.ino: In function 'void setup()':

C:\Users\tarun\Documents\Visuino\Generated\Generated.ino:56:53: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

Declarations::FormattedText1.AddNullElement( "\"" );

^

author
BoianM (author)tarun2010karak2016-02-27

They have the server working now.
Follow this instructable:
https://www.instructables.com/id/Setting-Up-the-Arduino-IDE-to-Program-ESP8266/
and install the official 2.1.0.
The best procedure is:
1. Remove the version you have from the board manager
2. Go to : C:\Users\[USERNAME]\AppData\Local\Arduino15\packages
3. Delete the esp8266 folder there
4. Install the official 2.1.0 version following the Instructable
5. I just updated Visuino to the latest changes they did in the official 2.1.0 so update the Visuino to 7.7.0.69 - https://www.visuino.com/download

This should work. I just tested today with the official ESP 2.1.0 and it all seems to work fine.

author
tarun2010karak (author)BoianM2016-03-07

Hi BoianM, I'v a problem with visuino is that after uploading my Arduino generated code I can't get anything in dht11server on my PC's google web browser. Here is my code

//----------------------------------------------

//

// Sketch Generated by Visuino

// www.visuino.com

//

//----------------------------------------------

#define VISUINO_ESP8266

#include <OpenWire.h>

#include <Mitov.h>

#include <ESP8266WiFi.h>

#include <Mitov_ESP8266_WiFi.h>

#include <Ethernet.h>

#include <SPI.h>

#include <Mitov_FormattedSerial.h>

#include <Mitov_DHT_Sensor.h>

#include <Mitov_Text.h>

#include <Mitov_Timing.h>

// Arduino Board Declarations

namespace BoardDeclarations

{

Mitov::ArduinoDigitalChannel ArduinoDigitalChannel_2( D2, true, false, false, false, true );

} // BoardDeclarations

// Declarations

namespace Declarations

{

Mitov::ESP8266WiFiModule TArduinoESP8266WiFiModule1;

Mitov::ESP8266ModuleRemoteAccessPoint TArduinoESP8266WiFiModuleRemoteAccessPoint1( TArduinoESP8266WiFiModule1 );

Mitov::TCPServerSocket<Mitov::BasicEthernetShield,WiFiServer,WiFiClient> TArduinoWiFiTCPServerSocket1( TArduinoESP8266WiFiModule1 );

Mitov::EthernetSocketStringInput<Mitov::TCPServerSocket<Mitov::BasicEthernetShield,WiFiServer,WiFiClient>, &TArduinoWiFiTCPServerSocket1> TArduinoWiFiTCPServerSocket1_SerialInputString_1;

Mitov::DHT11Sensor<D2> HumidityThermometer1;

Mitov::FormattedText_Fixed FormattedText1;

Mitov::FormattedTextElementAnalog TArduinoFormattedTextElementAnalog1( FormattedText1 );

Mitov::FormattedTextElementAnalog TArduinoFormattedTextElementAnalog2( FormattedText1 );

Mitov::DetectEdge DetectEdge1;

Mitov::Delay Delay1;

} // Declarations

//The setup function is called once at startup of the sketch

void setup()

{

Declarations::TArduinoESP8266WiFiModule1.AccessPoint.SSID = "GUEST";

Declarations::TArduinoESP8266WiFiModule1.HostName = "dht11server";

Declarations::TArduinoWiFiTCPServerSocket1.ConnectedOutputPin.Connect( Declarations::DetectEdge1.InputPin );

Declarations::HumidityThermometer1.TemperatureOutputPin.Connect( Declarations::TArduinoFormattedTextElementAnalog1.InputPin );

Declarations::HumidityThermometer1.HumidityOutputPin.Connect( Declarations::TArduinoFormattedTextElementAnalog2.InputPin );

Declarations::FormattedText1.OutputPin.Connect( Declarations::TArduinoWiFiTCPServerSocket1_SerialInputString_1.InputPin );

Declarations::FormattedText1.OutputPin.Connect( Declarations::Delay1.StartInputPin );

Declarations::FormattedText1.AddReadyElement( (char *)"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\nRefresh: 5\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\n<body>\r\n\"Temperature: ", 0 );

Declarations::FormattedText1.AddReadyElement( (char *)"\"\r\n\"Humidiry: ", 1 );

Declarations::FormattedText1.AddNullElement( "\"\r\n</body/>\r\n</html/>" );

Declarations::DetectEdge1.OutputPin.Connect( Declarations::FormattedText1.ClockInputPin );

Declarations::Delay1.OutputPin.Connect( Declarations::TArduinoWiFiTCPServerSocket1.DisconnectInputPin );

OpenWire::Component::_SystemInit();

}

// The loop function is called in an endless loop

void loop()

{

OpenWire::Component::_SystemLoop();

}

My SSID name is GUEST with no password. Please give step by spet suggestions to get the sensor value on my web browser after uploading my code in esp8266 Node Mcu v0.9. I'm using Visuino 7.7.0.74 with arduino 1.6.7

When I'm connecting my PC with the AP named GUEST and giving the server name as dht11server it is showing this page is not found. Please help..

author

Hi BoianM , this dht11server working on which mode? whether it is in station mode or AP mode?

author
BoianM (author)tarun2010karak2016-03-07

In this Instructable I have configured it as Station connecting to my existing HotSpot, so I can access it from the already connected devices. You can also configure it as HotSpot or in both modes at the same time.

author
BoianM (author)tarun2010karak2016-02-27

Install the ESP8266 version 2.1.0. Reconnect functionality was added in this version.
The ESP Arduino site at the moment seems to be down, but I expect that they will fix it soon.
http://arduino.esp8266.com/stable/package_esp8266com_index.json
returns timeout error at the moment :-(
Will check later if they have fixed it.

author
tarun2010karak (author)BoianM2016-02-27

thank u Boian..
I'hv downloaded it from this link.

https://github.com/esp8266/Arduino/archive/2.1.0.zip
let me know where to put this file..?? and how to use it..??

author
BoianM (author)tarun2010karak2016-03-01

Hi tarun2010karak,

I am sorry for the late reply. I thought I replied :-( . They have fixed the server. Please install the 2.1.0 stable version using the official board manager link :

http://arduino.esp8266.com/stable/package_esp8266c...

To do that:

1. Uninstall the staging version from the board manager.

2. Delete the C:\Users\[USER_NAME]\AppData\Local\Arduino15\packages\esp8266 directory

3. Change the board manager link to the sable one in the Arduino IDE preferences

4. Install from the Board Manager 2.1.0

Make sure you do step 2, otherwise you will have a compilation error, as the uninstall leaves some files behind :-(

author
yenoromp (author)2016-02-09

Why not post the code as well ?

author
BoianM (author)yenoromp2016-02-09

The Visuino project is included, and you can generate the code for free with Visuino. It also will generate the latest code as it is constantly being improved ;-) . You can run Visuino for 5 minutes every run without the need to register, and it is plenty of time to generate the code ;-)
The Code also uses the Free Open Source Visuino Components library, and the Visuino install will install it for you. Otherwise you have to get it from the repository manually from Bitbucket: https://bitbucket.org/mitov/visuino-libraries

The old generated code may not work with the latest versions of the libraries, so it is not good idea to post it.

From any point it is better to generate the code directly ;-)

author
yenoromp (author)BoianM2016-02-09

thanks , but a painful way to do it with visiduino.

author
BoianM (author)yenoromp2016-02-09

Still better than not being able to compile the code because the library has been updated ;-) . That will be even more pain...

About This Instructable

34,830views

63favorites

License:

More by BoianM:Program Arduino UNO With Visuino to Draw on ILI9341 TFT Touchscreen Display Shield With PenAssemble Kuman Wi-Fi Robot With Camera and ManipulatorArduino and Visuino: Long Distance Remote Light Sensor With RFM95W/RFM98W Makerfabs LoRa Shields
Add instructable to: