Build it step by step
0 of 7 doneWire the sensor
Check humidity on the serial monitor.
Test the relay and fan
Run a test sketch that clicks the relay.
Upload the sketch
Breathe on the sensor to raise the reading.
Watch the fan start
It should start above 70 percent.
Wait for it to stop
It should stop below 60 percent after at least five minutes.
Check the safety stop
Reduce MAX_RUN_MS and test it.
Mount it
Keep the sensor out of direct spray and electronics dry.
How do you build a bathroom fan on moisture?
A small 12 V fan switches on when humidity rises after a shower and off when it is back to normal. You need Arduino Nano, SHT31 temperature and humidity sensor, Relay Module 5V, 12 V DC fan 80 mm and 12 V 2 A DC adapter. It takes 7 steps and about 60 minutes.
- Level
- Beginner
- Time
- About 60 min
- Parts
- 5
Parts list
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- InterfacesBuyRelay Module 5V × 1
- Motors & ActuatorsBuy
- PowerBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| SHT31 VCC | Nano 5V | Power, check your module accepts 5 V |
| SHT31 GND | Nano GND | Ground |
| SHT31 SDA | Nano A4 | I2C data |
| SHT31 SCL | Nano A5 | I2C clock |
| Relay module VCC | Nano 5V | Coil power |
| Relay module GND | Nano GND | Ground |
| Relay module IN | Nano D7 | Control signal |
| 12 V adapter + | Relay COM | Fan supply |
| Relay NO | Fan + | Switched positive |
| Fan - and adapter - | Joined | Return path |
Code
This build uses a 12 V DC fan so everything is low voltage. A real mains bathroom extractor fan must be wired by a qualified electrician; use this project to learn the control idea and test with the small fan. The two humidity thresholds (switch on at 70, off at 60) are the hysteresis that stops the fan switching on and off at the edge. The minimum run time stops short bursts, and the maximum run time stops it running all day if a window is open and the room never dries. Place the sensor away from the shower spray and the fan's own airflow. Arduino IDE, board "Arduino Nano" (processor ATmega328P, or ATmega328P (Old Bootloader) for clones).
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).
// Library: Adafruit SHT31. Relay modules are usually active-low, change ACTIVE_LOW if yours is not.
#include <Wire.h>
#include <Adafruit_SHT31.h>
Adafruit_SHT31 sht;
const byte RELAY = 7;
const bool ACTIVE_LOW = true;
const float ON_RH = 70.0, OFF_RH = 60.0; // hysteresis
const unsigned long MIN_RUN_MS = 5UL * 60 * 1000; // run at least 5 minutes
const unsigned long MAX_RUN_MS = 45UL * 60 * 1000; // and stop after 45 minutes anyway
bool fanOn = false;
unsigned long fanStart = 0;
void fan(bool on) {
digitalWrite(RELAY, (on == ACTIVE_LOW) ? LOW : HIGH);
fanOn = on;
if (on) fanStart = millis();
}
void setup() {
Serial.begin(9600);
pinMode(RELAY, OUTPUT);
fan(false);
if (!sht.begin(0x44)) { Serial.println("SHT31 not found"); while (1) {} }
}
void loop() {
float h = sht.readHumidity();
if (!isnan(h)) {
unsigned long ran = millis() - fanStart;
if (!fanOn && h > ON_RH) { fan(true); Serial.println("fan on"); }
else if (fanOn && ((h < OFF_RH && ran > MIN_RUN_MS) || ran > MAX_RUN_MS)) { fan(false); Serial.println("fan off"); }
Serial.print(h, 1); Serial.println(" %RH");
}
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.
SHT31 not found
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Breath on the sensor | Humidity rises above 70 |
| Fan | Starts and runs at least five minutes |
| Back to normal | Fan stops below 60 percent |
| Maximum run reached | Fan stops anyway |
If it does not work
Fan never starts
Check the relay logic (ACTIVE_LOW) and the 12 V wiring.
Sensor not found
Check the I2C address 0x44 and wiring.
Fan flaps on and off
Widen the thresholds.
Readings stay high
Move the sensor away from damp surfaces.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the bathroom fan on moisture?
Arduino Nano, SHT31 temperature and humidity sensor, Relay Module 5V, 12 V DC fan 80 mm and 12 V 2 A DC adapter.
How long does the bathroom fan on moisture take to build?
About 60 minutes for a beginner maker, in 7 steps.
How do I know the bathroom fan on moisture works?
Breath on the sensor: Humidity rises above 70. Fan: Starts and runs at least five minutes. Back to normal: Fan stops below 60 percent.
Fan never starts: what should I check?
Check the relay logic (ACTIVE_LOW) and the 12 V wiring.
Sensor not found: what should I check?
Check the I2C address 0x44 and wiring.
Fan flaps on and off: what should I check?
Widen the thresholds.
Readings stay high: what should I check?
Move the sensor away from damp surfaces.
