Skip to content

Instantly share code, notes, and snippets.

@ilmaestro
Created October 12, 2014 23:06
Show Gist options
  • Save ilmaestro/65e4b227acfa7a23f1e7 to your computer and use it in GitHub Desktop.
Save ilmaestro/65e4b227acfa7a23f1e7 to your computer and use it in GitHub Desktop.
Arduino Shower Controller
/*
Shower Contoller
8/9/2010 - Ryan Kilkenny
features:
-relays to control two valves and a pump (main & recirculation)
* digital pins 13,12,11
-thermistor to detect temp of hot water pipe
-hall effect sensor to detect when soap is in use
Vers. 1 - when turned on, arduino will:
1. check temp of hot water pipe
2. if too cold, will open recirculation valve and turn on pump
- continue to check temp until temp rises to cutoff setting
- turn off pump, close recirc valve
3. turn on main valve
*/
#include <math.h>
#define MAINVALVE_PIN 10
#define RECIRCVALVE_PIN 12
#define PUMP_PIN 11
#define THERM_PIN 0
//global vars
double temperatureCutoff = 91.0;
boolean showerOn = false;
boolean testMode = false;
void setup()
{
// initialize the digital pins as an output:
pinMode(MAINVALVE_PIN, OUTPUT);
pinMode(RECIRCVALVE_PIN, OUTPUT);
pinMode(PUMP_PIN, OUTPUT);
Serial.begin(115200);
SetRelay(MAINVALVE_PIN, false);
SetRelay(RECIRCVALVE_PIN, false);
SetRelay(PUMP_PIN, false);
}
void loop()
{
if(testMode)
{
SetRelay(MAINVALVE_PIN, false);
SetRelay(RECIRCVALVE_PIN, false);
SetRelay(PUMP_PIN, false);
delay(3000);
//readThermistor();
/*
delay(2000);
SetRelay(MAINVALVE_PIN, true);
delay(3000);
SetRelay(RECIRCVALVE_PIN, true);
delay(3000);
*/
SetRelay(PUMP_PIN, true);
delay(3000);
}
else
{
if(!showerOn)
{
SetRelay(MAINVALVE_PIN, false);
SetRelay(RECIRCVALVE_PIN, false);
SetRelay(PUMP_PIN, false);
delay(3000);
Recirculate();
Shower();
}
}
}
/*functions*/
double Thermister(int RawADC) {
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
Temp = Temp - 273.15; // Convert Kelvin to Celcius
Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
return Temp;
}
void SetRelay(int pin, boolean on)
{
if(on)
{
digitalWrite(pin, HIGH); // set the LED on
} else {
digitalWrite(pin, LOW);
}
}
/*events*/
void Recirculate()
{
Serial.println("Recirculating...");
SetRelay(MAINVALVE_PIN, false);
SetRelay(RECIRCVALVE_PIN, true);
Serial.println("Recirculation valve: on");
delay(1000);
SetRelay(PUMP_PIN, true);
Serial.println("Recirculation pump: on");
double currentTemp = Thermister(analogRead(THERM_PIN));
while (currentTemp <= temperatureCutoff)
{
delay(3000);
currentTemp = Thermister(analogRead(THERM_PIN));
Serial.println(int(currentTemp));
}
SetRelay(PUMP_PIN, false);
Serial.println("Recirculation pump: off");
delay(3000);
SetRelay(RECIRCVALVE_PIN, false);
Serial.println("Recirculation valve: off");
delay(3000);
}
void Shower()
{
Serial.println("Starting Shower...");
delay(1000);
SetRelay(MAINVALVE_PIN, true);
SetRelay(RECIRCVALVE_PIN, false);
SetRelay(PUMP_PIN, false);
delay(1000);
showerOn = true;
Serial.println("Shower valve: on");
}
/*Tests*/
void readThermistor()
{
double currentTemp = Thermister(analogRead(THERM_PIN));
Serial.println(int(currentTemp));
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment