Sie sind auf Seite 1von 4

#include "SimpleDHT.

h" // include dht library


#include "OneWire.h" // include water temperature sensor library
#include "DallasTemperature.h" // include water temperature library
#include "LiquidCrystal.h" // include lcd library
#include "SPI.h" // include sd card library
#include "SD.h" // include sd card library

LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // define the lcd pins

OneWire oneWire(8); // define water temperature sensor (1)


OneWire twoWire(9); // define water temperature sensor (2)

DallasTemperature sensor1(&oneWire);
DallasTemperature sensor2(&twoWire);

SimpleDHT11 dht11(1); // define dht11 pin

byte temperature = 0; // store the temperature value


byte humidity = 0; // store the humidity value
int err = SimpleDHTErrSuccess; // an error message if there is no sensor

const int chipSelect = 10; // define the chip Select of sd card

float Celsius1 = 0, // store water temperature value for sensor1


Celsius2 = 0; // store water temperature value for sensor2

unsigned long t = 0, // time for toglle the relay


t2 = 0; // time for datalogger

const int time_on = 5, // the minutes that the relay will be on


time_off = 10; // the minutes that the relay will be off

int ref = 1; // to toglle the time between time_on and time_off

#define rel0 A0 // relay for the pumb


#define rel1 A1 // relay for heater
#define rel2 A2 // relay for the chiller
#define rel3 A3 // relay for the fan (dht)
#define rel4 A4 // relay for the heater (dht)
#define rel5 A5 // relay for the humidity (dht)

void setup() {
sensor1.begin();
sensor2.begin();
pinMode(rel0,OUTPUT);
pinMode(rel1,OUTPUT);
pinMode(rel2,OUTPUT);
pinMode(rel3,OUTPUT);
pinMode(rel4,OUTPUT);
pinMode(rel5,OUTPUT);
lcd.begin(16,2);
SD.begin(chipSelect);
sensors_names(); // put the names of sensors on sd card
}

void loop() {
unsigned long td = millis(); // store the time to save data
sensor1.requestTemperatures(); // read sensor value
Celsius1 = sensor1.getTempCByIndex(0); // store sensor value
sensor2.requestTemperatures(); // read sensor2 value
Celsius2 = sensor2.getTempCByIndex(0); // store sensor2 value

if(td - t2 >= 30000){ // for each 30 second store the sensors value on sd card
t2 = td;
sensors_datalogger(); // store sensors value on sd card
}
lcd_show(); // show sensors value in lcd
timer(); // switch on the realay for 5 minutes and off for 10 minutes
heater(); // compare the sensor value to turn on the relay for heater
chiller(); // compare the sensor2 value to turn on the relay for chiller
dht(); // read the temperature and humidity from dht11 sensor
dht_fan(); // compare the tempperature value to turn on the relay fan
dht_heater(); // compare the tempperature value to turn on the relay for heater
dht_humidity(); // compare the humidity value to turn on the relay
}

void sensors_names() {
File data = SD.open("Data.txt", FILE_WRITE);
if (data)
{
data.print("W1");
data.print(" ");
data.print("W2");
data.print(" ");
data.print("Air");
data.print(" ");
data.println("Humidity");
data.close();
}
}

void sensors_datalogger() {
File data = SD.open("data.txt", FILE_WRITE);
if (data)
{
data.print(Celsius1);
data.print(" ");
data.print(Celsius2);
data.print(" ");
data.print(temperature);
data.print(" ");
data.println(humidity);
data.close();
}
}

void lcd_show() {
lcd.setCursor(0, 0);
lcd.print("w1:");
lcd.setCursor(3, 0);
lcd.print(Celsius1);

lcd.setCursor(0, 1);
lcd.print("w2:");
lcd.setCursor(3, 1);
lcd.print(Celsius2);
lcd.setCursor(10,0);
lcd.print("A:");
lcd.setCursor(12,0);
lcd.print((int)temperature);

lcd.setCursor(10,1);
lcd.print("H:");
lcd.setCursor(12,1);
lcd.print((int)humidity);
}

void timer(){
unsigned long ts = millis(); // store the time for the relay
if(ref == 1){
if(ts - t >= (time_on * 60000)){ // compare between the time to toglle
digitalWrite(rel0,HIGH);
ref = 0;
}
}else{
if(ts - t >= ((time_off + time_on) * 60000)){ // compare between the time to toglle
t = ts;
ref = 1;
digitalWrite(rel0,LOW);
}
}
}

void heater() {
if(Celsius1 <= 20){
digitalWrite(rel1,HIGH);
}else if (Celsius1 >= 23){
digitalWrite(rel1,LOW);
}
}

void chiller() {
if(Celsius1 >= 25){
digitalWrite(rel2,HIGH);
}else if(Celsius1 <= 23){
digitalWrite(rel2,LOW);
}
}

void dht(){
if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
return;
}

Serial.print((int)temperature); Serial.print(" *C, ");


Serial.print((int)humidity); Serial.println(" H");
}

void dht_fan() {
if(temperature >= 26){
digitalWrite(rel3,HIGH);
}else if(temperature <= 24){
digitalWrite(rel3,LOW);
}
}
void dht_heater() {
if(temperature < 20){
digitalWrite(rel4,HIGH);
}else{
digitalWrite(rel4,LOW);
}
}

void dht_humidity() {
if(humidity <= 50){
digitalWrite(rel5,HIGH);
}else if(humidity >= 70){
digitalWrite(rel5,LOW);
}
}

??? ??? ??? ??????? ??? ???? ???? ?? ??? ??????? ???????
??? ?????? ??????
???? ????? ???? ????? ?????? ???????? ??????? ? ???? ????? ?????? ???????? ????????
? ????? ????? ???? ??????? ???? ???? ?????? ??? ??? ???? lcd ?????? ????? ??? sd
card
????? ????? ???? ???? ???? 5 ????? ?????? ???? 10 ?????
?????? ???? ???? ????? ?????? ???????? ?? ?????? ??? ???
20 ???? ?? ??? ????? ???? ???? ??? ??? ?????
23 ?? ????? ?????? ?????? ????? ???? ????? ?????? ???
25 ???? ?? ???? ????? ???? ???? ??? ??? ??? 23 ???? ?? ????? ??????
?????? ???? ???? ????? ?????? ??? 26 ???? ?? ???? ????? ?????? ??? ??? ?????? ???
24 ???? ???? ?????? ???? ????? ?????? ??? ??
20 ???? ????? ???? ???? ??? ??? ???? ??????? ??? 20 ????
?????? ??? ???? ???????? ??? 50 ?? ??? ???? ???? ??? ??? ??? 70.

Das könnte Ihnen auch gefallen