Motion Activated Temperature Controlled Fan -


hello,

im currenthly building motion activated temperature controlled fan. have 5v dc motor, pir sensor, lm35 temp sensor , 20 x4 i2c lcd. im using arduino mega. motor suppose cut on  @ temperature if motion sense. tried use if , else if statements control this. beginner im looking guidance in formulation of code. 

any appreciated

this code :
#include <wire.h>
#include <liquidcrystal_i2c.h>

liquidcrystal_i2c lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, positive);


int motorpin = 9;
int delaytime = 100; //milliseconds between each speed step
int calibrationtime = 30;       
long unsigned int lowin;
long unsigned int pause = 5000; 

boolean locklow = true;
boolean takelowtime; 
float tempc = 0;                                                 // variable holding celcius temp (floating decimal points precision)
float tempf = 0;
int temppin = a0;
int pirpin = 7;
int i;                                                // max/min temperature variables initial values. lm35 in simple setup measures temp above 0.


void setup() {
lcd.begin(20, 4);
lcd.setcursor(2,0); //start @ character 4 on line 0
lcd.print("motion activated");
delay(1000);
lcd.setcursor(3,2);
lcd.print("temperture fan");
delay(5000);
lcd.clear();

for(int = 0; < calibrationtime; i++){
  lcd.setcursor(2,0);
  lcd.print("calibrating sensor"); 
  delay(1000);
  }
     
   lcd.setcursor(3,3);
   lcd.print("sensor active");
    delay(5000); 

}

void loop() {
  analogread(temppin);
  tempc = analogread(temppin);          // read analog value lm35 sensor.
  tempc = (5.0 * tempc * 100.0)/1024.0;
  tempf = (tempc * 9)/ 5 + 32;       // converts fahrenheit
  lcd.setcursor(3,0);
  lcd.print(tempf);
 
  if (tempf>75 && digitalread(pirpin) == high)
   {
   
     lcd.clear();
     lcd.setcursor(2,1);
     lcd.print("motion detected");
     lcd.setcursor(0,2);
     digitalwrite(motorpin, high);
     lcd.print("fan on");
     if(locklow){                  //makes sure wait transition low before further output made:
         locklow = false;
         delay(50);
   }
   takelowtime = true;
   }
     else if ( tempf<75 && digitalread(pirpin) == high)
     {
      lcd.clear();
      lcd.setcursor(2,1);
      lcd.print("motion detected");
      digitalwrite(motorpin, low);
     }
     if(takelowtime){
        lowin = millis();          //save time of transition high low
        takelowtime = false;       //make sure done @ start of low phase
        }
                                                          //if sensor low more given pause,
                                                          //we assume no more motion going happen
       if(!locklow && millis() - lowin > pause){      //makes sure block of code executed again after
                                                    //a new motion sequence has been detected
           locklow = true;                       
           
           delay(50);
           }
       


}

quote
the motor suppose cut on  @ temperature if motion sense.
does matter if dog inside or not? can't imagine why turning fan on based on temperature , motion.

quote
this code :
and something. i'm going out on limb here , guessing not want. does, , how differs want mystery.


Arduino Forum > Using Arduino > Programming Questions > Motion Activated Temperature Controlled Fan -


arduino

Comments