Projects / Blue Pill comfort index meter

Blue Pill comfort index meter

A Blue Pill reads an SHT31 sensor, works out the dew point and shows a simple comfort rating on an OLED.

Intermediate2.3 hGuided buildReviewed

Build it step by step

0 of 6 done
  1. STM32STSHT3129.3°C

    Wire the programmer

    SWDIO, SWCLK, GND and 3.3V.

  2. STM32SHT3129.3°C

    Wire the sensor and display

    SDA to PB7, SCL to PB6, power at 3.3 V.

  3. STM32SHT3129.3°CSSD1306

    Install the libraries

    Adafruit SHT31, Adafruit SSD1306 and Adafruit GFX.

  4. STM32SHT3129.3°C

    Upload the sketch

    The display shows temperature, humidity, dew point and a word.

  5. STM32SHT3129.4°C

    Breathe on the sensor

    Humidity and dew point rise.

  6. STM32

    Move it to another room

    Wait a few minutes for the reading to settle.

In short

How do you build a blue Pill comfort index meter?

A Blue Pill reads an SHT31 sensor, works out the dew point and shows a simple comfort rating on an OLED. You need STM32 Blue Pill (STM32F103C8T6), ST-Link V2 programmer (clone), SHT31 temperature and humidity sensor, SSD1306 OLED Display and Breadboard 830 Tie Points. It takes 6 steps and about 140 minutes.

Level
Intermediate
Time
About 140 min
Parts
5

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
ST-Link GNDBoard GNDGround
ST-Link SWDIOBoard DIODebug data
ST-Link SWCLKBoard DCLKDebug clock
ST-Link 3.3VBoard 3.3 pinPower from the programmer (do not also plug in USB)
SHT31 VIN and OLED VCCBlue Pill 3.3 pinPower at 3.3 V
SHT31 GND and OLED GNDBlue Pill GNDCommon ground
SHT31 SDA and OLED SDABlue Pill PB7Shared I2C data
SHT31 SCL and OLED SCLBlue Pill PB6Shared I2C clock

Code

Relative humidity on its own does not tell you how muggy it feels, because warm air can hold more water than cool air. The dew point does: it is the temperature at which the water in the air would start to condense, and it tracks how humid the air feels fairly well. Below about 10 degrees the air feels dry, around 10 to 16 it is comfortable, and above 18 it starts to feel muggy. The program calculates the dew point from temperature and humidity with the Magnus formula, a standard approximation, and maps it to a word. The SHT31 is an accurate digital sensor on I2C at address 0x44. Keep it away from the Blue Pill and the display, which warm the air a little, and give it a few minutes to settle after you move it from one room to another.

Runs on a virtual STM32 Blue Pill in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Wire.h>
#include <Adafruit_SHT31.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SHT31 sht31;
Adafruit_SSD1306 oled(128, 64, &Wire, -1);

float dewPoint(float t, float rh) {
  float gamma = log(rh / 100.0) + (17.62 * t) / (243.12 + t);   // Magnus formula
  return 243.12 * gamma / (17.62 - gamma);
}

const char* rating(float dew) {
  if (dew < 10) return "Dry";
  if (dew < 16) return "Comfortable";
  if (dew < 18) return "Humid";
  if (dew < 21) return "Muggy";
  return "Oppressive";
}

void setup() {
  Wire.begin();                                    // I2C1 uses PB7 for SDA and PB6 for SCL
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { while (true) {} }
  if (!sht31.begin(0x44)) { while (true) {} }      // use 0x45 if the address pin is high
}

void loop() {
  float t = sht31.readTemperature();
  float rh = sht31.readHumidity();
  oled.clearDisplay();
  oled.setTextColor(SSD1306_WHITE);
  oled.setTextSize(1);
  if (isnan(t) || isnan(rh)) {
    oled.setCursor(0, 0);
    oled.print("Sensor read failed");
  } else {
    float dew = dewPoint(t, rh);
    oled.setCursor(0, 0);
    oled.print("Temp "); oled.print(t, 1); oled.print(" C");
    oled.setCursor(0, 12);
    oled.print("Humidity "); oled.print(rh, 0); oled.print(" %");
    oled.setCursor(0, 24);
    oled.print("Dew point "); oled.print(dew, 1); oled.print(" C");
    oled.setTextSize(2);
    oled.setCursor(0, 44);
    oled.print(rating(dew));
  }
  oled.display();
  delay(2000);
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
A normal roomComfortable or Dry
Breathe on the sensorHumidity rises quickly then falls
A steamy bathroomHumid, Muggy or Oppressive
Next to a cold windowLower temperature and a higher humidity
Dew pointAlways at or below the air temperature

If it does not work

Sensor read failed

Check the address 0x44 or 0x45 and the I2C wires.

Temperature reads high

Move the sensor away from the board and display.

Humidity looks wrong

Let the sensor settle after a change, and keep it dry and away from steam jets.

Display blank

Check the I2C address 0x3C.

Upload problems

Check the ST-Link wires and the board settings.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the blue Pill comfort index meter?

STM32 Blue Pill (STM32F103C8T6), ST-Link V2 programmer (clone), SHT31 temperature and humidity sensor, SSD1306 OLED Display and Breadboard 830 Tie Points.

How long does the blue Pill comfort index meter take to build?

About 140 minutes for a intermediate maker, in 6 steps.

How do I know the blue Pill comfort index meter works?

A normal room: Comfortable or Dry. Breathe on the sensor: Humidity rises quickly then falls. A steamy bathroom: Humid, Muggy or Oppressive.

Sensor read failed: what should I check?

Check the address 0x44 or 0x45 and the I2C wires.

Temperature reads high: what should I check?

Move the sensor away from the board and display.

Humidity looks wrong: what should I check?

Let the sensor settle after a change, and keep it dry and away from steam jets.

Display blank: what should I check?

Check the I2C address 0x3C.