Ariani GomezDaniel Law
Published

Lane Tech HS - Temperature Controlled Fan

Based on the time of day and temperature of my room, my fan will change speed to meet my desired comfortable temperature.

BeginnerFull instructions provided4 hours158
Lane Tech HS - Temperature Controlled Fan

Things used in this project

Hardware components

Argon
Particle Argon
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1

Story

Read more

Schematics

Fan Controller Breadboard

Fan Controller Schematic

Code

Fan Controller Code

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>


Servo servo;

//define the temperature and humidity sensor
#define DHTTYPE DHT11
#define DHTPIN D8

//initialize the DHT sensor with the name 'sense'
DHT sense(DHTPIN, DHTTYPE);

//temperature variable
double temperature;
double tempCheck;
double tempL = 0.00;
double tempR = 110.00;
int lastDebounceMin = 1;  // the last time temperature was checked
int debounceDelay = 5; // how many minutes in between each check
int currHour; // hour its being run
int currMin; // minute its being run


//how many times the fan has been pressed, mine only has 3 availible modes
int p;
void push(int x);
void levelDown();
void turnOff();
int pos = 0;

void setup() 
{
     servo.attach(6);
     pinMode(D8, OUTPUT);
     Serial.begin(9600); 
     sense.begin();
     Time.zone(-6);
     p=0;
     servo.write(180);
}
void loop() 
{
    currHour=Time.hour();
    currMin=Time.minute();
    if ((currMin - lastDebounceMin) >= debounceDelay)
    {
        lastDebounceMin = currMin;
        Serial.print("Last Check: ");
        Serial.print(currHour);
        Serial.print(":");
        Serial.println(currMin);
        
        tempCheck = sense.getTempFarenheit();
        // ensures that data is within reason
        
        if (tempL<tempCheck<tempR)
        {
            temperature = tempCheck;
            Serial.print( "Temperature = " );
            Serial.println(temperature);
            if((5 < currHour)&&(currHour<9))
            {
                if(72< temperature)
                {
                    //turn on fan when too hot
                    if (p<3)
                    {
                        push(1);
                        p++;
                        Serial.print("Press number: ");
                        Serial.println(p);
                    }
                          
                }
                else if(65 > temperature)
                {
                    //turn off fan when too cold
                    turnOff();
                    Serial.print("Press number: 0 ");
                    
                }
            }
            //at bedtime I prefer the room to be colder
            else if((19 < currHour)&&(currHour<24))
            {
                if(65.00 <= temperature)
                {
                    //turn on fan when too hot
                    if (p<3)
                    {
                        push(1);
                        p++;
                        Serial.print("Press number: ");
                        Serial.println(p);
                    }
                  
                }
                else if(55.00 > temperature)
                {
                   //turn down fan when too cold
                    levelDown();
                    p--;
                    Serial.print("Press number: ");
                    Serial.println(p);
                   
                }
                
            }
            //the time in between is just a general comfort zone
            else
            {
                if(70.00 <= temperature)
                {
                    //turn on fan when too hot
                    if (p<3)
                    {
                        push(1);
                        p++;
                        Serial.print("Press number: ");
                        Serial.println(p);
                    }
                  
                }
                else if(65.00 > temperature)
                {
                    //turn down fan when too cold
                    levelDown();
                    p--;
                    Serial.print("Press number: ");
                    Serial.println(p);
                }
            }
        }     
    }
}

void push(int x)
{
    int count = 0;
    while(count < x)
    {
        for(pos = 180; pos>=10; pos-=1)     
        {
            servo.write(pos);              
            delay(15);                     
        }
        delay(500);
        for(pos = 10; pos < 180; pos += 1)  
        {                                 
            servo.write(pos);              
            delay(15);              
        }
        
        count++;
    }
    
}
void levelDown()
{
    push(3);
}
void turnOff()
{
    if(p==1)
    {
        push(3);
    }
    else if(p==2)
    {
        push(2);
    }
    else if(p==3)
    {
        push(1);
    }
}

Credits

Ariani Gomez

Ariani Gomez

3 projects • 2 followers
Daniel Law

Daniel Law

46 projects • 9 followers
Teacher. Maker. Citizen of the planet.

Comments