Aden Zukas
Published © GPL3+

Automatic Temp-Sensing Fan

Home automation project creating device that allows ceiling fan to turn on and off through detection of certain thresholds of heat.

IntermediateShowcase (no instructions)3 hours36
Automatic Temp-Sensing Fan

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×1
Thermistor Resistor (10k ohms)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×4
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×14
Outlet Cable (5V)
×1
Resistor 10k ohm
Resistor 10k ohm
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Total wiring

Code

autotempfan code

C/C++
Combines Thermistor resistor data to activate servos that turn on the fan in my room
int ThermistorPin = 13;
int Vo;
float R1 = 10000;
float logR2, R2, T;
float c1 = 16.59490821e-03, c2 = -23.35666205e-04, c3 = 103.1153499e-07;

int on = 170;
int off= 10;

Servo onSwitch; //servo for the top of the switch which would turn the ceiling fan on
Servo offSwitch; //servo for the botoom of the switch which would turn the ceiling fan off

bool switchOff = true; // ceiling fan starts off; have to make code acknowledge when one is on or off to alternate.
bool switchOn = false; 

unsigned long previousMillis = 0;
const long interval = 1000; //interval for temp checking (1 second)

void setup(){
    
    Serial.begin(9600); //activates Serial monitor (for checking temp-sensing portion)
    
    onSwitch.attach(1); 
    offSwitch.attach(16);
    delay(100);
    onSwitch.write(off); //top servo set to off position
    offSwitch.write(off); //bottom servo set to off position
    
}


void loop(){
    unsigned long currentMillis = millis();
    
    //constantly updating last time temperature is checked to check on one second intervals
    if (currentMillis - previousMillis >= interval){
        previousMillis = currentMillis;
        
        //takes thermistor data and converts to temperature
        Vo = analogRead(ThermistorPin);
        R2 = R1 * (1023.0 / (float)Vo - 1.0);
        logR2 = log(R2);
        T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
        T = T - 273.15;
        T = (T * 9.0)/ 5.0 + 32.0; 
        
        //prints temperature values to serial monitor (testing purposes)
        Serial.print("Temperature: "); 
        Serial.print(T);
        Serial.println(" F"); 
        
        //gradually turns on fan when 90 degrees or above (for sake of testing)
        if(T >= 90.00){
            if(switchOn == false){
                for(int pos = off; pos <= on; pos++){ 
                    onSwitch.write(pos);
                    delay(15);
                }
                delay(1000);
                for(int pos = on; pos >= off; pos--){ 
                    onSwitch.write(pos);
                    delay(15);
                }
                switchOn = true;
                switchOff = false;
            }
        }
        //gradually turns off fan when the temperature is below the threshold
        if(T < 90.00){
            if(switchOff == false){
                for(int pos = off; pos <= on; pos++){ 
                    offSwitch.write(pos);
                    delay(15);
                }
                delay(1000);
                for(int pos = on; pos >= off; pos--){ 
                    offSwitch.write(pos);
                    delay(15);
                }
                switchOn = false;
                switchOff = true;
            }
        }
    }
}

Credits

Aden Zukas
2 projects • 0 followers
Lane Tech 2025
Contact

Comments

Please log in or sign up to comment.