Carson McClellandPeter Ensor
Published

Temperature Controlled Fan

This project is meant to give users the ability to have temperature dependent fan speed while working out.

BeginnerWork in progress214
Temperature Controlled Fan

Things used in this project

Hardware components

Photon
Particle Photon
×2
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
×1
Stepper Motor, Mini Step
Stepper Motor, Mini Step
×1
Breadboard (generic)
Breadboard (generic)
×2
Jumper wires (generic)
Jumper wires (generic)
×9

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
ThingSpeak API
ThingSpeak API
Maker service
IFTTT Maker service

Story

Read more

Schematics

Servo Motor Alone

Code

Code for Temperature Sensor

C/C++
This was our code to troubleshoot and find a way to get our temperature sensor to work.
#include <Adafruit_DHT.h>

#define DHTPIN 2
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

unsigned long last_time=0;
int how_often = 10000; //Take reading every 10 seconds
bool Celcius_or_Farenheit = true; //false for C, true for F

void setup() {
dht.begin();
}

void loop() {
if(millis()-last_time>how_often){
    String data = take_reading(Celcius_or_Farenheit);
    Particle.publish("tsenscrm", data);
    last_time = millis();
}
}

String take_reading(bool CorF){ //false for C, true for F
float t;
if(CorF){
    t = dht.getTempFarenheit();
}
else{
    float t = dht.getTempCelcius();
}
    return String(t);
}

Servo Code

C/C++
This code is from the Particle tutorial section. Everything was left inside the code, however, a lot of the code was "commented" out.
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created

int pos = 0;    // variable to store the servo position

void setup()
{
    Particle.function("gong", gong);  // create a function called "gong" that
                                      // can be called from the cloud
                                      // connect it to the gong function below

    myservo.attach(D0);   // attach the servo on the D0 pin to the servo object
    myservo.write(0);    // test the servo by moving it to 25°
    pinMode(D7, OUTPUT);  // set D7 as an output so we can flash the onboard LED
}

int gong(String command)   // when "gong" is called from the cloud, it will
{                          // be accompanied by a string.
    if(command == "now")   // if the string is "now", ring the gong once.
    {                            
        myservo.write(270);       // move servo to 0° - ding!
        digitalWrite(D7, HIGH); // flash the LED (as an indicator)
        delay(1000);             // wait 100 ms
       //myservo.write(3060);      // move servo to 25°
       digitalWrite(D7, LOW);  // turn off LED
        return 1;               // return a status of "1"
    }
    //else if(command == "alarm")     // if the string is "alarm",
    {                               
        //for (int i = 0; i < 3; i++) // ring the gong 3 times.
        {
           // myservo.write(0);       // move servo to 0° - ding!
            //digitalWrite(D7, HIGH); // flash the LED
            //delay(100);             // wait 100 ms
            //myservo.write(0);      // move servo to 25°
            //digitalWrite(D7, LOW);  // turn off LED
            //delay(1000);            // wait 1 second between gongs
        }
        //return 2;                   // return a status of "2"
    }
}

void loop()
{
  // empty because we call the gong function via the cloud
}

Credits

Carson McClelland

Carson McClelland

1 project • 0 followers
Peter Ensor

Peter Ensor

1 project • 0 followers
Thanks to Arduino “having11” Guy and Particle.

Comments

Add projectSign up / Login