电子说
步骤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
全部0条评论
快来发表一下你的评论吧 !