skip to content
Fredesk Studio

Weather Forecasting with ESP32 and Machine Learning

/ 4 min read

Introduction

I’ve been working on a weather forecasting system that combines IoT hardware with machine learning to predict local temperature patterns. This is an academic project I developed to explore the intersection of embedded systems and predictive modeling, inspired by machine learning concepts that helped shape the system’s approach.

The system demonstrates how you can collect real-time sensor data, process it through a neural network, and generate short-term forecasts - all running on a modest VPS setup.

Module with battery power

The complete source code and documentation for this project is available on GitHub.

What It Does

The weather forecasting system consists of three main parts:

ESP32 Sensor Node: Collects temperature readings every 10 minutes and transmits them via MQTT to a central server. The sensor runs on battery power and connects wirelessly to handle data collection in remote locations.

PCB development progress

Prediction Engine: Uses an LSTM neural network to analyze historical temperature data and generate 48-hour forecasts. The model runs on the server and updates predictions every 10 minutes as new data arrives.

Web Dashboard: Provides a simple interface to view current conditions, historical data, and temperature predictions with confidence scores.

Technical Approach

The project uses a straightforward architecture: ESP32 sensors send data over MQTT to a Python server running FastAPI. The server stores sensor readings in a MySQL database and feeds this data to a PyTorch-based LSTM model for temperature prediction.

I kept the model complexity intentionally low to fit within the constraints of a small VPS, focusing more on the end-to-end pipeline than achieving state-of-the-art accuracy. The LSTM processes recent temperature trends to predict future values, with each forecast including a confidence score based on model uncertainty.

The web interface shows both actual sensor readings and predicted temperatures, making it easy to see how well the model performs over time.

Current Status

This is still an ongoing project. I’m working on improving the model accuracy and expanding the system to include additional weather parameters like humidity and pressure. The modular design makes it relatively easy to add new sensor types or modify the prediction algorithms.

Future Development: Experimental Sensors

One of the most exciting aspects of this project is the development of experimental sensors that haven’t been integrated into the main system yet. I’ve been working on two specialized sensor modules that will significantly enhance the forecasting capabilities:

Ground Vibration Sensor

Ground vibration experimental sensor

The ground vibration sensor is designed to detect seismic activity and ground movement patterns that can correlate with weather changes. This experimental module uses piezoelectric sensors combined with operational amplifiers to measure micro-vibrations in the ground, which can provide early indicators of atmospheric pressure changes and weather pattern shifts.

Complete ground vibration sensor

The complete sensor assembly includes a custom PCB with signal conditioning circuits using op-amps, a waterproof housing for outdoor deployment, and a low-power microcontroller for data processing. However, there’s still significant work to be done on the piezo sensor calibration and signal processing algorithms. The goal is to correlate ground vibration patterns with temperature and pressure changes to improve forecast accuracy.

Wind Detection Sensor

Wind experimental sensor

The wind detection sensor represents another experimental approach to weather prediction. This sensor uses a crystal, and an amplifier to create a comprehensive wind profile around the measurement site. Wind patterns are often strong indicators of upcoming weather changes, and this sensor aims to capture those patterns at a very local level.

Integration Challenges

Integrating these experimental sensors into the main system presents several interesting challenges:

  • Data Fusion: Combining temperature, vibration, and wind data requires sophisticated algorithms to identify meaningful correlations
  • Power Management: Each additional sensor increases power consumption, requiring careful optimization for battery-powered operation
  • Signal Processing: The vibration and wind sensors generate much more data than simple temperature readings, necessitating edge processing capabilities
  • Calibration: Experimental sensors need extensive calibration to ensure data quality and reliability

The modular architecture of the current system makes it relatively straightforward to add these new sensor types, but the real challenge lies in developing the machine learning models that can effectively utilize this multi-modal data for improved weather prediction.

The code is available on GitHub for anyone interested in the implementation details or wanting to adapt it for their own weather monitoring needs.

Learning Outcomes

Building this system taught me a lot about integrating different technologies - from embedded programming on ESP32 to machine learning with PyTorch to web development with FastAPI. The project demonstrates how academic concepts can be applied to create practical IoT solutions, even when working within resource constraints.