Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
G
greenhouse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
João Lino
greenhouse
Commits
35574b82
Commit
35574b82
authored
Jun 09, 2018
by
João Lino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replaced DHT11 and adjusted parameters during tests.
parent
2c2e16d8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
128 additions
and
56 deletions
+128
-56
greenhouse.ino
greenhouse.ino
+128
-56
No files found.
greenhouse.ino
View file @
35574b82
...
...
@@ -3,7 +3,7 @@
dht
DHT
;
//
#define __debug
#define __debug
#define PROGRAM_VERSION "0.4.0"
...
...
@@ -17,23 +17,28 @@ dht DHT;
#define LED5Pin 8
#define LED6Pin 9
#define ButtonPin 13
#define TEMPERATURE_SAMPLES 10
int
leds
[
LEDCount
];
double
Setpoint
;
int
SetpointMode
;
boolean
relayState
;
double
temperaturaQueAchava
;
double
temperaturaMedia
[
TEMPERATURE_SAMPLES
];
int
temperaturaMediaIndex
;
boolean
tempSensorOK
;
//unsigned long elapsed;
void
setup
()
{
Serial
.
begin
(
115200
);
Serial
.
println
(
"
Kegerator
"
);
Serial
.
println
(
"
Greenhouse - for beer fermentation
"
);
Serial
.
print
(
"PROGRAM VERSION: "
);
Serial
.
println
(
PROGRAM_VERSION
);
Serial
.
print
(
"
\t
DHT LIBRARY VERSION: "
);
Serial
.
println
(
DHT_LIB_VERSION
);
Serial
.
println
();
Serial
.
println
(
"T
ype, status, Humidity (%), Temperature (C),
Relay State (ON
\\
OFF)"
);
Serial
.
println
(
"T
emp Sensor,
\t
Sensor Status,
\t
emperaturaAlvo (C),
\t
emperaturaQueDiz (C),
\t
tempetaturaQueEuAcho (C),
\t
Relay State (ON
\\
OFF)"
);
leds
[
0
]
=
LED1Pin
;
leds
[
1
]
=
LED2Pin
;
...
...
@@ -42,7 +47,7 @@ void setup()
leds
[
4
]
=
LED5Pin
;
leds
[
5
]
=
LED6Pin
;
Setpoint
=
18.0
;
SetpointMode
=
0
;
SetpointMode
=
18
;
temperaturaQueAchava
=
200.0
;
// Relay
...
...
@@ -66,10 +71,24 @@ void setup()
// Button
pinMode
(
ButtonPin
,
INPUT
);
for
(
temperaturaMediaIndex
=
0
;
temperaturaMediaIndex
<
TEMPERATURE_SAMPLES
;
temperaturaMediaIndex
++
)
{
temperaturaMedia
[
temperaturaMediaIndex
]
=
Setpoint
;
}
setLEDs
(
SetpointMode
);
tempSensorOK
=
false
;
//elapsed = millis();
}
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
()
)
{
// increase mode
...
...
@@ -100,66 +119,107 @@ void loop()
int
chk
=
DHT
.
read11
(
DHT11_PIN
);
// debug received data
debugDHT
(
chk
);
double
temperaturaQueDiz
=
DHT
.
temperature
;
double
tempetaturaQueEuAcho
;
if
(
temperaturaQueAchava
==
200.0
)
temperaturaQueAchava
=
temperaturaQueDiz
;
if
(
temperaturaQueAchava
>
temperaturaQueDiz
)
tempetaturaQueEuAcho
=
temperaturaQueAchava
-
0.25
;
else
if
(
temperaturaQueAchava
<
temperaturaQueDiz
)
tempetaturaQueEuAcho
=
temperaturaQueAchava
+
0.25
;
else
tempetaturaQueEuAcho
=
temperaturaQueAchava
;
//tempetaturaQueEuAcho = temperaturaQueDiz;
#ifdef __debug
Serial
.
print
(
"temperaturaAlvo = "
);
Serial
.
print
(
Setpoint
,
1
);
Serial
.
print
(
", temperaturaQueDiz = "
);
Serial
.
print
(
temperaturaQueDiz
,
1
);
Serial
.
print
(
", tempetaturaQueEuAcho = "
);
Serial
.
print
(
tempetaturaQueEuAcho
,
1
);
Serial
.
print
(
", "
);
#endif
tempSensorOK
=
debugDHT
(
chk
);
if
(
tempetaturaQueEuAcho
>
(
Setpoint
+
1.0
)
)
{
if
(
tempSensorOK
)
{
// turn on compressor to start cooling
relayState
=
true
;
digitalWrite
(
RelayPin
,
LOW
);
}
else
{
if
(
tempetaturaQueEuAcho
<=
(
Setpoint
-
1.0
)
)
{
double
temperaturaQueDiz
=
DHT
.
temperature
;
if
(
temperaturaQueAchava
==
200.0
)
{
temperaturaQueAchava
=
temperaturaQueDiz
;
}
// Calcular a temperatura de processamento
temperaturaMediaIndex
++
;
if
(
temperaturaMediaIndex
>=
TEMPERATURE_SAMPLES
)
{
temperaturaMediaIndex
=
0
;
}
// turn off compressor to stop cooling
relayState
=
false
;
digitalWrite
(
RelayPin
,
HIGH
);
/*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
;
}
}
}
#ifdef __debug
if
(
relayState
)
{
Serial
.
println
(
"ON"
);
}
else
{
Serial
.
println
(
"OFF"
);
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)
tempetaturaQueEuAcho = temperaturaQueAchava - 0.25;
else if (temperaturaQueAchava < temperaturaQueDiz)
tempetaturaQueEuAcho = temperaturaQueAchava + 0.25;
else
tempetaturaQueEuAcho = temperaturaQueAchava;
//tempetaturaQueEuAcho = temperaturaQueDiz;
*/
#ifdef __debug
Serial
.
print
(
""
);
Serial
.
print
(
Setpoint
,
2
);
Serial
.
print
(
", "
);
Serial
.
print
(
temperaturaQueDiz
,
2
);
Serial
.
print
(
", "
);
Serial
.
print
(
tempetaturaQueEuAcho
,
2
);
Serial
.
print
(
", "
);
#endif
if
(
tempetaturaQueEuAcho
>=
(
Setpoint
+
1.0
)
)
{
// turn on compressor to start cooling
relayState
=
true
;
digitalWrite
(
RelayPin
,
LOW
);
}
else
{
if
(
tempetaturaQueEuAcho
<=
(
Setpoint
-
0.0
)
)
{
// turn off compressor to stop cooling
relayState
=
false
;
digitalWrite
(
RelayPin
,
HIGH
);
}
}
#ifdef __debug
if
(
relayState
)
{
Serial
.
println
(
"ON"
);
}
else
{
Serial
.
println
(
"OFF"
);
}
#endif
temperaturaQueAchava
=
tempetaturaQueEuAcho
;
delay
(
50
);
//delay(100);
}
#endif
temperaturaQueAchava
=
tempetaturaQueEuAcho
;
delay
(
50
);
}
void
setLEDs
(
int
number
)
{
int
calcNumber
=
number
;
for
(
int
i
=
(
LEDCount
-
1
);
i
>=
0
;
i
++
)
{
boolean
zero
=
calcNumber
%
2
==
0
?
true
:
false
;
for
(
int
i
=
(
LEDCount
-
1
);
i
>=
0
;
i
--
)
{
boolean
zero
=
((
calcNumber
%
2
)
==
0
)
?
true
:
false
;
calcNumber
/=
2
;
if
(
zero
)
{
...
...
@@ -188,15 +248,18 @@ boolean hasBtnPressed() {
}
}
void
debugDHT
(
int
chk
)
{
boolean
debugDHT
(
int
chk
)
{
boolean
ret
=
false
;
#ifdef __debug
Serial
.
print
(
"DHT11, "
);
//
Serial.print("DHT11, ");
#endif
switch
(
chk
)
{
case
DHTLIB_OK
:
ret
=
true
;
#ifdef __debug
Serial
.
print
(
"DHT11, "
);
Serial
.
print
(
"OK, "
);
#endif
break
;
...
...
@@ -207,7 +270,14 @@ void debugDHT( int chk ) {
Serial
.
print
(
"Time out error, "
);
break
;
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
;
case
DHTLIB_ERROR_ACK_L
:
Serial
.
print
(
"Ack Low error, "
);
...
...
@@ -224,5 +294,7 @@ void debugDHT( int chk ) {
//Serial.print(DHT.humidity, 1);
//Serial.print(", ");
#endif
return
ret
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment