IoT Weather Station Using FreeRTOS and ESP32 Explained

IoT Weather Station Using FreeRTOS and ESP32 Explained

IoT Weather Station using ESP32 and FreeRTOS is a smart embedded project that gathers real-time environmental data such as temperature, humidity, and pressure and uploads it to the cloud for monitoring. By using the ESP32 microcontroller with FreeRTOS, this IoT weather monitoring system can efficiently manage multiple processes such as sensor data acquisition, display updates, and network communication simultaneously.

IoT Weather Station using ESP32 and FreeRTOS is designed to help you build an efficient weather monitoring system using BME280 and DHT sensors. This project explains how to upload real-time sensor readings to ThingSpeak and implement task management in FreeRTOS for better performance and reliability. It is one of the best ESP32 IoT projects for both beginners and professionals looking to learn IoT system development.

What Is an IoT Weather Station?


An 
IoT Weather Station monitors environmental parameters using sensors such as DHT11, DHT22, and BME280 with ESP32.
These sensors measure temperature, humidity, and pressure, then send data to a cloud service like ThingSpeak or Node-RED.
This compact setup makes it an ideal ESP32 weather station project, perfect for students and engineers learning IoT system design and cloud integration.


Register Now for IoT Weather Station Course

System Overview – How It Works


The ESP32 board reads data from environmental sensors and runs multiple FreeRTOS tasks to handle display updates, cloud uploads, and Wi-Fi management concurrently.
Each process runs independently using task management in FreeRTOS, improving reliability and responsiveness, which is essential for real-time IoT systems.

Hardware Components

ComponentDescription
ESP32 BoardDual-core MCU with Wi-Fi and Bluetooth
DHT11/DHT22Measures temperature and humidity
BME280 SensorMeasures humidity, pressure, and temperature
OLED Display (0.96”)Displays current readings
Breadboard and JumpersFor sensor connections
Power Supply/USB CableProvides power to the ESP32

Software Tools Required

  • Arduino IDE or PlatformIO
  • FreeRTOS support library for ESP32
  • ThingSpeak or Blynk for cloud dashboards
  • Adafruit_SSD1306 or u8g2 for OLED display
  • MQTT or HTTP for IoT data communication

System Architecture


Each block in the diagram represents a FreeRTOS task:

  • Sensor Task: Reads DHT and BME280 data
  • Display Task: Updates OLED display
  • Network Task: Handles Wi-Fi connectivity
  • Cloud Task: Sends readings to ThingSpeak


This modular design keeps each process isolated, improving stability.

FreeRTOS Task Management Explained


Using FreeRTOS, you can assign different priority levels to each process:

  • High: Network/Wi-Fi task
  • Medium: Sensor and Cloud communication tasks
  • Low: OLED display update task


This prioritization ensures consistent performance even under high CPU load.

Task Breakdown

TaskPriorityFunction
Sensor TaskMediumReads DHT or BME280 data every few seconds and pushes data to a queue
Display TaskLowUpdates the OLED with real-time readings
Wi-Fi TaskHighMaintains Wi-Fi connectivity and reconnection logic
Cloud TaskMediumPublishes data to ThingSpeak using HTTP or MQTT

IoT Communication Using MQTT and HTTP

MQTT Protocol:

  • Lightweight and ideal for IoT communication.
  • Example topics:
    • weather_station/temperature
    • weather_station/humidity

HTTP Protocol:

  • Easier to use for web APIs like ThingSpeak.
  • Sends sensor data using POST requests.


Both protocols are practical for ESP32 weather station projects, depending on your application.


Download IoT Weather Station Brochure

Example Code – ThingSpeak Upload

#include 
#include 
#include "DHT.h"

#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

const char* ssid = "YourWiFi";
const char* password = "YourPassword";
String apiKey = "YOUR_API_KEY";
const char* server = "http://api.thingspeak.com/update";

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  dht.begin();
}

void loop() {
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    float h = dht.readHumidity();
    float t = dht.readTemperature();
    String url = server + String("?api_key=") + apiKey + "&field1=" + t + "&field2=" + h;
    http.begin(url);
    http.GET();
    http.end();
  }
  delay(20000);
}
  

Optimization and Error Handling

  • Use the ESP32 watchdog timer example to reset the system if it hangs.
  • Enable ESP32 deep sleep mode for low-power operation.
  • Verify sensor connections and handle invalid readings.
  • Use uxTaskGetStackHighWaterMark() to monitor heap usage.
  • Implement non-blocking delays to prevent task freezing.

Debugging and Testing

  • Use Serial Monitor for live debugging.
  • Check task behavior using vTaskList() and other FreeRTOS debugging tools.
  • Test Wi-Fi reconnect and MQTT disconnection handling.
  • Validate queue and memory usage for stable performance.

Future Improvements

  • Add sensors for wind, rain, or air quality (MQ135).
  • Integrate a local web server to display data.
  • Implement OTA updates for firmware upgrades.
  • Log data to an SD card for offline analysis.
  • Connect with Home Assistant for smart home integration.

Talk to Academic Advisor - IoT Weather Station Course

Conclusion


The IoT Weather Station using FreeRTOS and ESP32 demonstrates real-time task management, efficient resource allocation, and cloud connectivity , all key aspects of modern IoT weather monitoring systems.
With sensors like DHT and BME280, and cloud platforms like ThingSpeak, this ESP32 IoT project serves as a complete learning experience for embedded developers and IoT enthusiasts looking to master real-time applications.

Frequently Asked Questions

 It is connecting a microcontroller to a GSM module to send/receive messages or data over mobile networks.

The SIM300 GSM module is widely used due to its tri-band support and compact size.

AT commands are instructions sent to the module to perform operations like sending SMS or making calls.

Enable ESP32 deep sleep mode for power-efficient applications.