Arduino 溫感澆花器 實作
材料:DHT11溫溼度感測器、繼電器、抽水馬達。
網站支援:
- 〈WEBDUINO----教學範例 14:繼電器控制風扇旋轉〉https://webduino.io/tutorials/tutorial-14-relay.html
- 〈繼電器規格書〉http://www.pu-yang.com.tw/media/products/0058795001416992470.pdf
- 〈Ming's Blogger----Arduino範例19:利用DHT11抓取溫度和濕度〉http://ming-shian.blogspot.tw/2014/05/arduino19dht11.htm
圖片:
程式:
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
int sw = 7 ;
void setup() {
Serial.begin(9600);
Serial.println("Strawberry Pot START");
pinMode(sw, OUTPUT);
dht.begin();
}
void loop() {
delay(1000);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.println(" *F\t");
if(t>=30)
{
digitalWrite(sw, HIGH);
delay(10000);
digitalWrite(sw, LOW);
}
if(t>=28)
{
digitalWrite(sw, HIGH);
delay(5000);
digitalWrite(sw, LOW);
}
else
{
digitalWrite(sw, LOW);
}
delay(10000);
}
留言列表