Commit dbae2a86 authored by Indiana Brown's avatar Indiana Brown

Test

parent a1276a5d
//Libraries //Libraries
#include "ThingSpeak.h" #include "ThingSpeak.h"
#include <WiFi.h> #include <WiFi.h>
#include <SPI.h>
//Program variables //Program variables
int sInput1; int sInput1;
int sInput2; int sInput2;
int sInput3; int sInput3;
int vccPin = 13;
//Averages variables //Averages variables
int Avg1, Avg2, Avg3, Avg4; int Avg1, Avg2, Avg3, Avg4;
...@@ -40,7 +39,12 @@ void setup() { ...@@ -40,7 +39,12 @@ void setup() {
String fv = WiFi.firmwareVersion(); String fv = WiFi.firmwareVersion();
if (fv != "1.1.0") { if (fv != "1.1.0") {
Serial.println("Update the firmware of the WiFi shield to avoid unexpected issues."); 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); ThingSpeak.begin(client);
} }
...@@ -49,10 +53,11 @@ void loop() { ...@@ -49,10 +53,11 @@ void loop() {
connectToWPA(); connectToWPA();
Serial.println("Reading data."); Serial.println("Reading data.");
takeReadings(); 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); dailyReading = ((Avg1 + Avg2 + Avg3 + Avg4)/4);
//Print for debug //Print for debug
Serial.print("Daily reading is: "); Serial.print("Daily reading is: ");
Serial.print(dailyReading); Serial.println(dailyReading);
Serial.println("Attempting to send data."); Serial.println("Attempting to send data.");
//Attempt to write the data to ThingSpeak //Attempt to write the data to ThingSpeak
ThingSpeak.setField(3, dailyReading); ThingSpeak.setField(3, dailyReading);
...@@ -88,37 +93,45 @@ void connectToWPA() { ...@@ -88,37 +93,45 @@ void connectToWPA() {
//Takes four averages (once every six hours) for the purpose of reporting the daily reading. //Takes four averages (once every six hours) for the purpose of reporting the daily reading.
void takeReadings(){ void takeReadings(){
//First average //First average
digitalWrite(vccPin, HIGH);
sInput1 = analogRead(A0); sInput1 = analogRead(A0);
sInput2 = analogRead(A1); sInput2 = analogRead(A1);
sInput3 = analogRead(A2); sInput3 = analogRead(A2);
Avg1 = ((sInput1 + sInput2 + sInput3)/3); Avg1 = ((sInput1 + sInput2 + sInput3)/3);
digitalWrite(vccPin, LOW);
//Delay 6 hours //Delay 6 hours
delay(21600000); delay(21600000);
//Second average //Second average
digitalWrite(vccPin, HIGH);
sInput1 = analogRead(A0); sInput1 = analogRead(A0);
sInput2 = analogRead(A1); sInput2 = analogRead(A1);
sInput3 = analogRead(A2); sInput3 = analogRead(A2);
Avg2 = ((sInput1 + sInput2 + sInput3)/3); Avg2 = ((sInput1 + sInput2 + sInput3)/3);
digitalWrite(vccPin, LOW);
//Delay 6 hours //Delay 6 hours
delay(21600000); delay(21600000);
//Third average //Third average
digitalWrite(vccPin, HIGH);
sInput1 = analogRead(A0); sInput1 = analogRead(A0);
sInput2 = analogRead(A1); sInput2 = analogRead(A1);
sInput3 = analogRead(A2); sInput3 = analogRead(A2);
Avg3 = ((sInput1 + sInput2 + sInput3)/3); Avg3 = ((sInput1 + sInput2 + sInput3)/3);
digitalWrite(vccPin, LOW);
//Delay 6 hours //Delay 6 hours
delay(21600000); delay(21600000);
//Fourth average //Fourth average
digitalWrite(vccPin, HIGH);
sInput1 = analogRead(A0); sInput1 = analogRead(A0);
sInput2 = analogRead(A1); sInput2 = analogRead(A1);
sInput3 = analogRead(A2); sInput3 = analogRead(A2);
Avg4 = ((sInput1 + sInput2 + sInput3)/3); Avg4 = ((sInput1 + sInput2 + sInput3)/3);
digitalWrite(vccPin, LOW);
//Delay 6 hours //Delay 6 hours
delay(21600000); delay(21600000);
...@@ -127,10 +140,12 @@ void takeReadings(){ ...@@ -127,10 +140,12 @@ void takeReadings(){
//Debug method to demonstrate that my program works. //Debug method to demonstrate that my program works.
void debug(){ void debug(){
//First average //First average
digitalWrite(vccPin, HIGH);
sInput1 = analogRead(A0); sInput1 = analogRead(A0);
sInput2 = analogRead(A1); sInput2 = analogRead(A1);
sInput3 = analogRead(A2); sInput3 = analogRead(A2);
Avg1 = ((sInput1 + sInput2 + sInput3)/3); Avg1 = ((sInput1 + sInput2 + sInput3)/3);
digitalWrite(vccPin, LOW);
Serial.print("First average: "); Serial.print("First average: ");
Serial.println(Avg1); Serial.println(Avg1);
//Delay 10 seconds //Delay 10 seconds
...@@ -138,10 +153,12 @@ void debug(){ ...@@ -138,10 +153,12 @@ void debug(){
//Second average //Second average
digitalWrite(vccPin, HIGH);
sInput1 = analogRead(A0); sInput1 = analogRead(A0);
sInput2 = analogRead(A1); sInput2 = analogRead(A1);
sInput3 = analogRead(A2); sInput3 = analogRead(A2);
Avg2 = ((sInput1 + sInput2 + sInput3)/3); Avg2 = ((sInput1 + sInput2 + sInput3)/3);
digitalWrite(vccPin, LOW);
Serial.print("Second average: "); Serial.print("Second average: ");
Serial.println(Avg2); Serial.println(Avg2);
//Delay 10 seconds //Delay 10 seconds
...@@ -149,10 +166,12 @@ void debug(){ ...@@ -149,10 +166,12 @@ void debug(){
//Third average //Third average
digitalWrite(vccPin, HIGH);
sInput1 = analogRead(A0); sInput1 = analogRead(A0);
sInput2 = analogRead(A1); sInput2 = analogRead(A1);
sInput3 = analogRead(A2); sInput3 = analogRead(A2);
Avg3 = ((sInput1 + sInput2 + sInput3)/3); Avg3 = ((sInput1 + sInput2 + sInput3)/3);
digitalWrite(vccPin, LOW);
Serial.print("Third average: "); Serial.print("Third average: ");
Serial.println(Avg3); Serial.println(Avg3);
//Delay 10 seconds //Delay 10 seconds
...@@ -160,10 +179,12 @@ void debug(){ ...@@ -160,10 +179,12 @@ void debug(){
//Fourth average //Fourth average
digitalWrite(vccPin, HIGH);
sInput1 = analogRead(A0); sInput1 = analogRead(A0);
sInput2 = analogRead(A1); sInput2 = analogRead(A1);
sInput3 = analogRead(A2); sInput3 = analogRead(A2);
Avg4 = ((sInput1 + sInput2 + sInput3)/3); Avg4 = ((sInput1 + sInput2 + sInput3)/3);
digitalWrite(vccPin, LOW);
Serial.print("Fourth average: "); Serial.print("Fourth average: ");
Serial.println(Avg4); Serial.println(Avg4);
//Delay 10 seconds //Delay 10 seconds
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment