Creating a project to monitor DHT11 sensor data (Temperature and Humidity) on a Web Server using NodeMCU (ESP8266) is a great way to view sensor data in real-time. In this tutorial, we will use NodeMCU to read data from the DHT11 sensor and host a simple web server to display the data.
Components Needed:
- NodeMCU (ESP8266)
- DHT11 Sensor (Temperature and Humidity Sensor)
- Jumper Wires
- Breadboard
- Micro USB Cable (for NodeMCU)
- Arduino IDE (for programming the NodeMCU)
Wiring the Circuit:
- DHT11 to NodeMCU Connections:
- VCC pin of DHT11 → 3V pin of NodeMCU
- GND pin of DHT11 → GND pin of NodeMCU
- DATA pin of DHT11 → D2 (GPIO4) pin of NodeMCU
Steps to Monitor DHT11 Data on a Web Server:
Step 1: Install the Arduino IDE
If you don't have it yet, install the Arduino IDE from the official website.
Step 2: Install NodeMCU Board in Arduino IDE
- Open the Arduino IDE.
- Go to File → Preferences.
- In the Additional Boards Manager URLs field, add the following link:http://arduino.esp8266.com/stable/package_esp8266com_index.json
Step 3: Install the DHT11 Library
- In the Arduino IDE, go to Sketch → Include Library → Manage Libraries.
- In the Library Manager, search for DHT sensor library and click Install.
Step 4: Write the Code
The code will read temperature and humidity values from the DHT11 sensor and serve them on a web page hosted on the NodeMCU.
Step 5: Explanation of
the Code
- WiFi
Setup:
The NodeMCU connects to your Wi-Fi network using the provided SSID
and password.
- DHT11
Sensor:
The DHT11 sensor reads the temperature and humidity values, which
are displayed on the web page.
- Web
Server:
The code creates a simple web server that serves an HTML page with the
current temperature and humidity. The page automatically refreshes every 5
seconds to show updated data.
- HTML
Page:
The webpage displays the temperature and humidity in Celsius
and percentage, respectively.
Step 6: Upload the Code
- Select
the NodeMCU board from the Tools → Board menu.
- Select
the correct COM port.
- Click
the Upload button in the Arduino IDE to upload the code to the
NodeMCU.
Step 7: Monitor the Data
- After
the upload, the NodeMCU will connect to your Wi-Fi and start the
web server.
- Open
the Serial Monitor to see the IP address of the NodeMCU.
- Enter
the IP address shown in the Serial Monitor into your browser's
address bar (e.g., http://192.168.1.100).
- You
should now see a webpage showing the current Temperature and Humidity
values. The page will refresh automatically every 5 seconds.
Optional Enhancements:
- Styling
the Web Page:
You can use CSS to improve the look of the webpage.
- Multiple
Sensors:
If you have multiple DHT11 sensors, you can modify the code to read from
and display data from all sensors.
- Mobile-Friendly
Interface:
Modify the HTML and CSS to make the page mobile-responsive.
Troubleshooting:
- Wi-Fi
Connectivity Issues: Double-check your Wi-Fi SSID and password.
- Sensor
Readings:
Ensure the DHT11 sensor is correctly connected to the NodeMCU. If
the readings fail, check the wiring.
- No Webpage: If the webpage doesn't load, make sure the NodeMCU has connected to Wi-Fi (check the Serial Monitor for the IP address).
Conclusion:
You have successfully built a web server using NodeMCU
to monitor DHT11 sensor data for Temperature and Humidity.
This setup allows you to access sensor data remotely through any web browser.
You can expand this project by adding more sensors, improving the web
interface, or even storing data on platforms like ThingSpeak or Firebase.
No comments:
Post a Comment