Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
ifarm
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
TMP-2022-009
ifarm
Commits
da66105c
Commit
da66105c
authored
Nov 16, 2022
by
ayodyabanuka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated Arduino Code
parent
844069e5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
35 deletions
+50
-35
lib/AB/Arduino Project/Project.ino
lib/AB/Arduino Project/Project.ino
+50
-35
No files found.
lib/AB/Arduino Project/Project.ino
View file @
da66105c
...
...
@@ -7,8 +7,8 @@
// Set these to run example.
#define FIREBASE_HOST "ifarm-4ec55-default-rtdb.firebaseio.com"
#define FIREBASE_AUTH "0XoTKCHRo5iB63DShpRfq5Q545GQfDlTcBxQrEkP"
#define WIFI_SSID "
Dialog 4G CB3
"
#define WIFI_PASSWORD "
BMy7M977
"
#define WIFI_SSID "
abfiber
"
#define WIFI_PASSWORD "
Ayobanuka@1998
"
#define LED1 D1
#define LED2 D2
#define TRIGGER_PIN D7
...
...
@@ -21,13 +21,13 @@ NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
// Declare the Firebase Data object in the global scope
FirebaseData
firebaseData
;
FirebaseData
firebaseData
Moist
,
firebaseDataLevel
,
firebaseDataServo
,
firebaseDataError
;
// Declare global variable to store value
int
val
=
0
;
Servo
servo
;
const
int
AirValue
=
1024.0
;
//you need to replace this value with Value_1
const
int
WaterValue
=
950.0
;
//you need to replace this value with Value_2
const
int
AirValue
=
1024.0
;
const
int
WaterValue
=
950.0
;
float
foodMoistureValue
=
0.0
;
float
foodmoisturepercent
=
0.0
;
float
foodpercent
=
0.0
;
...
...
@@ -42,11 +42,11 @@ void setup() {
pinMode
(
LED1
,
OUTPUT
);
digitalWrite
(
LED1
,
HIGH
);
pinMode
(
LED2
,
OUTPUT
);
digitalWrite
(
LED2
,
LOW
);
// connect to wifi.
servo
.
attach
(
2
);
//D4
servo
.
write
(
90
);
digitalWrite
(
LED2
,
LOW
);
servo
.
attach
(
2
);
//D4
servo
.
write
(
0
);
// connect to wifi.
WiFi
.
begin
(
WIFI_SSID
,
WIFI_PASSWORD
);
Serial
.
print
(
"connecting"
);
while
(
WiFi
.
status
()
!=
WL_CONNECTED
)
{
...
...
@@ -60,55 +60,70 @@ digitalWrite(LED2, LOW);
Serial
.
println
(
WiFi
.
localIP
());
Firebase
.
begin
(
FIREBASE_HOST
,
FIREBASE_AUTH
);
Firebase
.
setInt
(
firebaseData
,
"/Food/"
+
productnumber
+
"/SERVO"
,
0
);
Firebase
.
setInt
(
firebaseDataServo
,
"/Food/"
+
productnumber
+
"/SERVO"
,
0
);
Firebase
.
setInt
(
firebaseDataError
,
"/Food/"
+
productnumber
+
"/ERROR"
,
2
);
Serial
.
println
(
"Sensor Data
\n
"
);
}
int
s
=
0
;
int
e
=
1
;
void
loop
()
{
float
foodlimit
;
float
foodlimit
;
float
dis
=
sonar
.
ping_cm
();
if
(
dis
==
9
)
{
foodlimit
=
0
;
}
else
if
(
dis
<=
1
)
{
float
dis
=
sonar
.
ping_cm
();
if
(
dis
==
9
)
{
foodlimit
=
0
;
}
else
if
(
dis
<=
1
)
{
foodlimit
=
100
;
}
else
if
(
dis
>
1
||
dis
<
9
){
foodlimit
=
round
(((
8
-
dis
)
/
8
)
*
100
);
}
Firebase
.
setFloat
(
firebaseData
,
"/Food/"
+
productnumber
+
"/dis"
,
foodlimit
);
}
else
if
(
dis
>
1
||
dis
<
9
)
{
foodlimit
=
round
(((
9
-
dis
)
/
9
)
*
100
);
}
Firebase
.
setFloat
(
firebaseDataLevel
,
"/Food/"
+
productnumber
+
"/dis"
,
foodlimit
);
Serial
.
print
(
" Soil Moisture: "
);
Serial
.
print
(
foodpercent
);
Serial
.
print
(
"%"
);
Firebase
.
getInt
(
firebaseDataError
,
"/Food/"
+
productnumber
+
"/ERROR"
);
e
=
firebaseDataError
.
intData
();
Serial
.
print
(
" ERROR! "
);
Serial
.
println
(
e
);
if
(
e
==
1
)
{
digitalWrite
(
LED1
,
HIGH
);
}
else
if
(
e
==
2
)
{
digitalWrite
(
LED1
,
LOW
);
}
foodMoistureValue
=
analogRead
(
A0
);
foodmoisturepercent
=
map
(
foodMoistureValue
,
AirValue
,
WaterValue
,
0
,
100
);
if
(
foodmoisturepercent
>=
100.0
)
{
if
(
foodmoisturepercent
>=
100.0
)
{
foodpercent
=
100.0
;
}
else
if
(
foodmoisturepercent
<=
0.0
)
{
foodpercent
=
0.0
;
}
else
if
(
foodmoisturepercent
>
0.0
&&
foodmoisturepercent
<
100.0
)
{
foodpercent
=
foodmoisturepercent
;
}
}
else
if
(
foodmoisturepercent
<=
0.0
)
{
foodpercent
=
0.0
;
}
else
if
(
foodmoisturepercent
>
0.0
&&
foodmoisturepercent
<
100.0
)
{
foodpercent
=
foodmoisturepercent
;
}
Serial
.
print
(
" Soil Moisture: "
);
Serial
.
print
(
foodpercent
);
Serial
.
print
(
"%"
);
Firebase
.
setFloat
(
firebaseData
,
"/Food/"
+
productnumber
+
"/Moist/foodMoist"
,
foodpercent
);
if
(
Firebase
.
getInt
(
firebaseData
,
"/Food/"
+
productnumber
+
"/SERVO"
))
{
s
=
firebaseData
.
intData
();
Serial
.
print
(
" Servo: "
);
Serial
.
println
(
s
);
if
(
foodpercent
==
0
)
{
Firebase
.
setInt
(
firebaseDataMoist
,
"/Food/"
+
productnumber
+
"/ERROR"
,
2
);
}
else
{
Firebase
.
setInt
(
firebaseDataMoist
,
"/Food/"
+
productnumber
+
"/ERROR"
,
1
);
}
Firebase
.
setFloat
(
firebaseDataMoist
,
"/Food/"
+
productnumber
+
"/Moist/foodMoist"
,
foodpercent
);
Firebase
.
getInt
(
firebaseDataServo
,
"/Food/"
+
productnumber
+
"/SERVO"
);
s
=
firebaseDataServo
.
intData
();
Serial
.
print
(
" Servo: "
);
Serial
.
println
(
s
);
if
(
s
==
0
)
{
servo
.
write
(
0
);
// tell servo to go to position in variable 'pos'
delay
(
2000
);
return
;
}
else
{
servo
.
write
(
180
);
delay
(
2000
);
return
;
}
delay
(
1000
);
...
...
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