Projects / Comfort index display

Comfort index display

Beginner1 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. NANOAHT2022.2°CSSD1306

    Install the libraries

    AHTX0, SSD1306 and GFX.

  2. NANO

    Wire the sensor

    VCC, GND, SDA to A4, SCL to A5.

  3. NANO

    Wire the display

    Same four wires on the same pins.

  4. NANOAHT2022.2°C

    Upload the sketch

    A word and three readings appear.

  5. NANOAHT2022.2°C

    Breathe near the sensor

    Humidity rises.

  6. NANO

    Move to another room

    The word may change.

  7. NANO

    Tune the labels

    Edit the numbers in label().

  8. NANO

    Compare

    Check with a second thermometer if you have one.

In short

How do you build a comfort index display?

A temperature and humidity sensor shows a simple comfort rating from cool and dry to hot and humid. You need Arduino Nano, AHT20 temperature and humidity sensor, SSD1306 OLED Display and Breadboard 830 Tie Points. It takes 8 steps and about 60 minutes.

Level
Beginner
Time
About 60 min
Parts
4

Parts list

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

Wiring

FromToWhy
AHT20 VCCNano 5VMost boards accept 3.3 V to 5 V, check yours
AHT20 GNDNano GNDCommon ground
AHT20 SDANano A4Shared I2C data
AHT20 SCLNano A5Shared I2C clock
OLED VCCNano 5VCheck the label on your module
OLED GNDNano GNDCommon ground
OLED SDANano A4Same bus as the sensor
OLED SCLNano A5Same bus as the sensor

Code

The AHT20 measures air temperature and relative humidity over I2C. Humidity matters for comfort because the same temperature feels different in dry and damp air. The sketch uses a standard heat-index formula: a simple estimate when the air is cooler than about 27 C, and the fuller regression formula when it is warmer, then maps the result to one friendly word on the display: Cool, Dry, Comfy, Damp, Warm, Sticky or Hot. The numbers behind it are shown below the word. The display and the sensor share the same two I2C wires, which is why they both go to A4 and A5, and each has its own address. The heat index is an estimate designed for warm weather, so the labels at the cool end are only a simple guide, and the boundaries are a matter of taste: change the numbers in the label function to suit your room. Keep the sensor away from the Nano and the breadboard regulator, because they warm the air and push the temperature up a degree or two.

Runs on a virtual Arduino Nano 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_AHTX0.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_AHTX0 aht;
Adafruit_SSD1306 oled(128, 64, &Wire, -1);

// Heat index estimate in Fahrenheit (Rothfusz regression, used above about 80 F)
float heatIndexF(float t, float rh) {
  float simple = 0.5 * (t + 61.0 + ((t - 68.0) * 1.2) + (rh * 0.094));
  if (simple < 80.0) return simple;
  return -42.379 + 2.04901523 * t + 10.14333127 * rh - 0.22475541 * t * rh
         - 0.00683783 * t * t - 0.05481717 * rh * rh + 0.00122874 * t * t * rh
         + 0.00085282 * t * rh * rh - 0.00000199 * t * t * rh * rh;
}

const char* label(float feelsC, float rh) {
  if (feelsC < 16) return "Cool";
  if (feelsC < 25) return (rh < 30) ? "Dry" : (rh > 65 ? "Damp" : "Comfy");
  if (feelsC < 30) return (rh > 60) ? "Sticky" : "Warm";
  return "Hot";
}

void setup() {
  Serial.begin(9600);
  if (!aht.begin()) { Serial.println("AHT20 not found"); while (1) { } }
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println("OLED not found"); while (1) { } }
  oled.setTextColor(SSD1306_WHITE);
}

void loop() {
  sensors_event_t hum, temp;
  aht.getEvent(&hum, &temp);
  float tc = temp.temperature, rh = hum.relative_humidity;
  float feelsC = (heatIndexF(tc * 9.0 / 5.0 + 32.0, rh) - 32.0) * 5.0 / 9.0;

  oled.clearDisplay();
  oled.setTextSize(2);
  oled.setCursor(0, 0);
  oled.print(label(feelsC, rh));
  oled.setTextSize(1);
  oled.setCursor(0, 28);
  oled.print("Temp  "); oled.print(tc, 1); oled.println(" C");
  oled.print("Humid "); oled.print(rh, 0); oled.println(" %");
  oled.print("Feels "); oled.print(feelsC, 1); oled.println(" C");
  oled.display();

  Serial.print(tc); Serial.print(","); Serial.println(rh);
  delay(2000);
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

AHT20 not found

Test checklist

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

CheckExpected
Normal roomComfy or Cool, sensible numbers
Breath near the sensorHumidity jumps for a few seconds
Sensor disconnectedSerial says AHT20 not found
Display disconnectedSerial says OLED not found
Warm and humid roomSticky or Hot

If it does not work

AHT20 not found

Check SDA and SCL and the supply voltage of your module.

OLED not found

Try address 0x3D instead of 0x3C.

Temperature reads high

Move the sensor away from warm parts.

Display is blank

Check the display library size, 128 by 64.

Text is cut off

Reduce the text size.

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

Ask Lark AI

Common questions

What parts do I need for the comfort index display?

Arduino Nano, AHT20 temperature and humidity sensor, SSD1306 OLED Display and Breadboard 830 Tie Points.

How long does the comfort index display take to build?

About 60 minutes for a beginner maker, in 8 steps.

How do I know the comfort index display works?

Normal room: Comfy or Cool, sensible numbers. Breath near the sensor: Humidity jumps for a few seconds. Sensor disconnected: Serial says AHT20 not found.

AHT20 not found: what should I check?

Check SDA and SCL and the supply voltage of your module.

OLED not found: what should I check?

Try address 0x3D instead of 0x3C.

Temperature reads high: what should I check?

Move the sensor away from warm parts.

Display is blank: what should I check?

Check the display library size, 128 by 64.