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
5d5e6a82
Commit
5d5e6a82
authored
Dec 10, 2018
by
Indiana Brown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added digital power pin (vccPin). Removed needless library (SPI.h).
parent
b6cbc041
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
173 deletions
+0
-173
iot_soil_moisture_master.ino
iot_soil_moisture_master.ino
+0
-173
No files found.
iot_soil_moisture_master.ino
deleted
100644 → 0
View file @
b6cbc041
//Libraries
#include "ThingSpeak.h"
#include <WiFi.h>
#include <SPI.h>
//Program variables
int
sInput1
;
int
sInput2
;
int
sInput3
;
//Averages variables
int
Avg1
,
Avg2
,
Avg3
,
Avg4
;
int
dailyReading
;
//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"
;
//Setup (runs once)
void
setup
()
{
//Serial monitor setup
Serial
.
begin
(
9600
);
Serial
.
println
(
"Program starting."
);
Serial
.
println
(
" "
);
//Checks for a WiFi shield and halts the program if one is not detected
if
(
WiFi
.
status
()
==
WL_NO_SHIELD
)
{
Serial
.
println
(
"There were problems detecting the WiFi sheild. Check connection."
);
while
(
true
);
}
//Checks if the firmware version is up-to-date
String
fv
=
WiFi
.
firmwareVersion
();
if
(
fv
!=
"1.1.0"
)
{
Serial
.
println
(
"Update the firmware of the WiFi shield to avoid unexpected issues."
);
}
ThingSpeak
.
begin
(
client
);
}
//Loop (runs continuously)
void
loop
()
{
connectToWPA
();
Serial
.
println
(
"Reading data."
);
takeReadings
();
dailyReading
=
((
Avg1
+
Avg2
+
Avg3
+
Avg4
)
/
4
);
//Print for debug
Serial
.
print
(
"Daily reading is: "
);
Serial
.
print
(
dailyReading
);
Serial
.
println
(
"Attempting to send data."
);
//Attempt to write the data to ThingSpeak
ThingSpeak
.
setField
(
3
,
dailyReading
);
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
(
dailyReading
);
}
else
{
Serial
.
println
(
"Problem updating channel. HTTP error code "
+
String
(
x
));
}
}
//Attempts to connect to the Internet.
void
connectToWPA
()
{
//Checks if device is already connected to the Internet. If it is not, it attempts a connection. Otherwise it moves on.
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
);
}
}
//Takes four averages (once every six hours) for the purpose of reporting the daily reading.
void
takeReadings
(){
//First average
sInput1
=
analogRead
(
A0
);
sInput2
=
analogRead
(
A1
);
sInput3
=
analogRead
(
A2
);
Avg1
=
((
sInput1
+
sInput2
+
sInput3
)
/
3
);
//Delay 6 hours
delay
(
21600000
);
//Second average
sInput1
=
analogRead
(
A0
);
sInput2
=
analogRead
(
A1
);
sInput3
=
analogRead
(
A2
);
Avg2
=
((
sInput1
+
sInput2
+
sInput3
)
/
3
);
//Delay 6 hours
delay
(
21600000
);
//Third average
sInput1
=
analogRead
(
A0
);
sInput2
=
analogRead
(
A1
);
sInput3
=
analogRead
(
A2
);
Avg3
=
((
sInput1
+
sInput2
+
sInput3
)
/
3
);
//Delay 6 hours
delay
(
21600000
);
//Fourth average
sInput1
=
analogRead
(
A0
);
sInput2
=
analogRead
(
A1
);
sInput3
=
analogRead
(
A2
);
Avg4
=
((
sInput1
+
sInput2
+
sInput3
)
/
3
);
//Delay 6 hours
delay
(
21600000
);
}
//Debug method to demonstrate that my program works.
void
debug
(){
//First average
sInput1
=
analogRead
(
A0
);
sInput2
=
analogRead
(
A1
);
sInput3
=
analogRead
(
A2
);
Avg1
=
((
sInput1
+
sInput2
+
sInput3
)
/
3
);
Serial
.
print
(
"First average: "
);
Serial
.
println
(
Avg1
);
//Delay 10 seconds
delay
(
10000
);
//Second average
sInput1
=
analogRead
(
A0
);
sInput2
=
analogRead
(
A1
);
sInput3
=
analogRead
(
A2
);
Avg2
=
((
sInput1
+
sInput2
+
sInput3
)
/
3
);
Serial
.
print
(
"Second average: "
);
Serial
.
println
(
Avg2
);
//Delay 10 seconds
delay
(
10000
);
//Third average
sInput1
=
analogRead
(
A0
);
sInput2
=
analogRead
(
A1
);
sInput3
=
analogRead
(
A2
);
Avg3
=
((
sInput1
+
sInput2
+
sInput3
)
/
3
);
Serial
.
print
(
"Third average: "
);
Serial
.
println
(
Avg3
);
//Delay 10 seconds
delay
(
10000
);
//Fourth average
sInput1
=
analogRead
(
A0
);
sInput2
=
analogRead
(
A1
);
sInput3
=
analogRead
(
A2
);
Avg4
=
((
sInput1
+
sInput2
+
sInput3
)
/
3
);
Serial
.
print
(
"Fourth average: "
);
Serial
.
println
(
Avg4
);
//Delay 10 seconds
delay
(
10000
);
}
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