1 adet 4 lü röle (ışık, nem ve fan)
2 adet sg90 servo motor
1 adet button
1 adet 5510 lcd ekran
1 adet buzzer
#include
#include
#include
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
#define RELAY1 0
#define RELAY2 3
#define RELAY3 7
#define RELAY4 12
DHT dht(DHTPIN, DHTTYPE);
static PCD8544 lcd = PCD8544(8, 9, 10, 11, 4);
Servo myservo;
Servo myservo2;
int pos1 = 0;
int pos2 = 1;
int temp = 0;
int Button=13;
int speakerPin = 12;
float temp1 = 38.4;
float hum1 = 60.0;
float temp2 = 38.7;
float hum2 = 70.0;
float deftemp = temp1;
float defhum = hum1;
int r1,rx1 =0;
int r2,rx2 =0;
int r3,rx3 =0;
int tAlert= 0;
int hAlert = 0;
void setup()
{
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pinMode(RELAY3, OUTPUT);
//pinMode(RELAY4, OUTPUT);
myservo.attach(5);
myservo2.attach(6);
lcd.begin(84, 48);
dht.begin();
Serial.begin(9600);
lcd.setCursor(10,0);
lcd.print("Sicaklik: ");
lcd.setCursor(10,4);
lcd.print("Nem:");
pinMode(Button, INPUT);
pinMode (speakerPin, OUTPUT);
}
void loop()
{
Serial.println("Start loop");
Serial.print("D Temp: ");Serial.println(deftemp);
Serial.print("D Hum: ");Serial.println(defhum);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f)) {
alert(255, 1500, "Sensor", "Error");
return;
}
screen(h, t);
// button set
if(digitalRead(Button)==LOW)
{
if(deftemp == temp1) {
deftemp = temp2;
defhum = hum2;
} else if(deftemp == temp2) {
deftemp = temp1;
defhum = hum1;
}
Serial.print("New Temp: ");Serial.println(deftemp);
Serial.print("New Hum: ");Serial.println(defhum);
}
// relay control
if(h < defhum && t < deftemp) {
r1= 0;//fan
r2= 1;//lamba
r3= 1;//nem
tAlert++;
hAlert++;
Serial.println("Sicaklik Yetersiz Lamba Acik, Nem Yetersiz Nem Acik, Fan kapali");
}
else if(h < defhum && t > deftemp) {
r1= 1;
r2= 0;
r3= 1;
tAlert++;
Serial.println("Sicaklik Fazla Lamba Kapali, Nem Yetersiz Nem Acik, fan acik");
}
else if(h > defhum && t < deftemp) {
r1= 0;
r2= 1;
r3= 0;
hAlert++;
Serial.println("Sicaklik Az Lamba Acik, Nem Fazla Nem Kapali , Fan Kapali");
}
else{
r1= 1;
r2= 0;
r3= 0;
hAlert = 0;
tAlert = 0;
Serial.println("Sicaklik Yeterli Lamba Kapali, Nem Yeterli Nem Kapali,fan acik");
}
if(r1 != rx1 && r1 == 1 ) {
digitalWrite(RELAY1,HIGH);
Serial.println("Humidty Relay 1 open");
}else if(r1 != rx1 && r1 == 0 ) {
digitalWrite(RELAY1,LOW);
Serial.println("Humidty Relay 1 close");
}
rx1 =r1;
if(r2 != rx2 && r2 == 1 ) {
digitalWrite(RELAY2,HIGH);
Serial.println("Temperature Relay 2 open");
}else if(r2 != rx2 && r2 == 0 ) {
digitalWrite(RELAY2,LOW);
Serial.println("Temperature Relay 2 close");
}
rx2 =r2;
if(r3 != rx3 && r3 == 1 ) {
digitalWrite(RELAY3,HIGH);
Serial.println("Fan Relay 3 open");
}else if(r3 != rx3 && r3 == 0 ) {
digitalWrite(RELAY3,LOW);
Serial.println("Fan Relay 3 close");
}
rx3 =r3;
if(tAlert == 500) {
alert(255, 5000, "Temperature", "Error");
tAlert= 0;
}
if(hAlert == 500) {
alert(255, 10000, "Humidty", "Error");
hAlert= 0;
}
//servo
if(pos2 ==0 || pos2==180) {
temp= pos1;
pos1 = pos2;
pos2 = temp;
}
else if(pos2 > pos1) {
pos1 = pos2;
pos2++;
}
else {
pos1 = pos2;
pos2--;
}
myservo.write(pos1);
myservo2.write(pos1);
Serial.print("Servo position :");
Serial.println(pos1);
}
void alert(int v, int d, char mystr[], char mystr2[]) {
writeScreen(mystr, mystr2);
for(int i=0;i