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
75fe2262
Commit
75fe2262
authored
Oct 14, 2018
by
João Lino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added a termocouple driver to measur fermentation temperature.
parent
35574b82
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
209 additions
and
80 deletions
+209
-80
greenhouse.ino
greenhouse.ino
+209
-80
No files found.
greenhouse.ino
View file @
75fe2262
#include <MAX6675.h>
#include <dht.h>
#include <dht.h>
dht
DHT
;
dht
DHT
;
#define __debug
//#define __debug
#define __info
#define PROGRAM_VERSION "0.4.0"
#define PROGRAM_VERSION "0.4.0"
...
@@ -18,6 +19,22 @@ dht DHT;
...
@@ -18,6 +19,22 @@ dht DHT;
#define LED6Pin 9
#define LED6Pin 9
#define ButtonPin 13
#define ButtonPin 13
#define TEMPERATURE_SAMPLES 10
#define TEMPERATURE_SAMPLES 10
#define TEMPERATURE_SAMPLES_TC 30
#define MINIMUM_TIME_OFF 480000 // 8 min
#define TC_TEMP_OFFSET 0.0
// ##############
int
thermoDO
=
A2
;
int
thermoCS
=
A1
;
int
thermoCLK
=
A0
;
int
thermoUnits
=
1
;
MAX6675
thermocouple
(
thermoCS
,
thermoDO
,
thermoCLK
,
thermoUnits
);
//MAX6675 thermocouple(thermoCS,thermoDO,thermoCLK,units);
double
temperaturaQueAchavaTC
;
double
temperaturaMediaTC
[
TEMPERATURE_SAMPLES_TC
];
int
temperaturaMediaIndexTC
;
// ##############
int
leds
[
LEDCount
];
int
leds
[
LEDCount
];
double
Setpoint
;
double
Setpoint
;
...
@@ -29,6 +46,11 @@ int temperaturaMediaIndex;
...
@@ -29,6 +46,11 @@ int temperaturaMediaIndex;
boolean
tempSensorOK
;
boolean
tempSensorOK
;
//unsigned long elapsed;
//unsigned long elapsed;
unsigned
long
currentTime
;
unsigned
long
tcReadTime
;
unsigned
long
dhtReadTime
;
unsigned
long
lastTurnOff
;
void
setup
()
void
setup
()
{
{
Serial
.
begin
(
115200
);
Serial
.
begin
(
115200
);
...
@@ -40,16 +62,26 @@ void setup()
...
@@ -40,16 +62,26 @@ void setup()
Serial
.
println
();
Serial
.
println
();
Serial
.
println
(
"Temp Sensor,
\t
Sensor Status,
\t
emperaturaAlvo (C),
\t
emperaturaQueDiz (C),
\t
tempetaturaQueEuAcho (C),
\t
Relay State (ON
\\
OFF)"
);
Serial
.
println
(
"Temp Sensor,
\t
Sensor Status,
\t
emperaturaAlvo (C),
\t
emperaturaQueDiz (C),
\t
tempetaturaQueEuAcho (C),
\t
Relay State (ON
\\
OFF)"
);
// ##############
temperaturaQueAchavaTC
=
200.0
;
// ##############
leds
[
0
]
=
LED1Pin
;
leds
[
0
]
=
LED1Pin
;
leds
[
1
]
=
LED2Pin
;
leds
[
1
]
=
LED2Pin
;
leds
[
2
]
=
LED3Pin
;
leds
[
2
]
=
LED3Pin
;
leds
[
3
]
=
LED4Pin
;
leds
[
3
]
=
LED4Pin
;
leds
[
4
]
=
LED5Pin
;
leds
[
4
]
=
LED5Pin
;
leds
[
5
]
=
LED6Pin
;
leds
[
5
]
=
LED6Pin
;
Setpoint
=
18
.0
;
Setpoint
=
0
.0
;
SetpointMode
=
18
;
SetpointMode
=
0
;
temperaturaQueAchava
=
200.0
;
temperaturaQueAchava
=
200.0
;
// Read Timmers
currentTime
=
millis
();
tcReadTime
=
millis
();
dhtReadTime
=
millis
();
lastTurnOff
=
0
;
// Relay
// Relay
relayState
=
false
;
relayState
=
false
;
pinMode
(
RelayPin
,
OUTPUT
);
pinMode
(
RelayPin
,
OUTPUT
);
...
@@ -75,6 +107,9 @@ void setup()
...
@@ -75,6 +107,9 @@ void setup()
for
(
temperaturaMediaIndex
=
0
;
temperaturaMediaIndex
<
TEMPERATURE_SAMPLES
;
temperaturaMediaIndex
++
)
{
for
(
temperaturaMediaIndex
=
0
;
temperaturaMediaIndex
<
TEMPERATURE_SAMPLES
;
temperaturaMediaIndex
++
)
{
temperaturaMedia
[
temperaturaMediaIndex
]
=
Setpoint
;
temperaturaMedia
[
temperaturaMediaIndex
]
=
Setpoint
;
}
}
for
(
temperaturaMediaIndexTC
=
0
;
temperaturaMediaIndexTC
<
TEMPERATURE_SAMPLES_TC
;
temperaturaMediaIndexTC
++
)
{
temperaturaMediaTC
[
temperaturaMediaIndexTC
]
=
Setpoint
;
}
setLEDs
(
SetpointMode
);
setLEDs
(
SetpointMode
);
...
@@ -84,49 +119,96 @@ void setup()
...
@@ -84,49 +119,96 @@ void setup()
void
loop
()
void
loop
()
{
{
/*if ( millis() - 4000 > elapsed ) {
processBtnPress
();
Serial.println("Temp Sensor,\tSensor Status,\temperaturaAlvo (C),\temperaturaQueDiz (C),\ttempetaturaQueEuAcho (C),\tRelay State (ON\\OFF)");
elapsed = millis();
}*/
if
(
hasBtnPressed
()
)
{
// increase mode
SetpointMode
++
;
// reset mode back to 0
double
temperaturaQueDizTC
=
0
;
if
(
SetpointMode
>
63
)
{
currentTime
=
millis
();
SetpointMode
=
0
;
if
(
currentTime
>
(
tcReadTime
+
50
))
{
tcReadTime
=
millis
();
temperaturaQueDizTC
=
thermocouple
.
read_temp
()
+
TC_TEMP_OFFSET
;
}
}
// change leds
if
(
temperaturaQueDizTC
!=
0
)
{
setLEDs
(
SetpointMode
);
if
(
temperaturaQueAchavaTC
==
200.0
)
{
temperaturaQueAchavaTC
=
temperaturaQueDizTC
;
if
(
SetpointMode
>
31
)
{
if
(
millis
()
<
1000
)
{
for
(
temperaturaMediaIndexTC
=
0
;
temperaturaMediaIndexTC
<
TEMPERATURE_SAMPLES_TC
;
temperaturaMediaIndexTC
++
)
{
temperaturaMediaTC
[
temperaturaMediaIndexTC
]
=
temperaturaQueAchavaTC
;
}
}
}
///TODO set automatic fermentation temperatures
// Calcular a temperatura de processamento
Setpoint
=
SetpointMode
-
32
+
0.5
;
temperaturaMediaIndexTC
++
;
if
(
temperaturaMediaIndexTC
>=
TEMPERATURE_SAMPLES_TC
)
{
temperaturaMediaIndexTC
=
0
;
}
if
(
temperaturaQueDizTC
>
(
temperaturaQueAchavaTC
+
0
))
{
//Serial.print("+0.1, ");
temperaturaMediaTC
[
temperaturaMediaIndexTC
]
=
(
temperaturaQueAchavaTC
+
0.2
);
}
}
else
{
else
{
if
(
temperaturaQueDizTC
<
(
temperaturaQueAchavaTC
-
0.1
))
{
//Serial.print("-0.1, ");
temperaturaMediaTC
[
temperaturaMediaIndexTC
]
=
(
temperaturaQueAchavaTC
-
1.0
);
}
else
{
//Serial.print(", ");
temperaturaMediaTC
[
temperaturaMediaIndexTC
]
=
temperaturaQueDizTC
;
}
}
// set manual temperatures
// Calcula a média
Setpoint
=
SetpointMode
;
double
tempetaturaQueEuAchoTC
=
0.0
;
for
(
int
i
=
0
;
i
<
TEMPERATURE_SAMPLES_TC
;
i
++
)
{
tempetaturaQueEuAchoTC
+=
temperaturaMediaTC
[
i
];
}
}
tempetaturaQueEuAchoTC
/=
TEMPERATURE_SAMPLES_TC
;
// Grava o valor aual para o proximo ciclo
temperaturaQueAchavaTC
=
tempetaturaQueEuAchoTC
;
#ifdef __debug
Serial
.
print
(
millis
());
Serial
.
print
(
", ThermoCouple, "
);
Serial
.
print
(
Setpoint
,
2
);
Serial
.
print
(
", "
);
Serial
.
print
(
temperaturaQueDizTC
,
2
);
Serial
.
print
(
", "
);
Serial
.
println
(
tempetaturaQueEuAchoTC
,
2
);
#endif
}
}
currentTime
=
millis
();
if
(
currentTime
>
(
dhtReadTime
+
200
))
{
// Read data off of the DHT11 sensor
// Read data off of the DHT11 sensor
int
chk
=
DHT
.
read11
(
DHT11_PIN
);
int
chk
=
DHT
.
read11
(
DHT11_PIN
);
// debug received data
// debug received data
tempSensorOK
=
debugDHT
(
chk
);
tempSensorOK
=
debugDHT
(
chk
);
dhtReadTime
=
millis
();
}
else
{
tempSensorOK
=
false
;
}
if
(
tempSensorOK
)
{
if
(
tempSensorOK
)
{
double
temperaturaQueDiz
=
DHT
.
temperature
;
double
temperaturaQueDiz
=
DHT
.
temperature
;
if
(
temperaturaQueAchava
==
200.0
)
{
if
(
temperaturaQueAchava
==
200.0
)
{
temperaturaQueAchava
=
temperaturaQueDiz
;
temperaturaQueAchava
=
temperaturaQueDiz
;
if
(
millis
()
<
1000
)
{
for
(
temperaturaMediaIndex
=
0
;
temperaturaMediaIndex
<
TEMPERATURE_SAMPLES
;
temperaturaMediaIndex
++
)
{
temperaturaMedia
[
temperaturaMediaIndex
]
=
temperaturaQueAchava
;
}
}
}
}
// Calcular a temperatura de processamento
// Calcular a temperatura de processamento
...
@@ -135,84 +217,131 @@ void loop()
...
@@ -135,84 +217,131 @@ void loop()
temperaturaMediaIndex
=
0
;
temperaturaMediaIndex
=
0
;
}
}
/*Serial.print("t[");
Serial.print(temperaturaMediaIndex);
Serial.print("]=");
Serial.print(temperaturaQueAchava);*/
if
(
temperaturaQueDiz
>
(
temperaturaQueAchava
+
0
))
{
if
(
temperaturaQueDiz
>
(
temperaturaQueAchava
+
0
))
{
//Serial.print("+0.1, ");
temperaturaMedia
[
temperaturaMediaIndex
]
=
(
temperaturaQueAchava
+
0.2
);
temperaturaMedia
[
temperaturaMediaIndex
]
=
(
temperaturaQueAchava
+
0.2
);
}
}
else
{
else
{
if
(
temperaturaQueDiz
<
(
temperaturaQueAchava
-
0.1
))
{
if
(
temperaturaQueDiz
<
(
temperaturaQueAchava
-
0.1
))
{
//Serial.print("-0.1, ");
temperaturaMedia
[
temperaturaMediaIndex
]
=
(
temperaturaQueAchava
-
1.0
);
temperaturaMedia
[
temperaturaMediaIndex
]
=
(
temperaturaQueAchava
-
1.0
);
}
}
else
{
else
{
//Serial.print(", ");
temperaturaMedia
[
temperaturaMediaIndex
]
=
temperaturaQueDiz
;
temperaturaMedia
[
temperaturaMediaIndex
]
=
temperaturaQueDiz
;
}
}
}
}
// Calcula a média
double
tempetaturaQueEuAcho
=
0.0
;
double
tempetaturaQueEuAcho
=
0.0
;
for
(
int
i
=
0
;
i
<
TEMPERATURE_SAMPLES
;
i
++
)
{
for
(
int
i
=
0
;
i
<
TEMPERATURE_SAMPLES
;
i
++
)
{
/*Serial.print(temperaturaMedia[i]);
Serial.print(" ");*/
tempetaturaQueEuAcho
+=
temperaturaMedia
[
i
];
tempetaturaQueEuAcho
+=
temperaturaMedia
[
i
];
}
}
tempetaturaQueEuAcho
/=
TEMPERATURE_SAMPLES
;
tempetaturaQueEuAcho
/=
TEMPERATURE_SAMPLES
;
//Serial.print(", ");
/*
// Grava o valor aual para o proximo ciclo
temperaturaQueAchava
=
tempetaturaQueEuAcho
;
#ifdef __debug
Serial
.
print
(
millis
());
Serial
.
print
(
", DHT, "
);
Serial
.
print
(
Setpoint
,
2
);
Serial
.
print
(
", "
);
Serial
.
print
(
temperaturaQueDiz
,
2
);
Serial
.
print
(
", "
);
Serial
.
println
(
tempetaturaQueEuAcho
,
2
);
#endif
if (temperaturaQueAchava > temperaturaQueDiz)
executeCompressorControl
(
tempetaturaQueEuAcho
,
Setpoint
);
tempetaturaQueEuAcho = temperaturaQueAchava - 0.25;
}
else if (temperaturaQueAchava < temperaturaQueDiz)
tempetaturaQueEuAcho = temperaturaQueAchava + 0.25;
else
tempetaturaQueEuAcho = temperaturaQueAchava;
//tempetaturaQueEuAcho = temperaturaQueDiz;
#ifdef __info
*/
Serial
.
print
(
millis
());
#ifdef __debug
Serial
.
print
(
", "
);
Serial
.
print
(
""
);
Serial
.
print
(
Setpoint
,
2
);
Serial
.
print
(
Setpoint
,
2
);
Serial
.
print
(
", "
);
Serial
.
print
(
", "
);
Serial
.
print
(
temperaturaQue
Diz
,
2
);
Serial
.
print
(
temperaturaQue
Achava
,
2
);
Serial
.
print
(
", "
);
Serial
.
print
(
", "
);
Serial
.
print
(
tempe
taturaQueEuAcho
,
2
);
Serial
.
print
(
tempe
raturaQueAchavaTC
,
2
);
Serial
.
print
(
", "
);
Serial
.
print
(
", "
);
#endif
Serial
.
println
(
relayState
?
"1"
:
"0"
);
#endif
}
if
(
tempetaturaQueEuAcho
>=
(
Setpoint
+
1.0
)
)
{
void
processBtnPress
()
{
if
(
hasBtnPressed
()
)
{
// turn on compressor to start cooling
// increase mode
relayState
=
true
;
SetpointMode
++
;
digitalWrite
(
RelayPin
,
LOW
);
// reset mode back to 0
if
(
SetpointMode
>
63
)
{
SetpointMode
=
0
;
}
// change leds
setLEDs
(
SetpointMode
);
if
(
SetpointMode
>
31
)
{
///TODO set automatic fermentation temperatures
Setpoint
=
SetpointMode
-
32
+
0.5
;
}
else
{
// set manual temperatures
Setpoint
=
SetpointMode
;
}
}
}
void
executeCompressorControl
(
double
tempetaturaAtual
,
double
temperaturaTarget
)
{
if
(
tempetaturaAtual
>=
(
temperaturaTarget
+
1.0
)
)
{
setCompressor
(
true
);
}
}
else
{
else
{
if
(
tempetaturaQueEuAcho
<=
(
Setpoint
-
0.0
)
)
{
if
(
tempetaturaAtual
<=
(
temperaturaTarget
-
0.0
)
)
{
setCompressor
(
false
);
}
}
}
void
setCompressor
(
boolean
turnIt
)
{
currentTime
=
millis
();
if
(
relayState
)
{
if
(
turnIt
)
{
// Nothing to do, it is on, will stay on
}
else
{
// turn off compressor to stop cooling
// turn off compressor to stop cooling
lastTurnOff
=
currentTime
;
relayState
=
false
;
relayState
=
false
;
digitalWrite
(
RelayPin
,
HIGH
);
digitalWrite
(
RelayPin
,
HIGH
);
}
}
}
}
else
{
if
(
turnIt
)
{
if
(
currentTime
>=
(
lastTurnOff
+
MINIMUM_TIME_OFF
))
{
// turn on compressor to start cooling
relayState
=
true
;
digitalWrite
(
RelayPin
,
LOW
);
}
}
else
{
// Nothing to do, it is off, will stay off
}
}
#ifdef __debug
#ifdef __debug
Serial
.
print
(
millis
());
Serial
.
print
(
", Compressor, "
);
Serial
.
print
(
Setpoint
,
2
);
Serial
.
print
(
", "
);
if
(
relayState
)
{
if
(
relayState
)
{
Serial
.
println
(
"ON"
);
Serial
.
println
(
"ON"
);
}
}
else
{
else
{
Serial
.
println
(
"OFF"
);
Serial
.
println
(
"OFF"
);
}
}
#endif
#endif
temperaturaQueAchava
=
tempetaturaQueEuAcho
;
delay
(
50
);
//delay(100);
}
}
}
void
setLEDs
(
int
number
)
{
void
setLEDs
(
int
number
)
{
...
@@ -258,10 +387,10 @@ boolean debugDHT( int chk ) {
...
@@ -258,10 +387,10 @@ boolean debugDHT( int chk ) {
{
{
case
DHTLIB_OK
:
case
DHTLIB_OK
:
ret
=
true
;
ret
=
true
;
#ifdef __debug
/*
#ifdef __debug
Serial.print("DHT11, ");
Serial.print("DHT11, ");
Serial.print("OK, ");
Serial.print("OK, ");
#endif
#endif
*/
break
;
break
;
case
DHTLIB_ERROR_CHECKSUM
:
case
DHTLIB_ERROR_CHECKSUM
:
Serial
.
print
(
"Checksum error, "
);
Serial
.
print
(
"Checksum error, "
);
...
...
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