步驟1:接線
連接所有部件,如示意圖所示(Fritizng文件和部件可從下面下載)
在Arduino頂部滑動時,我沒有顯示LCD接線。
請記住在5V和SIG節點之間放置4.7 kohm電阻。 od DHT22。您可以購買帶有內置電阻器的DHT傳感器,如果不需要的話。
要連接任何東西到繼電器-繼電器中的電源分別接到COM1和COM2,應打開設備并斷開電源。關閉到NO1和NO2(否–常開)。
我正在使用Screw Shield-所以我不必焊接任何東西
步驟2:代碼-在網站上看起來很糟,但抓取了附件文件
/*Sky Control - Temperature and humidity sensor with relays made by ArkadiuszO2 v1
* Please read comments
* Shopping list includes:
* 1. Arduino Uno
* 2. DHT22 sensor
* 3. 2 channel relay - 5V
* 4. DFRobot LCD Keypad Shield
*
* In V2 i will add Air quality sensor based on Sharp‘s GP2Y1010AU0F
*/ #include
#include
#include //Starting values after boot up, you can change them
int temp = 25;
int hum = 50; //For DHT22 (AM2023)
#define DHTPIN 15
#define DHTTYPE DHT22
const int relay1 = 18;
const int relay2 = 19;
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
DFR_Key keypad;
int localKey = 0;
String keyString = “”;
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
int read_LCD_buttons(){
adc_key_in = analogRead(0);
if (adc_key_in 》 1000) return btnNONE;
if (adc_key_in 《 50) return btnRIGHT;
if (adc_key_in 《 250) return btnUP;
if (adc_key_in 《 450) return btnDOWN;
if (adc_key_in 《 650) return btnLEFT;
if (adc_key_in 《 850) return btnSELECT;
}
void setup()
{
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Sky control v1”);
lcd.setCursor(0, 1);
lcd.print(“Instr on Select”);
delay(2500);
Serial.begin(9600);
dht.begin();
delay(1000);
lcd.clear();
//Sample rate (default 10 ms)
keypad.setRate(10);
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(t) || isnan(h)) { //checking sensor operation
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Sensor broken??!”);
delay(10000);
} else {
//You can change values (step) after each button press, default is 1’C for step and 5% humidity
lcd_key = read_LCD_buttons();
switch (lcd_key){
case btnLEFT:{
temp = temp +1;
break;
}
case btnRIGHT:{
temp = temp - 1;
break;
}
case btnUP:{
hum = hum + 5;
break;
}
case btnDOWN:{
hum = hum - 5;
break;
}
case btnSELECT:{
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Hum Up/Down +-5%”);
lcd.setCursor(0, 1);
lcd.print(“Temp L/R +-1”);
lcd.print((char)223);
lcd.print(“C”);
delay (5000);
break;
}
}
lcd.setCursor(0, 0);
lcd.print(“Hum: ”);
lcd.print(h);
lcd.print(“%”);
lcd.print(“(”);
lcd.print(hum);
lcd.print(“%)”);
lcd.setCursor(0, 1);
lcd.print(“Tem: ”);
lcd.print(t);
lcd.print((char)223);
lcd.print(“(”);
lcd.print(temp);
lcd.print((char)223);
lcd.print(“)”);
//adding this so the humidifier will not be powering on and off constantly (humidifier will exceed upper limit by 10% - IF YOU NEED EXACT VALUES COMMENT THIS SECTION AND UNCOMMENT NEXT ??!
int H = hum + 10;
if(h 《 hum ) digitalWrite(relay1, LOW);
else if (h 》= H) digitalWrite(relay1, HIGH);
/* 《- UNCOMMENT THIS IF YOU NEED EXACT VALUES BUT COMMENT 5 LINES ABOVE
if(h 《 hum ) digitalWrite(relay1, LOW);
else digitalWrite(relay1, HIGH);
*/
if(t 《 temp ) digitalWrite(relay2, LOW);
else digitalWrite(relay2, HIGH);
}
}
第3步:操作
按“選擇”后,您將看到基本的操作說明
“向上/向下”將預設濕度增加+ -5%
左/右將預設溫度改變+ -1°C
在代碼中,您會發現加濕器將超出預設限制10%-這樣就可以了不會一直在打開和關閉電源,即。您已將目標濕度設置為50%-繼電器將在讀數達到49%時打開加濕器的電源,并在讀數達到60%時關閉加濕器的電源。您可以通過修改代碼來更改它。
責任編輯:wv
-
溫濕度控制器
+關注
關注
1文章
35瀏覽量
9787
發布評論請先 登錄
相關推薦
評論