Introduction: Automatic Bathroom Fan With Arduino Nano
Do you know that annoying feeling when you have to get out of your bed to turn off the bathroom fan? The one which you must switch on because otherwise everything gets wet and eventually mouldy in your place? Well, you can forget about that now with this little gadget :)
The small DHT22 temperature/humidity sensor measures the relative humidity in every 15 seconds. It calculates an average of the last three measurements, and if the value is higher than 65% it turns on the fan. When the fan is turned on, it will run for at least 2 minutes. During this time all measurements are ignored. After the fan is switched off, measurements will be ignored for 10 minutes.
This is to avoid the fan switching on and off when the humidity is hanging on the edge.
Parts needed:
-Bathroom fan (any type will do, I used one with automatic shutters, called SIKU 100-AZ)
-Arduino Nano
-Mini-USB cable
-220 V - USB phone charger/power supply
-DHT22 Temperature/Humidity sensor
-Grove relay (10 A) [any relay will do with the same specifications]
1. Connect the DHT22 pin VCC (first from the left if you're looking at the side with the grill) to Arduino Nano. +3.3 V output. You could connect it to the +5 V as well, but we'll need that for the relay.
2. Connect the second pin on the DHT22 to Arduino A2
3. Connect the far right pin of the DHT22 to Arduino GND.
4. Connect the relay to the Arduino with the Grove Cable.
Red: +5V
Black: GND
Yellow: D7
White: not connected.
5. Upload the program.
6. Connect the Arduino to the power supply with the micro USB cable and plug the power supply into the connector.
7. Check if it works: once it's on, blow humid air (from your mouth for example) on the grill of the DHT22 sensor. Keep doing it, it must stay humid for at least 45 seconds to trigger the fan. Listen to the click of the relay after 45-50 seconds. If it's there'you're good.
THE STEPS BELOW HERE ARE DEALING WITH HIGH VOLTAGE. PROCEED ONLY IF YOU KNOW WHAT YOU'RE DOING AND ALWAYS USE A MULTIMETER TO CHECK IF THERE'S VOLTAGE BEFORE YOU TOUCH ANY CABLES!
8. Switch off the mains power in your bathroom or wherever you're planning to mount the fan.
9. Check with a voltage meter (multimeter) if there's still electricity in the wires: Switch it to ~ mode (AC) and to a range which is greater than 250 V - usually it's 600 V.
Carefully touch one of the cables with one and the other with the other measuring pin. Do not touch them yourself and only hold the rubber part. If you're sure there's no voltage in it, you can proceed.
10. Connect the null wire to the fan's null input. It is usually marked with a blue color or it is just a wire without any plastic on it.
11. Connect the hot wire (the one that carries the voltage) to the relay's contact marked COM for COMMON. This wire is usually marked black (to remember more easily, black means death - just if you touch it).
12. Connect the other contact of the relay marked N.O (Normally Open) to the fan's hot wire input.
13. Turn the electricity back and see if it works. :)
Attachments

Participated in the
Arduino All The Things! Contest
3 Comments
1 year ago
I made a similar project some time ago unfortunately tried several humidity sensors and every time they stop working properly after a while. I think they get dust inside them and stop reading humidity properly.
Reply 1 year ago
I'm using the same DHT22 sensor for like I think 4 years now and it's still going completely fine although it's pins became rusty 😅 and also I have never cleaned it so I don't think so that the dust can cause such malfunction.
For me the setup that is working properly is
if humidity>99 for 10s then turn on the fan
if humidity<98 for 10s then turn off the fan (actually time for turning off could be a little big bigger)
At the beginning when I was starting my project I have used some funny low value for the humidity condition and the fan would never turn off. In the region where I live the air humidity varies in between 30 and 60%.
Dunno how much different it's for your region. Also the humidity on the outside and inside your house can be a little bit different. The place of your sensor and the layout and size of the bathroom also matters pretty much as well as the temperature in the room (because the sensor is measuring the relative humidity). There are a lot of variables that influence the humidity in the bathroom and the best solution would be just measuring the humidity in your bathroom before, during and after taking a shower and just after collecting some data tweaking the code's conditions and delays values so the fan will turn on and off when it should.
What I think could possibly happen to your setup is that for 2 days it was working perfectly fine and then the weather changed so the humidity raised so even if you weren't taking a shower the fan just kept running because the outside humidity which affects also humidity inside your house was just to high for it to ever turn off.
The other thing that comes to my mind is the relay's and fan engine's coils are generating some interferences that affect somehow the microcontroller but I don't have any experience or knowledge about that - maybe moving arduino away from the fan and relay would give some result.
Or maybe it can be just a poor power supply - after the relay's coil is powered the voltage drop and affect arduino.
5 years ago
I made it!
It was working great for 2 days activating on humidity etc.
After 2 days I discovered the fan is on all the time and never turns off.
What happened? There are two possibilities - one is that the humidity sensor broke in some way. The other is that the code has some bug in it. I tried resetting the arduino and it didnt help.
But at least the code restarted and i dont think its causing it.
So no idea what's causing it to keep the fan on all the time other then the humidity sensor beeing broken?