IoT Weather Monitoring System using NodeMCU ESP8266
Monitor Temperature, Humidity & Rain in real-time using DHT11 and FC-37 sensors — expandable to ThingSpeak, Blynk & Arduino IoT Cloud.
📋 Project Overview
This project turns a NodeMCU (ESP8266) into a compact weather station. It reads environmental data every 2 seconds and outputs it to the Serial Monitor. Because NodeMCU has built-in Wi-Fi, the same setup can be easily extended to push data to cloud dashboards without any additional hardware.
DHT11 → D3
Output in °C
DHT11 → D3
Output in %
FC-37 → A0
0–1023 range
🛒 Components Required
📌 Pin Connections
| Component | NodeMCU Pin | Type | Notes |
|---|---|---|---|
| DHT11 Data | D3 (GPIO 0) | Digital Input | Add 10kΩ pull-up resistor |
| DHT11 VCC | 3.3V | Power | Do NOT use 5V |
| DHT11 GND | GND | Ground | Common ground |
| Rain Sensor AO | A0 | Analog Input | Only one A0 pin on NodeMCU |
| Rain Sensor VCC | 3.3V | Power | Keep at 3.3V |
| Rain Sensor GND | GND | Ground | Common ground |
🔌 Circuit Diagram
🧪 Try the Simulation
💻 Arduino Code
Before uploading, install the DHT sensor library by Adafruit via Arduino IDE's Library Manager.
/* * IoT-Based Weather Monitoring System * MakeMindz.com * * Board : NodeMCU 1.0 (ESP-12E Module) * Sensors : DHT11 (D3) — Temp & Humidity * FC-37 Rain Sensor (A0) — Rainfall * Output : Serial Monitor @ 115200 baud */ #include <DHT.h> // ── Pin Definitions ── #define DHTPIN D3 #define DHTTYPE DHT11 #define RAIN_SENSOR_PIN A0 // ── Initialise DHT sensor ── DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(115200); dht.begin(); Serial.println("Weather Monitor Started"); } void loop() { // ── Read DHT11 ── float humidity = dht.readHumidity(); float temperature = dht.readTemperature(); // ── Error check ── if (isnan(humidity) || isnan(temperature)) { Serial.println("Failed to read from DHT sensor!"); return; } // ── Read rain sensor (0=wet, 1023=dry) ── int rainValue = analogRead(RAIN_SENSOR_PIN); // ── Serial output ── Serial.print("Humidity: "); Serial.print(humidity); Serial.print(" %\t"); Serial.print("Temperature: "); Serial.print(temperature); Serial.print(" *C\t"); Serial.print("Rain Sensor Value: "); Serial.println(rainValue); delay(2000); // Wait 2 seconds between readings }
⚡ How the Code Works
#include <DHT.h> — Adafruit's DHT library handles the one-wire protocol for reading the DHT11 sensor.
DHTPIN = D3 (DHT11 data line), RAIN_SENSOR_PIN = A0 (rain sensor analog output).
Serial.begin(115200) starts communication. dht.begin() activates the DHT11 sensor.
dht.readHumidity() and dht.readTemperature() return float values each loop cycle.
isnan() checks for invalid sensor reads. If DHT11 fails, it prints an error message and skips the cycle.
analogRead(A0) returns 0–1023. Lower values = more water. See the rain level table below.
All three readings are printed as a tab-separated line. delay(2000) pauses 2 seconds before the next cycle.
📟 Serial Monitor Output Example
Open Serial Monitor in Arduino IDE at 115200 baud rate. You should see output like this every 2 seconds:
🌧️ Understanding Rain Sensor Values
☀️ Completely Dry
🌥️ Slight Moisture
🌦️ Light Rain
🌧️ Heavy Rain
🛠️ How to Upload the Code
Download from arduino.cc if not already installed.
Go to File → Preferences → Additional Board Manager URLs. Add: http://arduino.esp8266.com/stable/package_esp8266com_index.json, then install from Board Manager.
Tools → Board → NodeMCU 1.0 (ESP-12E Module)
Tools → Manage Libraries → Search DHT sensor library → Install the one by Adafruit. Also install Adafruit Unified Sensor when prompted.
Tools → Port → Select the port that appears when NodeMCU is plugged in via USB.
Click Upload (→). Once done, open Serial Monitor and set baud rate to 115200. Readings appear every 2 seconds.
☁️ Upgrade to Full IoT Weather Station
NodeMCU has built-in Wi-Fi — add cloud credentials and HTTP/MQTT code to push data online:
Free cloud platform with live charts. Use WiFiClient + HTTP GET.
Control from your phone. Install Blynk library and add virtual pins.
Official dashboard. Simple drag-and-drop setup with ArduinoIoTCloud library.
Send rain alerts via bot. Use UniversalTelegramBot library.
Serve a live webpage from NodeMCU. No cloud needed — works on local Wi-Fi.
Add an SSD1306 OLED to show readings without a computer.
🌍 Applications
- 🏫 School Weather Station
- 🌱 Smart Agriculture Monitor
- 🚨 Rain Alert System
- 🏡 Greenhouse Monitoring
- 📐 IoT Mini Project / STEM
- 🎪 Science Exhibition Model
Comments
Post a Comment