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
5ac31476
Commit
5ac31476
authored
Sep 01, 2022
by
DESKTOP-D7AKHEM\Rajindu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
light controlling code
parent
c1541063
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
153 additions
and
18 deletions
+153
-18
iot/envbot/EnvBot.ino
iot/envbot/EnvBot.ino
+153
-18
No files found.
iot/envbot/EnvBot.ino
View file @
5ac31476
...
...
@@ -28,8 +28,12 @@ String outputFuzzyHumidifier;
//-----------------pin definitions and variables related to light-----------------------------
#define LIGHT_PIN 5
int
lightSetPoint
,
currentLightPwm
=
0
;
float
lightRead
;
int
lightSetPoint
;
float
lightRead
,
deltaSetLight
,
pwmValueLeds
,
lightVeryLarge
,
lightLarge
,
lightNormal
,
lightSmall
,
lightVerySmall
,
//fuzzy member for delta light
lightRule1
,
lightRule2a
,
lightRule2b
,
lightRule3a
,
lightRule3b
,
lightRule4a
,
lightRule4b
,
lightRule5
,
//fuzzy rules for light setting
outputLeds
;
//output rules
String
outputFuzzyLeds
;
//-----------------pin definitions and variables related to air-------------------------------
#define MQ_PIN A0
...
...
@@ -72,18 +76,22 @@ void loop() {
//temp_fuzzy_output();
//humidity functions
humidity_set
();
//set required humidity for strawberry
humidity_readSensor
();
//function for reading humidity from sensor
humidity_fuzzification
();
humidity_fuzzy_rule
();
humidity_defuzzification
();
humidity_output
();
humidity_fuzzy_output
();
//
humidity_set(); //set required humidity for strawberry
//
humidity_readSensor(); //function for reading humidity from sensor
//
humidity_fuzzification();
//
humidity_fuzzy_rule();
//
humidity_defuzzification();
//
humidity_output();
//
humidity_fuzzy_output();
//light functions
//light_set();
//light_readSensor();
//light_control(); //TODO
light_set
();
//set required light intensity for strawberry
light_readSensor
();
//function for reading light intensity from sensor
light_fuzzification
();
light_fuzzy_rule
();
light_defuzzification
();
light_output
();
light_fuzzy_output
();
//air funtions
//air_quality_set();
...
...
@@ -386,21 +394,148 @@ void humidity_fuzzy_output(){
//-------------light-----------------------
void
light_set
(){
lightSetPoint
=
2
0
;
//set required light set point for strawberry
lightSetPoint
=
2
254
;
//set required light set point for strawberry
}
void
light_readSensor
(){
lightRead
=
GY30
.
readLightLevel
();
//read light intensity from light sensor
//lightRead = 19;
//lightRead = GY30.readLightLevel(); //read light intensity from light sensor
lightRead
=
754
;
if
(
lightRead
<
lightSetPoint
){
deltaSetLight
=
abs
(
lightSetPoint
-
lightRead
);
//find the light differece between sensor input and the set light intensity
}
else
{
deltaSetLight
=
0
;
}
Serial
.
print
(
"Light Intensity: "
);
Serial
.
println
(
lightRead
);
Serial
.
print
(
"Difference: "
);
Serial
.
println
(
deltaSetLight
);
}
void
light_control
(){
analogWrite
(
LIGHT_PIN
,
255
);
void
light_fuzzification
(){
deltaLightVerySmall
();
deltaLightSmall
();
deltaLightNormal
();
deltaLightLarge
();
deltaLightVeryLarge
();
}
unsigned
char
deltaLightVerySmall
(){
if
(
deltaSetLight
<=
400
){
lightVerySmall
=
1
;
}
else
if
(
deltaSetLight
>=
400
&&
deltaSetLight
<=
800
){
lightVerySmall
=
(
800
-
deltaSetLight
)
/
400
;
}
else
if
(
deltaSetLight
>=
800
){
lightVerySmall
=
0
;
}
Serial
.
print
(
"Delta Very Small: "
);
Serial
.
println
(
lightVerySmall
);
return
lightVerySmall
;
}
unsigned
char
deltaLightSmall
(){
if
(
deltaSetLight
<=
400
){
lightSmall
=
0
;
}
else
if
(
deltaSetLight
>=
400
&&
deltaSetLight
<=
800
){
lightSmall
=
(
deltaSetLight
-
400
)
/
400
;
}
else
if
(
deltaSetLight
>=
800
&&
deltaSetLight
<=
1200
){
lightSmall
=
(
1200
-
deltaSetLight
)
/
400
;
}
else
if
(
deltaSetLight
>=
1200
){
lightSmall
=
0
;
}
Serial
.
print
(
"Delta Small: "
);
Serial
.
println
(
lightSmall
);
return
lightSmall
;
}
unsigned
char
deltaLightNormal
(){
if
(
deltaSetLight
<=
800
){
lightNormal
=
0
;
}
else
if
(
deltaSetLight
>=
800
&&
deltaSetLight
<=
1200
){
lightNormal
=
(
deltaSetLight
-
800
)
/
400
;
}
else
if
(
deltaSetLight
>=
1200
&&
deltaSetLight
<=
1600
){
lightNormal
=
(
1600
-
deltaSetLight
)
/
400
;
}
else
if
(
deltaSetLight
>=
1600
){
lightNormal
=
0
;
}
Serial
.
print
(
"Delta Normal: "
);
Serial
.
println
(
lightNormal
);
return
lightNormal
;
}
unsigned
char
deltaLightLarge
(){
if
(
deltaSetLight
<=
1200
){
lightLarge
=
0
;
}
else
if
(
deltaSetLight
>=
1200
&&
deltaSetLight
<=
1600
){
lightLarge
=
(
deltaSetLight
-
1200
)
/
400
;
}
else
if
(
deltaSetLight
>=
1600
&&
deltaSetLight
<=
2000
){
lightLarge
=
(
2000
-
deltaSetLight
)
/
400
;
}
else
if
(
deltaSetLight
>=
2000
){
lightLarge
=
0
;
}
Serial
.
print
(
"Delta Large: "
);
Serial
.
println
(
lightLarge
);
return
lightLarge
;
}
unsigned
char
deltaLightVeryLarge
(){
if
(
deltaSetLight
<=
1600
){
lightVeryLarge
=
0
;
}
else
if
(
deltaSetLight
>=
1600
&&
deltaSetLight
<=
2000
){
lightVeryLarge
=
(
deltaSetLight
-
1600
)
/
400
;
}
else
if
(
deltaSetLight
>=
2000
){
lightVeryLarge
=
1
;
}
Serial
.
print
(
"Delta Very Large: "
);
Serial
.
println
(
lightVeryLarge
);
return
lightVeryLarge
;
}
void
light_fuzzy_rule
(){
lightRule1
=
80
+
(
lightVeryLarge
*
20
);
lightRule2a
=
60
+
(
lightLarge
*
20
);
lightRule2b
=
100
-
(
lightLarge
*
20
);
lightRule3a
=
40
+
(
lightNormal
*
20
);
lightRule3b
=
80
-
(
lightNormal
*
20
);
lightRule4a
=
20
+
(
lightSmall
*
20
);
lightRule4b
=
60
-
(
lightSmall
*
20
);
lightRule5
=
40
-
(
lightVerySmall
*
20
);
}
void
light_defuzzification
(){
outputLeds
=
((
lightRule1
*
lightVeryLarge
)
+
(
lightRule2a
*
lightLarge
)
+
(
lightRule2b
*
lightLarge
)
+
(
lightRule3a
*
lightNormal
)
+
(
lightRule3b
*
lightNormal
)
+
(
lightRule4a
*
lightSmall
)
+
(
lightRule4b
*
lightSmall
)
+
(
lightRule5
*
lightVerySmall
))
/
(
lightVeryLarge
+
lightLarge
+
lightLarge
+
lightNormal
+
lightNormal
+
lightSmall
+
lightSmall
+
lightVerySmall
);
Serial
.
print
(
"Leds Output Duty: "
);
Serial
.
println
(
outputLeds
);
}
void
light_output
(){
pwmValueLeds
=
map
(
outputLeds
,
0
,
100
,
0
,
255
);
Serial
.
print
(
"Leds Output PWM: "
);
Serial
.
println
(
pwmValueLeds
);
analogWrite
(
LIGHT_PIN
,
pwmValueLeds
);
}
void
light_fuzzy_output
(){
if
(
outputLeds
<=
20
){
outputFuzzyLeds
=
"Very Low"
;
}
else
if
(
outputLeds
>=
20
&&
outputLeds
<=
40
){
outputFuzzyLeds
=
"Low"
;
}
else
if
(
outputLeds
>=
40
&&
outputLeds
<=
60
){
outputFuzzyLeds
=
"Normal"
;
}
else
if
(
outputLeds
>=
60
&&
outputLeds
<=
80
){
outputFuzzyLeds
=
"High"
;
}
else
if
(
outputLeds
>=
80
&&
outputLeds
<=
100
){
outputFuzzyLeds
=
"Very High"
;
}
Serial
.
print
(
"Fuzzy Output Leds: "
);
Serial
.
println
(
outputFuzzyLeds
);
}
/*void light_control(){
analogWrite(LIGHT_PIN, 255);
}*/
//------------------air quality--------------------
void
air_quality_set
(){
airQualitySetPoint
=
20
;
//set required air quality set point for strawberry
...
...
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