Commit 35574b82 authored by João Lino's avatar João Lino

Replaced DHT11 and adjusted parameters during tests.

parent 2c2e16d8
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
dht DHT; dht DHT;
//#define __debug #define __debug
#define PROGRAM_VERSION "0.4.0" #define PROGRAM_VERSION "0.4.0"
...@@ -17,23 +17,28 @@ dht DHT; ...@@ -17,23 +17,28 @@ dht DHT;
#define LED5Pin 8 #define LED5Pin 8
#define LED6Pin 9 #define LED6Pin 9
#define ButtonPin 13 #define ButtonPin 13
#define TEMPERATURE_SAMPLES 10
int leds[LEDCount]; int leds[LEDCount];
double Setpoint; double Setpoint;
int SetpointMode; int SetpointMode;
boolean relayState; boolean relayState;
double temperaturaQueAchava; double temperaturaQueAchava;
double temperaturaMedia[TEMPERATURE_SAMPLES];
int temperaturaMediaIndex;
boolean tempSensorOK;
//unsigned long elapsed;
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
Serial.println("Kegerator"); Serial.println("Greenhouse - for beer fermentation");
Serial.print("PROGRAM VERSION: "); Serial.print("PROGRAM VERSION: ");
Serial.println(PROGRAM_VERSION); Serial.println(PROGRAM_VERSION);
Serial.print("\tDHT LIBRARY VERSION: "); Serial.print("\tDHT LIBRARY VERSION: ");
Serial.println(DHT_LIB_VERSION); Serial.println(DHT_LIB_VERSION);
Serial.println(); Serial.println();
Serial.println("Type, status, Humidity (%), Temperature (C), Relay State (ON\\OFF)"); Serial.println("Temp Sensor,\tSensor Status,\temperaturaAlvo (C),\temperaturaQueDiz (C),\ttempetaturaQueEuAcho (C),\tRelay State (ON\\OFF)");
leds[0] = LED1Pin; leds[0] = LED1Pin;
leds[1] = LED2Pin; leds[1] = LED2Pin;
...@@ -42,7 +47,7 @@ void setup() ...@@ -42,7 +47,7 @@ void setup()
leds[4] = LED5Pin; leds[4] = LED5Pin;
leds[5] = LED6Pin; leds[5] = LED6Pin;
Setpoint = 18.0; Setpoint = 18.0;
SetpointMode = 0; SetpointMode = 18;
temperaturaQueAchava = 200.0; temperaturaQueAchava = 200.0;
// Relay // Relay
...@@ -66,10 +71,24 @@ void setup() ...@@ -66,10 +71,24 @@ void setup()
// Button // Button
pinMode(ButtonPin, INPUT); pinMode(ButtonPin, INPUT);
for( temperaturaMediaIndex = 0; temperaturaMediaIndex < TEMPERATURE_SAMPLES; temperaturaMediaIndex++ ) {
temperaturaMedia[temperaturaMediaIndex] = Setpoint;
}
setLEDs(SetpointMode);
tempSensorOK = false;
//elapsed = millis();
} }
void loop() void loop()
{ {
/*if ( millis() - 4000 > elapsed ) {
Serial.println("Temp Sensor,\tSensor Status,\temperaturaAlvo (C),\temperaturaQueDiz (C),\ttempetaturaQueEuAcho (C),\tRelay State (ON\\OFF)");
elapsed = millis();
}*/
if ( hasBtnPressed() ) { if ( hasBtnPressed() ) {
// increase mode // increase mode
...@@ -100,13 +119,52 @@ void loop() ...@@ -100,13 +119,52 @@ void loop()
int chk = DHT.read11(DHT11_PIN); int chk = DHT.read11(DHT11_PIN);
// debug received data // debug received data
debugDHT(chk); tempSensorOK = debugDHT(chk);
if(tempSensorOK) {
double temperaturaQueDiz = DHT.temperature; double temperaturaQueDiz = DHT.temperature;
double tempetaturaQueEuAcho;
if (temperaturaQueAchava == 200.0) if (temperaturaQueAchava == 200.0) {
temperaturaQueAchava = temperaturaQueDiz; temperaturaQueAchava = temperaturaQueDiz;
}
// Calcular a temperatura de processamento
temperaturaMediaIndex++;
if ( temperaturaMediaIndex >= TEMPERATURE_SAMPLES ) {
temperaturaMediaIndex = 0;
}
/*Serial.print("t[");
Serial.print(temperaturaMediaIndex);
Serial.print("]=");
Serial.print(temperaturaQueAchava);*/
if (temperaturaQueDiz > (temperaturaQueAchava + 0)) {
//Serial.print("+0.1, ");
temperaturaMedia[temperaturaMediaIndex] = (temperaturaQueAchava + 0.2);
}
else {
if (temperaturaQueDiz < (temperaturaQueAchava - 0.1)) {
//Serial.print("-0.1, ");
temperaturaMedia[temperaturaMediaIndex] = (temperaturaQueAchava - 1.0);
}
else {
//Serial.print(", ");
temperaturaMedia[temperaturaMediaIndex] = temperaturaQueDiz;
}
}
double tempetaturaQueEuAcho = 0.0;
for ( int i = 0; i < TEMPERATURE_SAMPLES; i++ ) {
/*Serial.print(temperaturaMedia[i]);
Serial.print(" ");*/
tempetaturaQueEuAcho += temperaturaMedia[i];
}
tempetaturaQueEuAcho /= TEMPERATURE_SAMPLES;
//Serial.print(", ");
/*
if (temperaturaQueAchava > temperaturaQueDiz) if (temperaturaQueAchava > temperaturaQueDiz)
tempetaturaQueEuAcho = temperaturaQueAchava - 0.25; tempetaturaQueEuAcho = temperaturaQueAchava - 0.25;
...@@ -116,25 +174,25 @@ void loop() ...@@ -116,25 +174,25 @@ void loop()
tempetaturaQueEuAcho = temperaturaQueAchava; tempetaturaQueEuAcho = temperaturaQueAchava;
//tempetaturaQueEuAcho = temperaturaQueDiz; //tempetaturaQueEuAcho = temperaturaQueDiz;
*/
#ifdef __debug #ifdef __debug
Serial.print("temperaturaAlvo = "); Serial.print("");
Serial.print(Setpoint, 1); Serial.print(Setpoint, 2);
Serial.print(", temperaturaQueDiz = ");
Serial.print(temperaturaQueDiz, 1);
Serial.print(", tempetaturaQueEuAcho = ");
Serial.print(tempetaturaQueEuAcho, 1);
Serial.print(", "); Serial.print(", ");
#endif Serial.print(temperaturaQueDiz, 2);
Serial.print(", ");
Serial.print(tempetaturaQueEuAcho, 2);
Serial.print(", ");
#endif
if ( tempetaturaQueEuAcho > (Setpoint + 1.0) ) { if ( tempetaturaQueEuAcho >= (Setpoint + 1.0) ) {
// turn on compressor to start cooling // turn on compressor to start cooling
relayState = true; relayState = true;
digitalWrite( RelayPin, LOW ); digitalWrite( RelayPin, LOW );
} }
else { else {
if ( tempetaturaQueEuAcho <= (Setpoint - 1.0) ) { if ( tempetaturaQueEuAcho <= (Setpoint - 0.0) ) {
// turn off compressor to stop cooling // turn off compressor to stop cooling
relayState = false; relayState = false;
...@@ -142,24 +200,26 @@ void loop() ...@@ -142,24 +200,26 @@ void loop()
} }
} }
#ifdef __debug #ifdef __debug
if (relayState) { if (relayState) {
Serial.println( "ON" ); Serial.println( "ON" );
} }
else { else {
Serial.println( "OFF" ); Serial.println( "OFF" );
} }
#endif #endif
temperaturaQueAchava = tempetaturaQueEuAcho; temperaturaQueAchava = tempetaturaQueEuAcho;
delay(50); delay(50);
//delay(100);
}
} }
void setLEDs( int number ) { void setLEDs( int number ) {
int calcNumber = number; int calcNumber = number;
for ( int i = (LEDCount - 1); i >= 0; i++ ) { for ( int i = (LEDCount - 1); i >= 0; i-- ) {
boolean zero = calcNumber % 2 == 0 ? true : false; boolean zero = ((calcNumber % 2) == 0) ? true : false;
calcNumber /= 2; calcNumber /= 2;
if (zero) { if (zero) {
...@@ -188,15 +248,18 @@ boolean hasBtnPressed() { ...@@ -188,15 +248,18 @@ boolean hasBtnPressed() {
} }
} }
void debugDHT( int chk ) { boolean debugDHT( int chk ) {
boolean ret = false;
#ifdef __debug #ifdef __debug
Serial.print("DHT11, "); //Serial.print("DHT11, ");
#endif #endif
switch (chk) switch (chk)
{ {
case DHTLIB_OK: case DHTLIB_OK:
ret = true;
#ifdef __debug #ifdef __debug
Serial.print("DHT11, ");
Serial.print("OK, "); Serial.print("OK, ");
#endif #endif
break; break;
...@@ -207,7 +270,14 @@ void debugDHT( int chk ) { ...@@ -207,7 +270,14 @@ void debugDHT( int chk ) {
Serial.print("Time out error, "); Serial.print("Time out error, ");
break; break;
case DHTLIB_ERROR_CONNECT: case DHTLIB_ERROR_CONNECT:
Serial.print("Connect error, "); //Serial.print("Connect error, ");
/*
relayState = false;
digitalWrite( RelayPin, HIGH );
setLEDs(63);
while(true) Serial.println("ERROR, SAFEMODE ON!!!!");
*/
break; break;
case DHTLIB_ERROR_ACK_L: case DHTLIB_ERROR_ACK_L:
Serial.print("Ack Low error, "); Serial.print("Ack Low error, ");
...@@ -224,5 +294,7 @@ void debugDHT( int chk ) { ...@@ -224,5 +294,7 @@ void debugDHT( int chk ) {
//Serial.print(DHT.humidity, 1); //Serial.print(DHT.humidity, 1);
//Serial.print(", "); //Serial.print(", ");
#endif #endif
return ret;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment