Shane WhickerJustin Brown
Published

Temperature Controlled Automatic Fan

Are you tired of being too hot in the middle of the night when the fan is off, but too cold when its on? Now there is a solution.

IntermediateShowcase (no instructions)6 hours946
Temperature Controlled Automatic Fan

Things used in this project

Hardware components

BMP280 Temperature and Pressure Sensor (purple)
×1
Fan
×1
Photon
Particle Photon
×2
Berme 2 channel solid state relay
×1
Jumper wires (generic)
Jumper wires (generic)
×15

Hand tools and fabrication machines

Screwdriver
Wire strippers

Story

Read more

Schematics

Photon wiring (publishing)

Wiring diagram for the publishing or data gathering photon

Temperature Data

This is a temperature graph of data from the temperature sensor. The orange shows the value at which the fan turns on. Anything above that bar is when the fan is on.

Receiving photon wiring diagram

Code

Reciever photon

C/C++
int fanspeed1 = D2;
int fanspeed2 = D0;

 



 

void setup() {
    
    Particle.subscribe("on", temp_data, "44002b000c47343432313031");
    
    Particle.subscribe("off", temp_dataoff, "44002b000c47343432313031");
    
    
    
  
        
        
    


pinMode(fanspeed1, OUTPUT);

pinMode(fanspeed2, OUTPUT);

 

Particle.function("fan", fanToggle);


    digitalWrite(fanspeed1, LOW);

    digitalWrite(fanspeed2, LOW);

}

  void temp_data(const char*event, const char*data){
        digitalWrite(fanspeed1, HIGH);
  }

  void temp_dataoff(const char*event, const char*data){
        digitalWrite(fanspeed1, LOW);
  }
 

int fanToggle(String command) {


    if (command=="on"){

        digitalWrite(fanspeed1, HIGH);


    return 1;

    }

    else if (command=="off");{

    digitalWrite(fanspeed1, LOW);

 return 0;

    }


}

Temperature Photon

C/C++
#include "Adafruit_BMP280/Adafruit_Sensor.h"
#include "Adafruit_BMP280/Adafruit_BMP280.h"

 #define BMP_CS A2
 #define BMP_SCK A3
 #define BMP_MISO A4
 #define BMP_MOSI A5 

//Adafruit_BMP280 bmp; // I2C
Adafruit_BMP280 bmp(BMP_CS); // hardware SPI
//Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);

Timer timer(5000, checkEnvironment);

// Update to reflect current pressure at sea level
float seaLevelhPa = 1035.7;

void setup() {
    


  Particle.publish("DEBUG", "starting...");

  if (bmp.begin()) {
    Particle.publish("DEBUG", "starting the environment timer...");
    timer.start();
  }
  else {
    Particle.publish("WARN", "Could not find a valid BMP280 sensor, check wiring!");
  }

  Particle.publish("DEBUG", "started!");
}

void loop() {
    


    
}

void checkEnvironment() {
    
        
    float tempf = (cToF(bmp.readTemperature()));
    
    if (tempf <= 72) {Particle.publish("off", "off", 60);}
    
    if (tempf > 72) {Particle.publish("on", "on", 60);}
    

}



float cToF(float c) {
  return c * 9/5 + 32-5;
}

float pToHg(float p) {
  return p/3389.39;
}

Credits

Shane Whicker

Shane Whicker

1 project • 0 followers
Justin Brown

Justin Brown

1 project • 0 followers
Thanks to Shane Whicker and Justin Brown.

Comments