|
本帖最後由 tearouii 於 2019-1-15 18:46 編輯
#include <dht.h>
#define dht_dpin 2 溫溼度腳位定義
dht DHT;
int in1 = 5; //馬達腳位
int in2 = 6;
int in3 = 7;
int in4 = 8;
void setup(){
Serial.begin(9600);
delay(300);//Let system settle
Serial.println("Humidity and temperature\n\n");
delay(700);
pinMode(3, OUTPUT);//繼電器
pinMode(5, OUTPUT);//5~8馬達腳位輸出
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
}
void motor(){
if(DHT.temperature>24)//馬達
{
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
delay(260);
digitalWrite(in1,LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
delay(100);
digitalWrite(in1,LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
delay(250);
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
delay(1000);
}
else
{
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
delay(300);
digitalWrite(in1,LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
delay(300);
digitalWrite(in1,LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
delay(250);
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
delay(1000);
}
}
void loop(){
DHT.read11(dht_dpin); //溫溼度
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
delay(1000); //每1000ms 更新一次
if(DHT.temperature>24)
{
digitalWrite(3, LOW); //繼電器
motor();
}
else
{
digitalWrite(3, HIGH);
motor();
}
}
想把DHT.temperature的數據再引導新的出來運用到上面的馬達 void motor 那個
目前他會跑完一次 連同馬達完 再更新程式
我想要做到馬達感應到溫溼度感測器的數據後 跑一次
而不是一直 更新 然後 跑 更新 跑 無限輪迴
請求論壇大大協助
感謝 |
|