IoT-Based Weather Monitoring System Using NodeMCU (ESP8266), Rain Sensor & DHT11

IoT Weather Monitoring System using NodeMCU ESP8266 + DHT11 + Rain Sensor | MakeMindz
🌤️ MakeMindz Tutorial

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.

📡 NodeMCU ESP8266 🌡️ DHT11 Sensor 🌧️ FC-37 Rain Sensor ☁️ IoT Ready 📟 Serial Monitor
🕐
1–2 hrs
Build Time
Beginner
Difficulty
📊
3 Params
Monitored

📋 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.


🌡️
Temperature

DHT11 → D3
Output in °C

💧
Humidity

DHT11 → D3
Output in %

🌧️
Rain Level

FC-37 → A0
0–1023 range

🛒 Components Required

📡
NodeMCU (ESP8266)Main controller with Wi-Fi
🌡️
DHT11 SensorTemperature & humidity
🌧️
FC-37 Rain SensorOr any rain module
🔌
Jumper WiresMale-to-female set
🧩
Breadboard400-point recommended
🔋
USB Cable (Micro-B)For programming & power
⚠️
Important: NodeMCU operates on 3.3V logic. Do NOT connect 5V to the A0 pin or GPIO pins — this can permanently damage the board.

📌 Pin Connections

ComponentNodeMCU PinTypeNotes
DHT11 DataD3 (GPIO 0)Digital InputAdd 10kΩ pull-up resistor
DHT11 VCC3.3VPowerDo NOT use 5V
DHT11 GNDGNDGroundCommon ground
Rain Sensor AOA0Analog InputOnly one A0 pin on NodeMCU
Rain Sensor VCC3.3VPowerKeep at 3.3V
Rain Sensor GNDGNDGroundCommon ground

🔌 Circuit Diagram

IoT Weather Monitoring — NodeMCU Circuit Diagram MakeMindz.com NodeMCU ESP8266 3.3V ● GND ● D3 ● A0 ● ● USB / PWR ● Wi-Fi Built-in Wi-Fi Ready for Cloud DHT11 SENSOR Temp + Humidity VCC DATA NC GND 10kΩ FC-37 RAIN SENSOR Rainfall Detection VCC GND DO AO Serial Monitor (115200) Humidity: 65.00 % Temperature: 30.00 *C Rain Sensor: 820 ☁️ Cloud Extension (Optional) ThingSpeak Blynk Arduino Cloud Add WiFi credentials + HTTP/MQTT to go online ↑ Wi-Fi built into NodeMCU 3.3V GND D3 Data A0 Analog - - Pull-up
💡
Tip: Add a 10kΩ resistor between the DHT11 DATA pin and 3.3V for a stable signal. Without it, you may get occasional "Failed to read" errors.

🧪 Try the Simulation

🔵
Simulate on TinkercadFree browser-based simulator — use virtual DHT11 & analog sensor
🟢
Simulate on WokwiBest NodeMCU/ESP8266 simulator — supports DHT11 and Serial Monitor
🟠
Simulate on CirkitDesignerImport the diagram.json below for the full circuit layout

💻 Arduino Code

Before uploading, install the DHT sensor library by Adafruit via Arduino IDE's Library Manager.

weather_monitor.ino
/*
 * 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

1
Include DHT Library

#include <DHT.h> — Adafruit's DHT library handles the one-wire protocol for reading the DHT11 sensor.

2
Define Pins

DHTPIN = D3 (DHT11 data line), RAIN_SENSOR_PIN = A0 (rain sensor analog output).

3
Setup: Initialise Serial & Sensor

Serial.begin(115200) starts communication. dht.begin() activates the DHT11 sensor.

4
Read Humidity & Temperature

dht.readHumidity() and dht.readTemperature() return float values each loop cycle.

5
Error Handling

isnan() checks for invalid sensor reads. If DHT11 fails, it prints an error message and skips the cycle.

6
Read Rain Sensor

analogRead(A0) returns 0–1023. Lower values = more water. See the rain level table below.

7
Print to Serial & Wait

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:

Weather Monitor Started
Humidity: 65.00 %   Temperature: 30.00 *C   Rain Sensor Value: 820
Humidity: 66.00 %   Temperature: 29.80 *C   Rain Sensor Value: 415
Humidity: 68.00 %   Temperature: 29.50 *C   Rain Sensor Value: 120

🌧️ Understanding Rain Sensor Values

📝
Rain sensor values are inversely proportional to water level — lower number = wetter surface. Values may vary slightly with calibration.
900–1023
☀️ Completely Dry
600–900
🌥️ Slight Moisture
300–600
🌦️ Light Rain
0–300
🌧️ Heavy Rain

🛠️ How to Upload the Code

1
Install Arduino IDE

Download from arduino.cc if not already installed.

2
Add ESP8266 Board

Go to File → Preferences → Additional Board Manager URLs. Add: http://arduino.esp8266.com/stable/package_esp8266com_index.json, then install from Board Manager.

3
Select Board

Tools → Board → NodeMCU 1.0 (ESP-12E Module)

4
Install DHT Library

Tools → Manage Libraries → Search DHT sensor library → Install the one by Adafruit. Also install Adafruit Unified Sensor when prompted.

5
Select COM Port

Tools → Port → Select the port that appears when NodeMCU is plugged in via USB.

6
Upload & Monitor

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:

📊
ThingSpeak

Free cloud platform with live charts. Use WiFiClient + HTTP GET.

📱
Blynk

Control from your phone. Install Blynk library and add virtual pins.

🤖
Arduino IoT Cloud

Official dashboard. Simple drag-and-drop setup with ArduinoIoTCloud library.

📨
Telegram Alerts

Send rain alerts via bot. Use UniversalTelegramBot library.

🌐
Local Web Server

Serve a live webpage from NodeMCU. No cloud needed — works on local Wi-Fi.

🖥️
OLED Display

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

© 2026 MakeMindz.com — Arduino, IoT & Robotics Tutorials

Built with ❤️ for makers, students & engineers

Comments

try for free