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.
-Bathroom fan (any type will do, I used one with automatic shutters, called SIKU 100-AZ)
-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.
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. :)