Train a multivariate LSTM to predict temperature using weather data, and deploy it on resource-constrained STM32 microcontrollers.
Project goal – Use 10 years of hourly weather data to train a deep learning model that can predict temperature without requiring a physical sensor. The final model is optimized and converted to TensorFlow Lite format for embedded deployment.
This project uses an LSTM (Long Short-Term Memory) neural network trained on 8 weather features (e.g., humidity, pressure, wind) to predict temperature one hour into the future. Input is based on a one-week rolling window (168 time steps × 8 features).
.
├── fetch_data.py ← fetches Meteostat data and saves as CSV
├── temperature_data.csv ← full 10-year dataset (2015–2025, Hyderabad)
├── process_data.py ← normalizes and splits data, saves scaler
├── scaler_params.txt ← saved MinMaxScaler values
├── lstm_model.py ← builds, trains, and evaluates the LSTM model
├── convert_model.py ← converts model to TensorFlow Lite format
├── LICENSE ← MIT License
├── README.md ← this file
git clone https://github.com/barnav1/PS-I
cd PS-I
python -m venv venv && source venv/bin/activate
pip install -r requirements.txtOr install manually:
pip install pandas numpy matplotlib scikit-learn tensorflow meteostatPython 3.8+ recommended.
python fetch_data.pyDownloads hourly weather data from Meteostat API for Hyderabad (2015–2025).
python process_data.py- Filters and normalizes the 8 numerical features
- Saves scaler parameters to
scaler_params.txt
python lstm_model.py- Splits data into train/val/test
- Trains an LSTM model with early stopping
- Plots loss curves and saves
main.keras
python convert_model.py- Converts
.kerasto.tflite - Saves final model as
converted_model.tflite
- NRMSD: ~2% on the test set
- Model captures trends over a 168-hour window with high precision
- Inference is lightweight and suitable for CPU-only deployment
temp: air temperature (target)dwpt: dew pointrhum: relative humidityprcp: precipitationwdir: wind directionwspd: wind speedpres: pressurecoco: weather condition code
tensorflowpandasnumpymatplotlibscikit-learnmeteostat
- Meteostat API for free access to historical weather data
- TensorFlow & Keras for model building
- STM32Cube.AI for ML-on-MCU deployment tools
MIT License – see LICENSE for details.