Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
3
3CB105 Internet of Things - Soil Moisture Artifact - Indiana Brown
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Indiana Brown
3CB105 Internet of Things - Soil Moisture Artifact - Indiana Brown
Commits
de93f367
Commit
de93f367
authored
Dec 04, 2018
by
Indiana Brown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parents
Pipeline
#399
canceled with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
122 additions
and
0 deletions
+122
-0
iot_soil_moisture_master.ino
iot_soil_moisture_master.ino
+122
-0
No files found.
iot_soil_moisture_master.ino
0 → 100644
View file @
de93f367
//Libraries
#include "ThingSpeak.h"
#include <WiFi.h>
#include <SPI.h>
//Program variables
int
sInput1
;
int
sInput2
;
int
sInput3
;
int
vccPin
=
12
;
int
average
;
int
debugID
=
1
;
//Connectivity variables
char
ssid
[]
=
"BTHub5-MKS7"
;
char
pass
[]
=
"42d6789b8d"
;
int
status
=
WL_IDLE_STATUS
;
WiFiClient
client
;
//ThingSpeak variables
unsigned
long
myChannelNumber
=
640257
;
const
char
*
myWriteAPIKey
=
"BRO3JQU737EE4WN9"
;
int
timer
=
24
;
//Setup
void
setup
()
{
Serial
.
begin
(
9600
);
Serial
.
println
(
"Program starting."
);
Serial
.
println
(
" "
);
pinMode
(
vccPin
,
OUTPUT
);
pinMode
(
10
,
OUTPUT
);
digitalWrite
(
10
,
LOW
);
//check for the presence of the shield:
if
(
WiFi
.
status
()
==
WL_NO_SHIELD
)
{
Serial
.
println
(
"WiFi shield not present"
);
// don't continue:
while
(
true
);
}
String
fv
=
WiFi
.
firmwareVersion
();
if
(
fv
!=
"1.1.0"
)
{
Serial
.
println
(
"Please upgrade the firmware"
);
}
ThingSpeak
.
begin
(
client
);
}
//Loop
void
loop
()
{
connectToWPA
();
delay
(
2000
);
Serial
.
println
(
"Reading data."
);
sInput1
=
analogRead
(
A0
);
sInput2
=
analogRead
(
A1
);
sInput3
=
analogRead
(
A2
);
average
=
((
sInput1
+
sInput2
+
sInput3
)
/
3
);
Serial
.
println
(
"Attempting to send data"
);
//int x = ThingSpeak.writeField(myChannelNumber, 1, average, myWriteAPIKey);
ThingSpeak
.
setField
(
1
,
average
);
ThingSpeak
.
setField
(
2
,
timer
);
int
x
=
ThingSpeak
.
writeFields
(
myChannelNumber
,
myWriteAPIKey
);
//x is the return code for HTTP. 200 means that the data was successfully transmitted.
if
(
x
==
200
){
Serial
.
println
(
"Channel update successful."
);
Serial
.
print
(
"Moisture value sent: "
);
Serial
.
println
(
average
);
Serial
.
print
(
"Timer value sent: "
);
Serial
.
println
(
timer
);
}
else
{
Serial
.
println
(
"Problem updating channel. HTTP error code "
+
String
(
x
));
}
//15 mins delay
delay
(
900000
);
debug
();
}
//debug() takes and prints the current readings for each of the three sensors and then prints their average reading.
//It is used for debugging only.
void
debug
()
{
digitalWrite
(
vccPin
,
HIGH
);
sInput1
=
analogRead
(
A0
);
sInput2
=
analogRead
(
A1
);
sInput3
=
analogRead
(
A2
);
average
=
((
sInput1
+
sInput2
+
sInput3
)
/
3
);
Serial
.
print
(
"Debug ID: "
);
Serial
.
println
(
debugID
);
debugID
++
;
Serial
.
println
(
" "
);
Serial
.
print
(
"Input 1: "
);
Serial
.
println
(
sInput1
);
Serial
.
print
(
"Input 2: "
);
Serial
.
println
(
sInput2
);
Serial
.
print
(
"Input 3: "
);
Serial
.
println
(
sInput3
);
Serial
.
println
(
" "
);
Serial
.
print
(
"Average reading: "
);
Serial
.
println
(
average
);
Serial
.
println
(
" "
);
Serial
.
println
(
" "
);
//digitalWrite(vccPin, LOW);
delay
(
5000
);
}
void
connectToWPA
()
{
if
(
WiFi
.
status
()
!=
WL_CONNECTED
){
Serial
.
print
(
"Attempting to connect to SSID: "
);
Serial
.
println
(
ssid
);
while
(
WiFi
.
status
()
!=
WL_CONNECTED
){
digitalWrite
(
10
,
LOW
);
WiFi
.
begin
(
ssid
,
pass
);
Serial
.
print
(
"."
);
delay
(
5000
);
}
Serial
.
println
(
"
\n
Connected."
);
digitalWrite
(
10
,
HIGH
);
}
}
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