Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2022-154
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
1
Merge Requests
1
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
2022-154
2022-154
Commits
a23bb1c1
Commit
a23bb1c1
authored
Oct 09, 2022
by
Samaranayake S.L
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update nutrition_dose.ino
parent
95f46db8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
122 additions
and
33 deletions
+122
-33
iot/Chembot/nutrition_dose.ino
iot/Chembot/nutrition_dose.ino
+122
-33
No files found.
iot/Chembot/nutrition_dose.ino
View file @
a23bb1c1
#include <EEPROM.h>
#include "GravityTDS.h"
#define TdsSensorPin A1
GravityTDS
gravityTds
;
const
int
RELAY_PIN
=
A5
;
// the Arduino pin, which connects to the IN pin of relay
float
temperature
=
25
,
tdsValue
=
0
;
const
int
RELAY_PIN
=
A5
;
const
int
RELAY_PIN1
=
A4
;
const
int
RELAY_PIN2
=
A3
;
const
int
RELAY_PIN3
=
A2
;
// Sensor pins for moisture sensor
/* Change these values based on your calibration values */
#define soilWet 500 // Define max value we consider soil 'wet'
#define soilDry 750 // Define min value we consider soil 'dry'
#define sensorPower 7
#define sensorPin A0
float
temperature
=
25
,
tdsValue
=
0
;
unsigned
long
prevTime_T1
=
0
;
unsigned
long
prevTime_T2
=
0
;
unsigned
long
prevTime_T3
=
0
;
unsigned
long
prevTime_T4
=
0
;
long
interval_T1
=
5000
;
long
interval_T2
=
10000
;
long
interval_T3
=
15000
;
long
interval_T4
=
20000
;
void
setup
()
{
Serial
.
begin
(
115200
);
gravityTds
.
setPin
(
TdsSensorPin
);
gravityTds
.
setAref
(
5.0
);
//reference voltage on ADC, default 5.0V on Arduino UNO
gravityTds
.
setAdcRange
(
1024
);
//1024 for 10bit ADC;4096 for 12bit ADC
gravityTds
.
begin
();
//initialization
pinMode
(
RELAY_PIN
,
OUTPUT
);
Serial
.
begin
(
115200
);
//Chembot
digitalWrite
(
RELAY_PIN3
,
HIGH
);
gravityTds
.
setPin
(
TdsSensorPin
);
gravityTds
.
setAref
(
5.0
);
//reference voltage on ADC, default 5.0V on Arduino UNO
gravityTds
.
setAdcRange
(
1024
);
//1024 for 10bit ADC;4096 for 12bit ADC
gravityTds
.
begin
();
//initialization
pinMode
(
RELAY_PIN
,
OUTPUT
);
//Hydrobot
pinMode
(
sensorPower
,
OUTPUT
);
digitalWrite
(
sensorPower
,
LOW
);
}
void
loop
()
{
//temperature = readTemperature(); //add your temperature sensor and read it
gravityTds
.
setTemperature
(
temperature
);
// set the temperature and execute temperature compensation
gravityTds
.
update
();
//sample and calculate
tdsValue
=
gravityTds
.
getTdsValue
();
// then get the value
Serial
.
print
(
tdsValue
,
0
);
Serial
.
println
(
"ppm"
);
digitalWrite
(
RELAY_PIN2
,
HIGH
);
// water pump
unsigned
long
currentTime
=
millis
();
if
(
tdsValue
>
350
){
digitalWrite
(
RELAY_PIN
,
LOW
);
// turn on pump
/*.....................................................CHEMBOT..........................................................*/
gravityTds
.
setTemperature
(
temperature
);
// set the temperature and execute temperature compensation
gravityTds
.
update
();
//sample and calculate
tdsValue
=
gravityTds
.
getTdsValue
();
// then get the value
Serial
.
print
(
tdsValue
,
0
);
Serial
.
println
(
"ppm"
);
delay
(
1000
);
Serial
.
println
(
"pump off"
);
tdsValue
=
gravityTds
.
getTdsValue
();
// then get the value
if
(
tdsValue
>
350
)
{
digitalWrite
(
RELAY_PIN
,
LOW
);
// turn of pump
Serial
.
println
(
"pump off"
);
tdsValue
=
gravityTds
.
getTdsValue
();
// then get the value
}
else
if
(
tdsValue
<
350
){
digitalWrite
(
RELAY_PIN
,
HIGH
);
// turn on pump
delay
(
500
);
digitalWrite
(
RELAY_PIN
,
LOW
);
// turn on pump
delay
(
1000
);
Serial
.
println
(
"pump on"
);
tdsValue
=
gravityTds
.
getTdsValue
();
// then get the value
else
if
(
tdsValue
<
350
)
{
if
(
currentTime
-
prevTime_T1
>
interval_T1
)
{
digitalWrite
(
RELAY_PIN
,
HIGH
);
// turn on dosing pump
Serial
.
println
(
"Dosing pump 1 on"
);
prevTime_T1
=
currentTime
+
5
;
if
(
currentTime
-
prevTime_T2
>
interval_T2
)
{
digitalWrite
(
RELAY_PIN
,
LOW
);
// turn oF dosing pump
Serial
.
println
(
"Dosing pump 1 off"
);
prevTime_T2
=
currentTime
;
}
if
(
currentTime
-
prevTime_T3
>
interval_T3
)
{
digitalWrite
(
RELAY_PIN
,
LOW
);
// turn oF dosing pump
Serial
.
println
(
"Dosing pump 1 off"
);
prevTime_T3
=
currentTime
;
}
if
(
currentTime
-
prevTime_T4
>
interval_T4
)
{
digitalWrite
(
RELAY_PIN
,
LOW
);
// turn oF dosing pump
Serial
.
println
(
"Dosing pump 1 off"
);
prevTime_T4
=
currentTime
;
}
}
}
else
if
(
tdsValue
>
450
)
{
digitalWrite
(
RELAY_PIN3
,
LOW
);
// turn on dosing pump
Serial
.
println
(
"Water Pump Turned Off"
);
Serial
.
println
(
"High EC level detected!!!"
);
}
/*....................................................FINISH CHEMBOT..................................................*/
/*.....................................................HydroBot........................................................*/
//get the reading from the function below and print it
int
val
=
readSensor
();
Serial
.
print
(
"Digital Output: "
);
Serial
.
println
(
val
);
// Determine status of our soil moisture situation
if
(
val
)
{
Serial
.
println
(
"Status: Soil is too dry - time to water!"
);
}
else
{
Serial
.
println
(
"Status: Soil moisture is perfect"
);
}
Serial
.
println
();
}
// This function returns the analog soil moisture measurement
int
readSensor
()
{
digitalWrite
(
sensorPower
,
HIGH
);
// Turn the sensor ON
delay
(
10
);
// Allow power to settle
int
val
=
digitalRead
(
sensorPin
);
// Read the analog value form sensor
digitalWrite
(
sensorPower
,
LOW
);
// Turn the sensor OFF
return
val
;
// Return analog moisture value
}
/*....................................................FINISH HydroBot..................................................*/
\ No newline at end of file
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