Automatic Fan to Cool Your Room

Does your room ever get too hot or humid? Try out this automatic fan (results may vary)!

Project Description

This project was inspired by the need to make my room more comfortable during hot or humid days. Using a DHT11 Sensor, I measured the average temperature and humidity of my room and created a program to automatically turn on the fan when those values exceeded a certain threshold.

Important Notes:

  • The fan used in this project isn’t very powerful, but it’s an excellent way to learn how to use a motor controller and a DHT11 sensor.
  • Don’t forget to press the button on the breadboard power supply module to activate it! (I spent too much time troubleshooting this before realizing it.)

Components and Supplies

  1. Arduino Uno Rev3
  2. 5V DC Motor
  3. DHT11 Sensor
  4. M-M Jumper Wires (Pack of 6)
  5. L293D Motor Driver
  6. Breadboard – 830 Contacts
  7. USB 2.0 Cable Type A/B
  8. M-F Jumper Wires (Pack of 3)
  9. 9V Battery with Clip
  10. Breadboard Power Supply Module

Code:

@@ -1,6 +1,6 @@
/************************
Exercise the motor using
the L293D chip
ARDUINO AUTOMATIC FAN.
COOLING NOT GUARENTEED
************************/
#include <dht_nonblocking.h>
//Initializing Variables
@@ -9,9 +9,10 @@ the L293D chip
#define ENABLE 5
#define DIRA 3
#define DIRB 4
static const int DHT_SENSOR_PIN = 2;
int i;
DHT_nonblocking dht_sensor( DHT_SENSOR_PIN, DHT_SENSOR_TYPE );

DHT_nonblocking dht_sensor(DHT_SENSOR_PIN, DHT_SENSOR_TYPE);
/*
* Initialize the serial port.
@@ -27,49 +28,57 @@ void setup() {
* Poll for a measurement, keeping the state machine alive. Returns
* true if a measurement is available.
*/
static bool measure_environment( float *temperature, float *humidity )

static bool measure_environment(float *temperature, float *humidity)
{

static unsigned long measurement_timestamp = millis( );
/* Measure once every four seconds. */

if( millis( ) – measurement_timestamp > 3000ul )

if(millis() – measurement_timestamp > 3000ul)
{

if( dht_sensor.measure( temperature, humidity ) == true )

if(dht_sensor.measure(temperature, humidity) == true)
{

measurement_timestamp = millis( );

return( true );
measurement_timestamp = millis();

return(true);
}
}
return( false );
return(false);
}
/*
* Main program loop.
*/
void loop( )
void loop()
{
float temperature;
float humidity;

/* Measure temperature and humidity. If the functions returns
true, then a measurement is available. */


if( measure_environment( &temperature, &humidity ) == true )
true, then a measurement is available. */

if(measure_environment(&temperature, &humidity) == true)
{
//Prints out temp and humidity around the sensor

Serial.print( “T = ” );

Serial.print( temperature, 1 );

Serial.print( ” deg. C, H = ” );

Serial.print( humidity, 1 );

Serial.print(“T = “);

Serial.print(temperature, 1);

Serial.print(” deg. C, H = “);

Serial.print(humidity, 1);

Serial.println( “%” );

if(temperature >= 75 || humidity >= 100 ){ //Should in theory turn on the fan if the temp is higher than 75 or if humidity is higher than 100%
if(temperature >= 75 || humidity >= 60){ //Turns on the fan if the temp is higher than 75 or if humidity is higher than 60%(just as it begins to feel muggy).

Serial.println(“Activating Fan..”);

analogWrite(ENABLE,255); //enable on

digitalWrite(DIRA,255);

digitalWrite(DIRB,LOW);

Serial.println(“Fan on”);

delay(240000);

delay(300000); // 5 minutes in milliseconds

Serial.println(“Fan off”);

digitalWrite(ENABLE,LOW); //all done

Serial.print(“Cool Down Completed!”);
}
else{

Serial.println(“Environment is looking livible!”);
}
}
else{
Serial.println(“Attempting to read from DHT sensor…”);
}
}

Leave a Reply