xingkong123600 发表于 2014-6-1 22:37:28

检测温度和湿度,单加温度正常,加上湿度温度忽高忽低,但是湿度带动马达后,温度正常

检测温度和湿度,单加温度正常,加上湿度温度忽高忽低,但是湿度带动马达后,温度正常,,是什么原因。。。。太纠结了。。。。:'(:'(




int tempPin = 2;//wendu
long valtemp = 0;
float temperature = 0;

int wetPin = 3;//shidu
longvalwet = 0;
float wet= 0;
void setup() {   


   
pinMode(5,OUTPUT);//wendu
pinMode(6,OUTPUT);//shidu

pinMode(3,OUTPUT);//fan
pinMode(2,OUTPUT);//curtain

Serial.begin(9600);

}




void loop() {

tempTest();
wetTest();


delay(400);
}




void wetTest(){
   valwet=analogRead(wetPin);
   wet = (valwet*0.0048828125*100);
   Serial.print("shidu=");
   Serial.println(wet);

   if ( wet> 23 && f == 0){
digitalWrite( 6 , LOW );//led
digitalWrite( 2 , HIGH );//curtain
}else if( wet< 23 && f == 0){
digitalWrite( 6, HIGH );//LED
digitalWrite( 2 , LOW );//curtain
}
}


void tempTest(){
   valtemp=analogRead(tempPin);
temperature = (valtemp*0.0048828125*100);
   Serial.print("Tep=");
   Serial.print(temperature);
   Serial.println(" C");

   if ( temperature> 40 && f == 0){
digitalWrite( 5 , HIGH );//LED
digitalWrite( 3 , HIGH );//open fan
   }else if(temperature<40 && f == 0){
digitalWrite( 5 , LOW );
digitalWrite( 3 , LOW );//close fan\
if( temperature<30)digitalWrite( 9 , HIGH );//open heater
if(temperature>30)digitalWrite( 9 , LOW );//close
}

}

eddiewwm 发表于 2014-6-2 11:56:56

除了以下要汪意外,整體還可以,所述的 "加上湿度温度忽高忽低" 問題,很大可能是硬件那邊的問題,應小心檢查。

1)if ( ....&& f == 0){    //當中的 f 是甚麼?
2) 以下的用途無效
if( temperature<30)digitalWrite( 9 , HIGH );//open heater
if(temperature>30)digitalWrite( 9 , LOW );//close

xingkong123600 发表于 2014-6-2 15:13:57

eddiewwm 发表于 2014-6-2 11:56 static/image/common/back.gif
除了以下要汪意外,整體還可以,所述的 "加上湿度温度忽高忽低" 問題,很大可能是硬件那邊的問題,應小心檢 ...

代码改过了,,但还是互相影响,,谢谢了
页: [1]
查看完整版本: 检测温度和湿度,单加温度正常,加上湿度温度忽高忽低,但是湿度带动马达后,温度正常