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
dbae2a86
Commit
dbae2a86
authored
Dec 10, 2018
by
Indiana Brown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test
parent
a1276a5d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
4 deletions
+25
-4
iot_soil_moisture_master.ino
iot_soil_moisture_master.ino
+25
-4
No files found.
iot_soil_moisture_master.ino
View file @
dbae2a86
//Libraries
#include "ThingSpeak.h"
#include <WiFi.h>
#include <SPI.h>
//Program variables
int
sInput1
;
int
sInput2
;
int
sInput3
;
int
vccPin
=
13
;
//Averages variables
int
Avg1
,
Avg2
,
Avg3
,
Avg4
;
...
...
@@ -40,7 +39,12 @@ void setup() {
String
fv
=
WiFi
.
firmwareVersion
();
if
(
fv
!=
"1.1.0"
)
{
Serial
.
println
(
"Update the firmware of the WiFi shield to avoid unexpected issues."
);
}
}
//Sets the pin mode for pin 13 to output and gives it a 5v current
pinMode
(
vccPin
,
OUTPUT
);
digitalWrite
(
vccPin
,
HIGH
);
//Establishes ThingSpeak client
ThingSpeak
.
begin
(
client
);
}
...
...
@@ -49,10 +53,11 @@ void loop() {
connectToWPA
();
Serial
.
println
(
"Reading data."
);
takeReadings
();
//debug(); //For showing the program working (speeds up reading time and prints to console, otherwise remains the same).
dailyReading
=
((
Avg1
+
Avg2
+
Avg3
+
Avg4
)
/
4
);
//Print for debug
Serial
.
print
(
"Daily reading is: "
);
Serial
.
print
(
dailyReading
);
Serial
.
print
ln
(
dailyReading
);
Serial
.
println
(
"Attempting to send data."
);
//Attempt to write the data to ThingSpeak
ThingSpeak
.
setField
(
3
,
dailyReading
);
...
...
@@ -88,37 +93,45 @@ void connectToWPA() {
//Takes four averages (once every six hours) for the purpose of reporting the daily reading.
void
takeReadings
(){
//First average
digitalWrite
(
vccPin
,
HIGH
);
sInput1
=
analogRead
(
A0
);
sInput2
=
analogRead
(
A1
);
sInput3
=
analogRead
(
A2
);
Avg1
=
((
sInput1
+
sInput2
+
sInput3
)
/
3
);
digitalWrite
(
vccPin
,
LOW
);
//Delay 6 hours
delay
(
21600000
);
//Second average
digitalWrite
(
vccPin
,
HIGH
);
sInput1
=
analogRead
(
A0
);
sInput2
=
analogRead
(
A1
);
sInput3
=
analogRead
(
A2
);
Avg2
=
((
sInput1
+
sInput2
+
sInput3
)
/
3
);
digitalWrite
(
vccPin
,
LOW
);
//Delay 6 hours
delay
(
21600000
);
//Third average
digitalWrite
(
vccPin
,
HIGH
);
sInput1
=
analogRead
(
A0
);
sInput2
=
analogRead
(
A1
);
sInput3
=
analogRead
(
A2
);
Avg3
=
((
sInput1
+
sInput2
+
sInput3
)
/
3
);
digitalWrite
(
vccPin
,
LOW
);
//Delay 6 hours
delay
(
21600000
);
//Fourth average
digitalWrite
(
vccPin
,
HIGH
);
sInput1
=
analogRead
(
A0
);
sInput2
=
analogRead
(
A1
);
sInput3
=
analogRead
(
A2
);
Avg4
=
((
sInput1
+
sInput2
+
sInput3
)
/
3
);
digitalWrite
(
vccPin
,
LOW
);
//Delay 6 hours
delay
(
21600000
);
...
...
@@ -127,10 +140,12 @@ void takeReadings(){
//Debug method to demonstrate that my program works.
void
debug
(){
//First average
digitalWrite
(
vccPin
,
HIGH
);
sInput1
=
analogRead
(
A0
);
sInput2
=
analogRead
(
A1
);
sInput3
=
analogRead
(
A2
);
Avg1
=
((
sInput1
+
sInput2
+
sInput3
)
/
3
);
digitalWrite
(
vccPin
,
LOW
);
Serial
.
print
(
"First average: "
);
Serial
.
println
(
Avg1
);
//Delay 10 seconds
...
...
@@ -138,10 +153,12 @@ void debug(){
//Second average
digitalWrite
(
vccPin
,
HIGH
);
sInput1
=
analogRead
(
A0
);
sInput2
=
analogRead
(
A1
);
sInput3
=
analogRead
(
A2
);
Avg2
=
((
sInput1
+
sInput2
+
sInput3
)
/
3
);
digitalWrite
(
vccPin
,
LOW
);
Serial
.
print
(
"Second average: "
);
Serial
.
println
(
Avg2
);
//Delay 10 seconds
...
...
@@ -149,10 +166,12 @@ void debug(){
//Third average
digitalWrite
(
vccPin
,
HIGH
);
sInput1
=
analogRead
(
A0
);
sInput2
=
analogRead
(
A1
);
sInput3
=
analogRead
(
A2
);
Avg3
=
((
sInput1
+
sInput2
+
sInput3
)
/
3
);
digitalWrite
(
vccPin
,
LOW
);
Serial
.
print
(
"Third average: "
);
Serial
.
println
(
Avg3
);
//Delay 10 seconds
...
...
@@ -160,10 +179,12 @@ void debug(){
//Fourth average
digitalWrite
(
vccPin
,
HIGH
);
sInput1
=
analogRead
(
A0
);
sInput2
=
analogRead
(
A1
);
sInput3
=
analogRead
(
A2
);
Avg4
=
((
sInput1
+
sInput2
+
sInput3
)
/
3
);
digitalWrite
(
vccPin
,
LOW
);
Serial
.
print
(
"Fourth average: "
);
Serial
.
println
(
Avg4
);
//Delay 10 seconds
...
...
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