第1步:不帶繼電器和顯示的原理圖
這是不帶繼電器和顯示原理圖
步驟2:顯示20x4 I2c
我的顯示等于此
http://www.sainsmart。 com/sainsmart-iic-i2c-twi-serial-2004-20x4-lcd-module-shield-for-arduino-uno-mega-r3.html
SDA-》 Arduino A4
SDL-》 Arduino A5
GND-》 GND
VCC-》 5V
步驟3:繼電器
已連接2個繼電器模塊
1x雙通道模塊與此相等,用于加熱器《1》 HonKong的1x單通道模塊用于大坦克中的風(fēng)扇
Rel1-》 Arduino D2
Rel2-》 Arduino D3
Rel3-》 Arduino D8
GND-》 Arduino GND
VCC-》 Arduino 5V
第4步:代碼
#include
#include
#include
#include
//RGBLED
int bluePin1 = 10;//RGB-LED
int greenPinfürBlaue LED1 int greenPin1 = 11;//RGB-LED
int redPin1 = 12中的數(shù)字PinfürGrüneLED1;//RGB-LED中的數(shù)字針腳旋轉(zhuǎn)LED1
int redIn1 = 0;
int greenIn1 = 1;
int blueIn1 = 2;
int redVal1;
int greenVal1;
int blueVal1;
int bluePin2 = 4;//RGB-LED
int greenPin2 = 5;//RGB-LED
int redPin2 = 6中的數(shù)字PinfürGrüneLED2;//RGB-LED中的數(shù)字引腳可旋轉(zhuǎn)LED2
int redIn2 = 3;
int greenIn2 = 4;
int blueIn2 = 5;
int redVal2;
int greenVal2;
int blueVal2;
//繼電器
int relPin1 = 2;//數(shù)字引腳繼電器1
int relPin2 = 3;//數(shù)字引腳繼電器2
int relPin3 = 8;//數(shù)字引腳繼電器3
int relPin1In = 3;
int relPin2In = 4;
int relPin3In = 5;
int relPin1Val;
int relPin2Val;
int relPin3Val;
//Heizungs狀態(tài)
int heiz1Val;
int heiz2Val;
#define BACKLIGHT_PIN 13
#define ONE_WIRE_BUS 7
LiquidCrystal_I2C lcd(0x20,20,4);//將LCD地址設(shè)置為0x20以顯示20個字符和4行
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature傳感器(&oneWire);
void setup(){
Serial.begin(9600) );
sensors.begin();
lcd.init();//初始化LCD
lcd.backlight();
pinMode(relPin1,OUTPUT);//繼電器1的輸出模式
pinMode(relPin2,OUTPUT);//繼電器2的輸出模式
pinMode(relPin3,OUTPUT);//繼電器3的輸出模式
}
void loop(){浮點(diǎn)溫度1 = sensor.getTempCByIndex(0);
lcd.setCursor(0,0 );
lcd.print(“ Aquarium:”);
lcd.print(sensors.getTempCByIndex(0));
lcd.print(“ C”);
浮點(diǎn)溫度2 = sensor.getTempCByIndex(1);
lcd.setCursor(0,2);
lcd.print(“ Becken:”);
lcd.print(sensors.getTempCByIndex(1));
lcd.print(“ C”);
//Je nach Temperatur Farbe der RGB-LED anpassen und Rel 1 schalten
if(temperature1 《= 27)
{
redVal1 = 0;
greenVal1 = 0;
blueVal1 = 150;
relPin1Val = LOW;
relPin3Val = LOW;
lcd.setCursor(0,1);
lcd.print(“ Heistung ist:Ein“);
}
否則if(temperature1》 27 && temperature1 《29)
{
redVal1 = 0;
greenVal1 = 150;
blueVal1 = 0;
relPin1Val =高;
relPin3Val =低;
lcd.setCursor(0,1);
lcd.print(“ Heizung ist:Aus”);
}
如果(溫度1》 29)
{
redVal1 = 150;
greenVal1 = 0;
blueVal1 = 0;
relPin1Val = HIGH;
relPin3Val = HIGH;
lcd.setCursor(0,1);
lcd.print(“ Lueftung ist:Ein”);
}
//Je nach溫度從RGB-LED通道和Rel 2通道
if(temperature2 《= 27)
{
redVal2 = 0;
greenVal2 = 0;
blueVal2 = 255;
relPin2Val = LOW;
lcd.setCursor(0,3);
lcd.print(“ Heizung ist:Ein”);
}
否則if(temperature2》 27 && temperature2 《29)
{
redVal2 = 0;
greenVal2 = 255;
blueVal2 = 0;
relPin2Val = HIGH;
lcd.setCursor(0,3);
lcd.print(“ Heizung ist:Aus”);
}
否則if(temperature2》 29)
{
redVal2 = 255;
greenVal2 = 0;
blueVal2 = 0;
relPin2Val = HIGH;
lcd.setCursor(0,3);
lcd.print(“ Lueftung ist:Ein”);
}
{
AnalogWrite (redPin1,redVal1);
模擬寫(greenPin1,greenVal1);
模擬寫(bluePin1,blueVal1);
模擬寫(redPin2,redVal2);
模擬寫(greenPin2,greenVal2);
模擬寫(bluePin2,blueVal2);
d igitalWrite(relPin1,relPin1Val);
digitalWrite(relPin2,relPin2Val);
digitalWrite(relPin3,relPin3Val);
}
}
-
恒溫器
+關(guān)注
關(guān)注
4文章
141瀏覽量
20703
發(fā)布評論請先 登錄
相關(guān)推薦
評論