Weather monitoring system built with ESP8266 NodeMCU, featuring multiple sensors for temperature, humidity, atmospheric pressure, and air quality monitoring with real-time web interface.
- Multi-sensor monitoring: DHT11, BMP280, and MQ-135 sensors
- Real-time JSON data: Access sensor data via web browser
- Visual status indicators: LED-based system health monitoring
- WiFi connectivity: Static IP configuration with automatic reconnection
- Data validation: Sensor reading validation and error handling
- External weather data: Integration with WeatherAPI.com
- ESP8266 NodeMCU - Main microcontroller
- DHT11 - Temperature and humidity sensor
- BMP280 - Barometric pressure and temperature sensor (IΒ²C)
- MQ-135 - Air quality sensor
- 2x LEDs (Green & Red) - Status indicators
- 2x 220Ξ© Resistors - For LED current limiting
- 1x 10kΞ© Resistor - DHT11 pull-up resistor
- Breadboard and jumper wires
DHT11 NodeMCU
VCC β 3.3V (3V3 pin)
GND β GND
DATA β D5 (GPIO14)
Note: Connect 10kΞ© resistor between VCC and DATA pins
BMP280 NodeMCU
VIN β 3.3V (3V3 pin)
GND β GND
SDA β D2 (GPIO4)
SCL β D1 (GPIO5)
MQ-135 NodeMCU
VCC β Vin (5V)
GND β GND
A0 β A0 (ADC0 pin)
Note: D0 pin is not used in this project
Green LED:
Anode (+) β D6 (GPIO12) through 220Ξ© resistor
Cathode(-) β GND
Red LED:
Anode (+) β D7 (GPIO13) through 220Ξ© resistor
Cathode(-) β GND
The system uses two LEDs to indicate operational status:
LED Pattern | Status | Description |
---|---|---|
π’ Solid Green | All OK | All sensors working, WiFi connected |
π’ Slow Blink | Minor Issues | One sensor failure, system functional |
π’ Double Blink | WiFi Disconnected | Sensors OK, WiFi connection lost |
π΄ Fast Blink | Multiple Failures | Multiple sensor failures |
π΄ Solid Red | Critical Failure | System-wide failure |
- Arduino IDE with ESP8266 board package
- Required libraries (install via Library Manager):
ESP8266WiFi ESP8266WebServer Adafruit_BMP280 DHT sensor library ArduinoJson
Warning
Arduino IDE File Structure Requirement
All .ino
and .h
files must be placed inside a folder named weather_station
for Arduino IDE to compile properly. The main file weather_station.ino
must have the same name as the containing folder. Failure to follow this structure will result in compilation errors.
Important
Configuration Setup
Before compiling, you must create your own config.h
file from the example:
- Copy
config_example.h
toconfig.h
- Update your WiFi credentials, API key, and network settings
- The
config.h
file is ignored by git to protect your sensitive information
-
Clone this repository
-
Copy
config_example.h
toconfig.h
:cp config_example.h config.h
-
Open
config.h
and update your settings:// WiFi Configuration #define WIFI_SSID "Your_WiFi_Name" #define WIFI_PASSWORD "Your_WiFi_Password" // Static IP Configuration (optional) #define STATIC_IP IPAddress(192, 168, 1, 223) #define GATEWAY_IP IPAddress(192, 168, 1, 1) // API Security #define API_KEY "your_custom_api_key" // Weather API Configuration (optional) #define WEATHER_API_KEY "your_weather_api_key" #define WEATHER_API_LOCATION "YourCity" #define WEATHER_API_INTERVAL 300 // Seconds between API calls (300 = 5 minutes) // MQ135 Calibration (REQUIRED for accurate readings) #define MQ135_CLEAN_AIR_VALUE 200 // Update with your sensor's baseline
-
Weather API Setup (Optional): To enable weather data features, sign up for a free API key at WeatherAPI.com and update your
config.h
:- Replace
"your_weather_api_key"
with your actual API key - Replace
"YourCity"
with your desired location (e.g., "Guwahati", "London", "New York") - Adjust
WEATHER_API_INTERVAL
to control how often fresh data is fetched (300 seconds = 5 minutes) - If you don't configure this, the weather endpoints will return error messages
- Replace
Caution
MQ135 Calibration Required
The MQ135 air quality sensor requires individual calibration as each sensor has different baseline values. You must update the MQ135_CLEAN_AIR_VALUE
in your config.h
file with your sensor's specific baseline reading. See the MQ135 Calibration section for detailed instructions.
- Connect your NodeMCU to your computer
- Select the correct board:
Tools > Board > ESP8266 Boards > NodeMCU 1.0
- Select the correct port:
Tools > Port > [Your COM Port]
- Upload the code:
Sketch > Upload
After successful connection, access your weather station at:
http://192.168.1.223/ (or your configured IP)
GET /jsondata?key=your_api_key
GET /jsondata?key=your_api_key&weather=true
Sensor Data with Response:
Note
The weather field is included only when weather=true is requested.
{
"sensors": {
"temperature_dht": 30.3,
"temperature_bmp": 29.6,
"temperature_avg": 30,
"humidity": 57.4,
"pressure": 991.5,
"air_quality_raw": 270,
"air_quality_ppm": 554.0875,
"air_quality_aqi": 63,
"air_quality_status": "Moderate",
"is_valid": true
},
"system": {
"free_heap": 43368,
"heap_fragmentation": 1,
"max_free_block": 43264,
"cpu_freq": 80,
"uptime": 16,
"uptime_formatted": "16s",
"free_sketch_space": 1740800,
"flash_chip_size": 4194304,
"flash_chip_speed": 40
},
"wifi": {
"ssid": "Mitra`s",
"rssi": -30,
"ip": "192.168.1.223",
"mac": "8C:AA:B5:FB:FF:82"
},
"weather": {
"location": "Guwahati, Assam",
"temp_c": 27.2,
"temp_f": 81,
"condition": "Mist",
"condition_icon": "//cdn.weatherapi.com/weather/64x64/night/143.png",
"pressure_mb": 1004,
"humidity": 89,
"feelslike_c": 31.6,
"uv": 0,
"last_update": 16364,
"is_valid": true,
"airquality": {
"co": 468.05,
"no2": 3.515,
"o3": 106,
"so2": 2.96,
"pm2_5": 20.35,
"pm10": 20.905,
"us_epa_index": 2,
"gb_defra_index": 2
},
"seconds_since_update": 0,
"can_fetch_new": false,
"force_refreshed": false
}
}
Modify timing in config.h
:
#define SENSOR_READ_INTERVAL 5000 // 5 seconds
#define LED_UPDATE_INTERVAL 100 // LED update rate
Adjust sensor validation ranges:
#define TEMP_MIN -100.0
#define TEMP_MAX 100.0
#define PRESSURE_MIN 800.0
#define PRESSURE_MAX 1200.0
The MQ135 sensor requires proper calibration for accurate air quality measurements. Each MQ135 sensor has unique characteristics and baseline values, making individual calibration essential.
Warning
Sensor Warm-up Required
MQ135 sensors require 24-48 hours of initial warm-up for stable readings. For best results, allow the sensor to run continuously for at least 24 hours before calibrating.
Tip
Calibration Tips
- Perform calibration in stable weather conditions
- Avoid calibrating during high humidity or temperature changes
- Take multiple readings and average them for better accuracy
- Re-calibrate if you move the sensor to a different environment
The calibration process determines the sensor's resistance in clean air (R0), which serves as a baseline for calculating gas concentrations:
- Clean Air Reading: The sensor reads analog values in known clean air conditions
- Resistance Calculation: Convert analog reading to resistance using the load resistor value
- R0 Determination: Calculate baseline resistance using the clean air factor from the datasheet
- PPM Calculation: Use the Rs/R0 ratio to determine gas concentration in parts per million
You must modify these values in your config.h
file based on your specific sensor:
// MQ-135 Calibration Configuration
#define MQ135_CLEAN_AIR_VALUE 200 // Your baseline reading in clean air
#define MQ135_RL_VALUE 1.0 // Load resistance (1kΞ© in my case))
#define MQ135_RO_CLEAN_AIR_FACTOR 3.6 // From datasheet for 100ppm CO2
#define MQ135_CALIBRATION_SAMPLE_TIMES 50 // Number of samples for calibration
#define MQ135_CALIBRATION_SAMPLE_INTERVAL 500 // Time between samples (ms)
- Place the sensor in clean outdoor air (away from pollution sources)
- Power on the weather station and monitor the serial output
- Look for the "MQ-135 Debug" section in serial monitor
- Record the "Raw" analog reading after the sensor has warmed up (atleast 30 minutes)
- This raw value becomes your
MQ135_CLEAN_AIR_VALUE
- Most MQ135 breakout boards use a 1kΞ© or 10kΞ© load resistor
- Check your board's schematic or documentation
- Update
MQ135_RL_VALUE
if different (value in kΞ©)
MQ135_RO_CLEAN_AIR_FACTOR
is typically 3.6 from the datasheet- This represents the Rs/R0 ratio at 100ppm CO2 in clean air
- Usually doesn't need modification unless using a different reference gas
// Example calibration for different environments:
// Urban environment (slightly higher baseline):
#define MQ135_CLEAN_AIR_VALUE 250
// Rural/countryside (cleaner air):
#define MQ135_CLEAN_AIR_VALUE 180
// Indoor environment (after ventilation):
#define MQ135_CLEAN_AIR_VALUE 220
The sensor provides multiple air quality metrics:
- Raw Value: Direct analog reading (0-1024)
- Resistance: Calculated sensor resistance in kΞ©
- PPM: Gas concentration in parts per million (CO2 equivalent)
- AQI: Air Quality Index (simplified scale 0-500)
- Status: Descriptive quality level (Good, Moderate, Unhealthy, etc.)
Note
This implementation provides a simplified air quality estimation:
- Real AQI considers multiple pollutants (PM2.5, PM10, O3, NO2, SO2, CO)
- MQ135 primarily responds to CO2, ammonia, and alcohol vapors
- Values are estimates suitable for general indoor air quality monitoring
- For precise measurements, use calibrated professional equipment
WiFi Connection Problems:
- Check SSID and password in
config.h
- Verify network is 2.4GHz (ESP8266 doesn't support 5GHz)
- Check LED status patterns
Sensor Reading Issues:
- Verify wiring connections
- Check power supply (sensors need stable 3.3V/5V)
- Monitor serial output for error messages
Web Json Data Not Loading:
- Confirm IP address in serial monitor
- Check firewall settings
- Verify the device is on the same network
Enable detailed debugging by monitoring serial output at 9600 baud rate.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Properly configure AQI sensor calibration and thresholds
- Add weather forecast integration
- Mobile app development (almost done)
This project is licensed under the MIT License - see the LICENSE file for details.
- Arduino community for extensive documentation
- Adafruit for excellent sensor libraries
- ESP8266 community for board support and examples
- Contributors to the open-source libraries used in this project
Crafted with π by Debojit
β Star this repository if you found it helpful!