All notes

Automating Calibration and Report Generation with Google Colab

A repeatable pipeline for comparing DHT11 and HTC-1 sensors, calibrating them with data-driven methods, classifying thermal comfort with fuzzy logic, and generating a LaTeX report, all inside Google Colab.

Comparing a low-cost sensor against a reference and writing up the result by hand is repetitive work. This note describes a workflow that does the whole thing inside Google Colab: extract paired readings from Google Sheets, calibrate the DHT11 against an HTC-1 reference, evaluate agreement with regression and Bland-Altman analysis, classify thermal comfort with a Mamdani fuzzy model, and generate a complete scientific-style report as a PDF, all from a single notebook.

Objective

Temperature and humidity matter in tropical workspaces, where natural ventilation carries most of the thermal load. Low-cost sensors such as the DHT11 are widely used, but their readings drift. The goal was to quantify the offset against an HTC-1, correct it with a data-driven calibration, and produce a report that could be regenerated whenever new data arrived.

Data Collection

The DHT11 and the HTC-1 sat side by side in a naturally ventilated office in Indonesia. Two datasets were recorded:

  • Before calibration, to establish the baseline error
  • After calibration, to verify the correction

Each dataset spanned several hours of normal office activity, so the comparison covered realistic changes in temperature and humidity rather than a single static condition.

Analysis in Colab

The notebook loads the paired readings from Google Sheets using gspread, then computes error metrics for the raw and the calibrated series. Mean absolute error and standard deviation summarize how far the DHT11 sits from the reference. A linear regression quantifies the relationship between the two sensors, and a Bland-Altman comparison checks bias and agreement across the measurement range instead of collapsing everything into one number.

The key metric is the mean absolute error:

MAE=1ni=1ny^iyi\mathrm{MAE} = \frac{1}{n}\sum_{i=1}^{n}\left|\hat{y}_i - y_i\right|

Calibration Results

After calibration, the DHT11 tracked the reference much more closely. The mean error and its spread both shrank, and the fitted regression line moved toward the line of identity. For a low-cost sensor, the improvement was substantial enough to make the readings usable for further analysis.

Fuzzy Mamdani Classification

Raw numbers are hard to interpret, so a Mamdani fuzzy model converted each reading into a thermal comfort category. Membership functions over temperature and humidity produced states from COLD through COMFORTABLE to HOT, which read naturally when compared with how the room actually felt.

The classified readings were then checked against the ASHRAE 55-2020 comfort range for naturally ventilated spaces in tropical climates, 23 to 28 degrees Celsius. The analysis reported the share of readings inside that band:

  • When less than 70% of readings were comfortable, it recommended specific actions: optimize natural ventilation during the hottest hours, add fans to improve air circulation, and review internal heat loads from equipment and lighting.
  • When at least 70% were comfortable, it recommended keeping the existing ventilation pattern and monitoring periodically to catch drift early.

Automated LaTeX Report

Once the analysis finished, the notebook assembled the report with pylatex: sections for the methodology and results, plus figures inserted directly from the analysis. The document compiled to a PDF and was saved to Google Drive so it could be shared immediately after each run.

from pylatex import Document, Section

doc = Document("Scientific_Thermal_Comfort_Report")

with doc.create(Section("Results and Discussion")):
    doc.append("This section presents the calibration outcomes and fuzzy logic analysis performed in Colab.")

doc.generate_pdf(clean_tex=False)

Why Automate

The notebook turned a one-off comparison into a repeatable pipeline. New data can be added to the sheet and the report regenerated in a single run, which makes it practical to re-validate the calibration as the sensors age or the environment changes. It also showed that an inexpensive sensor like the DHT11 becomes far more reliable once its readings are corrected against a proper reference.

Resources