Humidity Sensor-Controlled Bathroom Exhaust Fan
Accumulation of moisture in a closed up space like a bathroom can lead to the appearance of mould, which can cause health issues.
Components and supplies
1
Arduino Nano
1
DHT11 Temperature & Humidity Sensor (4 pins)
1
12v 1A power supply
1
12V 200mm DIA computer casing fan
1
MOSFET board
1
Jumper wires (generic)
Tools and machines
1
Hot glue gun (generic)
Project description
Code
Arduino Sketch
arduino
1#include <SimpleDHT.h> 2 3//Declaring digital pin no 2 as the dht11 4 data pin 5 6int pinDHT11 = 2; 7int DHTpower = 3; 8int Fan = 13; 9SimpleDHT11 10 dht11; 11 12void setup() { 13 pinMode(Fan, OUTPUT); 14 pinMode(DHTpower, OUTPUT); 15 16 digitalWrite(DHTpower, LOW); 17 digitalWrite(Fan, LOW); 18 Serial.begin(9600); 19 20} 21 22void loop() { 23 delay(1000); 24 RHcheck(); //check 25 Humidity Level 26 delay(15000); //wait 15sec 27 } 28 29 30void 31 RHcheck() { //Check Humidity Level Function 32 digitalWrite(DHTpower, 33 HIGH); //On Humidity Sensor 34 delay(5000); 35 Serial.println("============ 36 Check Humidity ==============="); 37 delay(1000); 38 Serial.println("DHT11 39 readings..."); 40 41 byte temperature = 0; 42 byte humidity = 0; 43 int 44 err = SimpleDHTErrSuccess; 45 46 //This bit will tell our Arduino what to do 47 if there is some sort of an error at getting readings from our sensor 48 if ((err 49 = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { 50 51 Serial.print("No reading , err="); Serial.println(err);delay(1000); 52 return; 53 54 } 55 Serial.print("Readings: "); 56 Serial.print((int)temperature); Serial.print(" 57 C, "); 58 Serial.print((int)humidity); Serial.println(" %"); 59 delay(500); 60 61 if((int)humidity < 50){ 62 digitalWrite(DHTpower, LOW); 63 delay(500); 64 65 Serial.println("Fan OFF"); 66 delay(500); 67 digitalWrite(Fan, LOW); 68 69 }else{ 70 if ((int)humidity > 58){ 71 Serial.println("Humidity > 58%"); 72 73 digitalWrite(DHTpower, LOW); 74 delay(500); 75 Serial.println("Fan 76 ON @ full speed"); 77 delay(500); 78 digitalWrite(Fan, HIGH); 79 }else{ 80 81 Serial.println("50% < Humidity < 58%"); 82 digitalWrite(DHTpower, 83 LOW); 84 delay(500); 85 Serial.println("Fan ON @ low speed"); 86 87 delay(500); 88 analogWrite(Fan, 150); 89 } 90 } 91 } 92
Arduino Sketch
arduino
1#include <SimpleDHT.h> 2 3//Declaring digital pin no 2 as the dht11 data pin 4 5int pinDHT11 = 2; 6int DHTpower = 3; 7int Fan = 13; 8SimpleDHT11 dht11; 9 10void setup() { 11 pinMode(Fan, OUTPUT); 12 pinMode(DHTpower, OUTPUT); 13 digitalWrite(DHTpower, LOW); 14 digitalWrite(Fan, LOW); 15 Serial.begin(9600); 16} 17 18void loop() { 19 delay(1000); 20 RHcheck(); //check Humidity Level 21 delay(15000); //wait 15sec 22 } 23 24 25void RHcheck() { //Check Humidity Level Function 26 digitalWrite(DHTpower, HIGH); //On Humidity Sensor 27 delay(5000); 28 Serial.println("============ Check Humidity ==============="); 29 delay(1000); 30 Serial.println("DHT11 readings..."); 31 32 byte temperature = 0; 33 byte humidity = 0; 34 int err = SimpleDHTErrSuccess; 35 36 //This bit will tell our Arduino what to do if there is some sort of an error at getting readings from our sensor 37 if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { 38 Serial.print("No reading , err="); Serial.println(err);delay(1000); 39 return; 40 } 41 Serial.print("Readings: "); 42 Serial.print((int)temperature); Serial.print(" C, "); 43 Serial.print((int)humidity); Serial.println(" %"); 44 delay(500); 45 if((int)humidity < 50){ 46 digitalWrite(DHTpower, LOW); 47 delay(500); 48 Serial.println("Fan OFF"); 49 delay(500); 50 digitalWrite(Fan, LOW); 51 }else{ 52 if ((int)humidity > 58){ 53 Serial.println("Humidity > 58%"); 54 digitalWrite(DHTpower, LOW); 55 delay(500); 56 Serial.println("Fan ON @ full speed"); 57 delay(500); 58 digitalWrite(Fan, HIGH); 59 }else{ 60 Serial.println("50% < Humidity < 58%"); 61 digitalWrite(DHTpower, LOW); 62 delay(500); 63 Serial.println("Fan ON @ low speed"); 64 delay(500); 65 analogWrite(Fan, 150); 66 } 67 } 68 } 69
Downloadable files
Wiring Schematic
Wiring Schematic

Comments
Only logged in users can leave comments