Projects / Bathroom exhaust fan on humidity

Bathroom exhaust fan on humidity

Beginner1.3 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANOAHT2026.0°C

    Test the sensor

    Print temperature and humidity.

  2. NANOAHT2026.1°C

    Learn the baseline

    Run for an hour and watch the average.

  3. NANOON

    Add the relay

    Hear it click from code.

  4. NANOAHT201226.1°C

    Wire the 12 V fan

    Use the NO terminal and a fuse on the adapter.

  5. NANO

    Add the rise rule

    Switch on at +10 percent.

  6. NANO

    Add the minimum run

    Keep it on for 5 minutes at least.

  7. NANOABS

    Fit it

    Mount the sensor where steam reaches it, electronics in a dry box.

In short

How do you build a bathroom exhaust fan on humidity?

A humidity sensor starts the bathroom exhaust fan when steam rises after a shower and stops it when the air is dry again. You need Arduino Nano, AHT20 temperature and humidity sensor, Relay Module 5V, ABS project box (100 × 60 × 25 mm), 12 V DC fan 80 mm and 12 V 2 A DC adapter. It takes 7 steps and about 75 minutes.

Level
Beginner
Time
About 75 min
Parts
6

Parts list

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

Wiring

FromToWhy
AHT20 VCC and GNDNano 5V and GNDPower
AHT20 SDANano A4I2C data
AHT20 SCLNano A5I2C clock
Relay module VCC and GNDNano 5V and GNDPower
Relay INNano D4Switch signal
12 V adapter plusRelay COMFan supply
Relay NO12 V fan plusSwitched fan supply
12 V fan minusAdapter minusFan return

Code

A fixed limit such as 70 percent does not suit every season, so the sketch learns the usual humidity slowly and reacts to a rise above it. The learning rate is slow enough that a shower does not become the new normal because the baseline stops adapting while the fan runs. This build switches only a 12 V DC fan through the relay. Keep the electronics and adapter outside the wet zone, in a dry box, and let only the fan sit in the damp area. Do not connect this to a mains exhaust fan yourself: a qualified electrician must wire any mains fan, with an approved switch or relay unit in an enclosure. Arduino IDE, board "Arduino Nano" (try the Old Bootloader option if the upload fails).

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).

// Humidity-triggered fan. Library: Adafruit AHTX0. Board: Arduino Nano.
#include <Adafruit_AHTX0.h>

Adafruit_AHTX0 aht;
const int RELAY = 4;
const float RISE_ON = 10.0, RISE_OFF = 3.0;      // percent above the usual level
const unsigned long MIN_RUN_MS = 5UL * 60 * 1000;
float baseline = 50;                              // slow average of the room's normal humidity
bool fanOn = false; unsigned long fanStart = 0;

void setup() {
  pinMode(RELAY, OUTPUT); digitalWrite(RELAY, HIGH);   // many relay boards are active LOW, HIGH = off
  Serial.begin(115200);
  if (!aht.begin()) { Serial.println("AHT20 not found"); while (1); }
  sensors_event_t h, t; aht.getEvent(&h, &t); baseline = h.relative_humidity;
}

void loop() {
  sensors_event_t h, t; aht.getEvent(&h, &t);
  float rh = h.relative_humidity;
  float rise = rh - baseline;

  if (!fanOn && rise > RISE_ON) { fanOn = true; fanStart = millis(); digitalWrite(RELAY, LOW); }
  if (fanOn && rise < RISE_OFF && millis() - fanStart > MIN_RUN_MS) { fanOn = false; digitalWrite(RELAY, HIGH); }

  if (!fanOn) baseline += (rh - baseline) * 0.002;      // learn the normal level only while the fan is off

  Serial.print("RH "); Serial.print(rh, 1); Serial.print(" base "); Serial.print(baseline, 1); Serial.print(" fan "); Serial.println(fanOn);
  delay(5000);
}

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
Breathe on the sensorHumidity jumps
After a showerFan starts within a minute
Dry air returnsFan stops after the minimum time
A rainy dayFan does not run all day

If it does not work

Fan never starts

Check the relay polarity (active LOW or HIGH).

Fan runs all the time

Lower the baseline learning rate or raise RISE_ON.

Sensor reads strangely

Keep it away from the fan's airflow and heat.

Relay chatters

Check that RISE_OFF is less than RISE_ON.

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

Ask Lark AI

Common questions

What parts do I need for the bathroom exhaust fan on humidity?

Arduino Nano, AHT20 temperature and humidity sensor, Relay Module 5V, ABS project box (100 × 60 × 25 mm), 12 V DC fan 80 mm and 12 V 2 A DC adapter.

How long does the bathroom exhaust fan on humidity take to build?

About 75 minutes for a beginner maker, in 7 steps.

How do I know the bathroom exhaust fan on humidity works?

Breathe on the sensor: Humidity jumps. After a shower: Fan starts within a minute. Dry air returns: Fan stops after the minimum time.

Fan never starts: what should I check?

Check the relay polarity (active LOW or HIGH).

Fan runs all the time: what should I check?

Lower the baseline learning rate or raise RISE_ON.

Sensor reads strangely: what should I check?

Keep it away from the fan's airflow and heat.

Relay chatters: what should I check?

Check that RISE_OFF is less than RISE_ON.