Automatic Vent Control



This machine starts a vent through a relay in ether an automatic mode or manual.
1. Automatic mode : The vent start whenever the humidity levels in the room (bathroom) is higher then the levels selected by the user in the humidity level knob and stops when the levels dropped below.
2. Manual Mode : The vent starts when the start button pressed and stops according to the duration select knob.
Parts List







Arduino pro mini (5v)
2 X 220ohm Resistors
2 X 1k Potentiometers
Realy module
AM2301 (boxed DHT22) humidity / temperature sensor
5v Regulator
Bunch of cables
Press Button (I used a doorbell button)
You Will Also Need
You will also need the DHTxx Arduino library
The Code
#include
dht DHT;
#define Rel 7 #define Buttn 4 #define onTime A1 #define trashold A0 #define DHT22_PIN 5
long sensCount = millis ();
void setup() { Serial.begin(9600); pinMode (Rel, OUTPUT); pinMode (Buttn, INPUT);
}
void loop() { // READ DATA if (millis () < sensCount) { sensCount = millis (); } /* millis() resets every 50 days or so */ if (millis () >= sensCount + 5000) { Serial.print("DHT22, \t"); int chk = DHT.read22(DHT22_PIN); switch (chk) { case DHTLIB_OK: Serial.print ("OK,\t"); Serial.print (DHT.humidity,1); Serial.print (",\t"); Serial.print (DHT.temperature, 1); Serial.print (",\t"); Serial.println (map (analogRead (trashold), 1, 1023, 45, 95)); break; case DHTLIB_ERROR_CHECKSUM: Serial.println ("Checksum error,\t"); break; case DHTLIB_ERROR_TIMEOUT: Serial.println ("Time out error,\t"); break; default: Serial.println ("Unknown error,\t"); break; } sensCount = millis (); } if (DHT.humidity >= map (analogRead (trashold), 1, 1023, 45, 95)) { digitalWrite (Rel, HIGH); } else digitalWrite (Rel, LOW);
/* Manual Ignition */ if (digitalRead (Buttn) == HIGH) { long delayButtn = map (analogRead (onTime), 0, 1023, 1, 61) * 6000; long startTime = millis (); digitalWrite (Rel, HIGH); /* Delay Loop */ while (millis () <= delayButtn + startTime) { Serial.println (map (delayButtn + startTime - millis (), 0, 3600000, 1, 60)); if (startTime > millis () ) { /* millis() resets every 50 days or so */ startTime = millis (); } delayButtn = map (analogRead (onTime), 0, 1023, 1, 61) * 60000; } digitalWrite (Rel, LOW); } } // // END OF FILE //