电子说
第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单通道模块用于大坦克中的风扇
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中的数字PinfürGrüneLED1;//RGB-LED中的数字针脚旋转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中的数字PinfürGrüneLED2;//RGB-LED中的数字引脚可旋转LED2
int redIn2 = 3;
int greenIn2 = 4;
int blueIn2 = 5;
int redVal2;
int greenVal2;
int blueVal2;
//继电器
int relPin1 = 2;//数字引脚继电器1
int relPin2 = 3;//数字引脚继电器2
int relPin3 = 8;//数字引脚继电器3
int relPin1In = 3;
int relPin2In = 4;
int relPin3In = 5;
int relPin1Val;
int relPin2Val;
int relPin3Val;
//Heizungs状态
int heiz1Val;
int heiz2Val;
#define BACKLIGHT_PIN 13
#define ONE_WIRE_BUS 7
LiquidCrystal_I2C lcd(0x20,20,4);//将LCD地址设置为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(){浮点温度1 = sensor.getTempCByIndex(0);
lcd.setCursor(0,0 );
lcd.print(“ Aquarium:”);
lcd.print(sensors.getTempCByIndex(0));
lcd.print(“ C”);
浮点温度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);
}
}
全部0条评论
快来发表一下你的评论吧 !