Skip to content

Commit

Permalink
Merged with alarm code
Browse files Browse the repository at this point in the history
  • Loading branch information
markypizz committed Nov 11, 2018
1 parent 7d9ba39 commit 83d7114
Show file tree
Hide file tree
Showing 5 changed files with 575 additions and 110 deletions.
140 changes: 120 additions & 20 deletions Arduino Code/Temp_Sensor/Temp_Sensor.ino
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@
#include <OneWire.h>
#include <DallasTemperature.h>
#include <EEPROM.h>
#include <SimpleTimer.h>

const int TSensor=4;
const int LED=7;
const int VALVE=2;
const int ONLED=7;
const int READYLED=2;

const byte ON = 2;
const byte OFF = 1;

OneWire
oneWire(TSensor);
const int MAX_HOT = 35;

DallasTemperature
sensors(&oneWire);
bool waitingCycles = false;
int counterForHotWater = 0;
bool timerStarted = false;

OneWire oneWire(TSensor);

DallasTemperature sensors(&oneWire);

SimpleTimer timer;
const int buzzer1=9;
const int buzzer2=8;

typedef struct {
int targetTemp;
int currentTemp;
bool hotValveClosed;
bool coldValveClosed;
bool grayWaterClosed;
bool mainLineClosed;
bool showerReady;
} stats;

stats statuses;

void setup(void) {
// put your setup code here, to run once:
pinMode(LED,OUTPUT);
pinMode(VALVE,OUTPUT);
pinMode(ONLED,OUTPUT);
pinMode(READYLED,OUTPUT);

Serial.begin(9600);
sensors.begin();
Expand All @@ -42,22 +51,113 @@ void setup(void) {
EEPROMWriteInt(0, temp);

statuses.targetTemp = temp;
statuses.currentTemp = 0;
statuses.hotValveClosed = true;
statuses.coldValveClosed = false;
statuses.grayWaterClosed = false;
statuses.currentTemp = 0;
statuses.coldValveClosed = true;
statuses.mainLineClosed = false;
statuses.showerReady = false;

digitalWrite(ONLED,HIGH);
}

void loop(void) {
sensors.requestTemperatures();
void firstwarning() {
tone(buzzer1,500); //((buzzer1,500) to send 500Hz sound signal
delay(200); // for 0.5 sec
noTone(buzzer1);
tone(buzzer2,500); //same
delay(500);
noTone(buzzer2);
timer.setTimeout(180000, secondwarning); // calls function after 3min
}

void secondwarning() {
timer.setTimer(5000, buzzerfunc1, 3);
timer.setInterval(60000, repeat); // repeats the function every 1min
}
void repeat() { //Calling functions to make the buzzer beep alternatively.
timer.setTimer(3000, buzzerfunc2, 5); // buzzerfunc2 will run 5 times every 3sec when function repeat is ran
}

void buzzerfunc1(){ //function for buzzer1
tone(buzzer1,700); //((buzzer1,500) to send 700Hz sound signal
delay(500); // for 0.5 sec
noTone(buzzer1);
tone(buzzer2,700); //((buzzer1,500) to send 700Hz sound signal
delay(700); // for 0.7 sec
noTone(buzzer2);
}

if (sensors.getTempCByIndex(0) > 30) {
statuses.hotValveClosed = true;
void buzzerfunc2(){ //function for buzzer1
tone(buzzer1,1000); //((buzzer1,500) to send 1000Hz sound signal
delay(300); // for 0.3 sec
noTone(buzzer1);
tone(buzzer2,1000); //((buzzer1,500) to send 1000Hz sound signal
delay(500); // for 0.5 sec
noTone(buzzer2);
}

void showerReadyAlert(){
tone(buzzer1,1000); //((buzzer1,1000) to send 1000Hz sound signal
tone(buzzer2,1000); //((buzzer2,1000) to send 1000Hz sound signal
delay(1000); // for 1 sec
noTone(buzzer1);
noTone(buzzer2);
}

void loop(void) {
//
// Look here for incoming iphone messages
// from serial port
//
//

if (waitingCycles) {
counterForHotWater += 1;

if (counterForHotWater == 5) {
//Open cold valve


waitingCycles = false;
}

} else {
statuses.hotValveClosed = false;
}
sensors.requestTemperatures();
int currentTemp = sensors.getTempCByIndex(0);

if (counterForHotWater == 5) {
if (!(statuses.showerReady)) {
//Shower not ready
if (currentTemp > statuses.targetTemp) {
//Alert with app
statuses.showerReady = true;

//Alert with Buzzers and LED
showerReadyAlert();
digitalWrite(READYLED,HIGH);

}
} else {
// Shower begun, start timer
if (timerStarted == false) {
timer.setTimeout(300000, firstwarning);
timerStarted = true;
}

//Poll timer
timer.run();
}
} else {
//Waiting to enable cold valve
if (currentTemp > MAX_HOT) {
//Open cold valve
statuses.coldValveClosed = false;
waitingCycles = true;
counterForHotWater = 1;
}
}
}


//Update current temperature
statuses.currentTemp = (int)sensors.getTempCByIndex(0);

Expand Down
Binary file added Arduino/libraries/SimpleTimer.zip
Binary file not shown.
Loading

0 comments on commit 83d7114

Please sign in to comment.