//***Project Rain Shield***
//Measure temp every ten minutes, if condition is met, pull pin high to activate relay every 10 minutes for 10 seconds.
//Relay will control solenoid to turn on water.
//Delay between relay and water start must be accounted for.
#include <Wire.h>
//#include "Adafruit_MCP9808.h"
//Create the MCP9808 temperature sensor object
//Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
// Pin for relay module set as output
int myRelay = 8;
volatile byte relayState = LOW;
int myCount = 1;
void setup() {
Serial.begin(9600);
while (!Serial);
// if (!tempsensor.begin(0x18)) {
// Serial.println("MCP9808 not found! Check connections & verify address.");
// while (1);
// }
Serial.println("MCP9808! Connected");
// tempsensor.setResolution(0);
pinMode(myRelay, OUTPUT);
digitalWrite(myRelay, LOW);
relayState = LOW;
Serial.println("RELAY OFF");
}
void loop() {
//Wake temp sensor
// tempsensor.wake();
float myTemp = 101; //= tempsensor.readTempF();
Serial.print(myCount);Serial.print(" Temp: "); Serial.print(myTemp, 1); Serial.println("*F");
if(myTemp>100 && relayState == LOW){
pullRelayHIGH();
delay(2000);
pullRelayLOW();
}
//tempsensor.shutdown_wake(1); // shutdown MSP9808 - power consumption ~0.1 mikro Ampere, stops temperature sampling
myCount = myCount+1;
delay(5000);
}
void pullRelayHIGH() {
if(relayState != HIGH){
digitalWrite(myRelay, HIGH);
relayState = HIGH;
Serial.println("RELAY ON");
}
}
void pullRelayLOW() {
if(relayState != LOW){
digitalWrite(myRelay, LOW);
relayState = LOW;
Serial.println("RELAY OFF");
}
}