I will be using a couple of Particle Electrons, and a Raspberry Pi 3 as my base electronics. I will add a basic BOM (Bill of Materials). I am also designing a DIY open source security system into the challenge as well as a simple heating control sketch.
With this system, you will be able to go on holidays and rest easy that your home is safe and secure (with no leaks).
The Board DesignFor the Main Control Board that sits in the control cabinet, I have included a Gerber file for the enthusiast that doesn’t want to go through the hassle of doing a total design work up.
I have three relays designed into the board.
One can be used for an alarm bell.
One can be used for turning on and off the solenoid.
One can be used for turning the heat or AC on and off.
The Raspberry Pi can be soldered into place in the spots provided to get power from the board.
// This #include statement was automatically added by the Particle IDE.
//#include <Adafruit_DHT_Particle.h>
// This #include statement was automatically added by the Particle IDE.
//#include <Adafruit_DHT.h>
#include <OneWire.h>
#include "DS18.h"
#define DHTTYPE DHT11 // Sensor type DHT11/21/22/AM2301/AM2302
#define DHTPIN D0 // Digital pin for communications
DHT dht(DHTPIN, DHTTYPE);
DS18 sensor(D1);
DS18 sensor1(D2);
//DS18 sensor2(D3);
int n; // counter
int RelayPin1 = D6; //Relay 1(Underside Heat On)
int RelayPin2 = D5; //Relay 2(Alarm Bell)
int RelayPin3 = D7; //Relay 3(Heat On)
int digitalin5 = A0; //Office Thermostat
int digitalin1 = A1; //Office Motion
int digitalin2 = A2; //Bed Motion ....OK
int digitalin4 = A3; //Living Motion.....OK
int digitalin3 = A4; //Kitchen Motion
int Smoke = D3; //Smoke Detector
int sensorValue = 0;
int buttonstate = LOW;
void setup() {
Serial.begin(9600);
dht.begin();
digitalWrite(RelayPin1,LOW);
digitalWrite(RelayPin2,LOW);
digitalWrite(RelayPin3,LOW);
pinMode(RelayPin1, OUTPUT); //Alarm relay
pinMode(RelayPin2, OUTPUT); //Heating relay
pinMode(RelayPin3, OUTPUT); //Water Shut off relay
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A4, INPUT);
pinMode(A3, INPUT);
pinMode(A0, INPUT);
pinMode(D3, INPUT);
pinMode(Smoke, INPUT);
Particle.function("Heating", HeatOn);
Particle.function("Heating1", HeatOn1);
Particle.function("Alarm", AlarmOn);
}
void loop() {
char message[56];
float h = dht.getHumidity();
float t = dht.getTempCelcius();
float f = dht.getTempFarenheit();
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
Particle.publish("Failed to read from DHT sensor!","0",PRIVATE);
return;
}
float hi = dht.getHeatIndex();
float dp = dht.getDewPoint();
float k = dht.getTempKelvin();
Serial.print("Humid: ");
Serial.print(h);
Serial.print("% - ");
Serial.print("Temp: ");
Serial.print(t);
Serial.print("*C ");
sensorValue =(t);
sprintf(message, "%d",sensorValue);
Particle.publish("Bath_Temp", message, PRIVATE);
sensorValue =(h);
sprintf(message, "%d",sensorValue);
Particle.publish("Bath_Hum", message, PRIVATE);
delay(10000);
sensorValue = digitalRead(A1);//Office Motion
if (sensorValue == LOW) {
Particle.publish("OffMot","0",PRIVATE);
Particle.publish("OfficeMotion","0",PRIVATE);
}
else if (sensorValue == HIGH) {
// Particle.publish("OfficeMotion","1",PRIVATE);
}
sensorValue = digitalRead(A2); //Bed Motion
if (sensorValue == LOW) {
Particle.publish("BedMot","0",PRIVATE);
Particle.publish("BedMotion","0",PRIVATE);
}
else if (sensorValue == HIGH) {
// Particle.publish("BedMotion","1",PRIVATE);
}
sensorValue = digitalRead(A3); //Living Motion
if (sensorValue == LOW) {
Particle.publish("LivingMot","0",PRIVATE);
Particle.publish("LivingMotion","0",PRIVATE);
}
else if (sensorValue == HIGH) {
// Particle.publish("LivingMotion","1",PRIVATE);
}
sensorValue = digitalRead(A4); //Kitchen Motion
if (sensorValue == LOW) {
Particle.publish("KitMot","0",PRIVATE);
Particle.publish("KitchenMot","0",PRIVATE);
digitalWrite(D5,HIGH);
}
else if (sensorValue == HIGH) {
// Particle.publish("KitchenMot","1",PRIVATE);
}
delay(100);
n++;
//}
if (sensor.read()) {
// Do something cool with the temperature
Serial.printf("Temperature %.2f C %.2f F ", sensor.celsius(), sensor.fahrenheit());
Particle.publish("Bed_Temp", String(sensor.celsius()), PRIVATE);
}
else {
if (sensor.searchDone()) {
}
}
}
int HeatOn(String command) {
if(command =="1") {
digitalWrite(D7,HIGH);
Particle.publish("Base_Heat_On","1",PRIVATE);
}
if(command =="0") {
digitalWrite(D7,LOW);
Particle.publish("Base_Heat_Off","0",PRIVATE);
}
return 1 ;
}
int HeatOn1(String command) {
if(command =="1") {
digitalWrite(D6,HIGH);
Particle.publish("Under_Heat_On","1",PRIVATE);
}
if(command =="0") {
digitalWrite(D6,LOW);
Particle.publish("Under_Heat_OFF","0",PRIVATE);
}
return 1 ;
}
int AlarmOn(String command) {
if(command =="1") {
digitalWrite(D5,HIGH);
Particle.publish("Alarm_On","1",PRIVATE);
}
if(command =="0") {
digitalWrite(D5,LOW);
Particle.publish("Alarm_OFF","0",PRIVATE);
}
return 1 ;
}
Soldering the Board
Work your way from the inside to the outside of the board. Briefly touching the pins to be soldered. Don't linger too long as you may melt the pieces above you on the other side of the board. You just want to wait long enough for the solder to liquefy that you are touching to the iron and the piece pat the same time. If you are not sure what you are doing practice on a blank board with some cheap resistors until your comfortable.
The remote Water Flow Meter Board that sits on your main intake pipe after the Flow meter and shutoff.I have included a gerber file for this Board as well.It requires power to operate. either a battery setup can be included in it or regular power from the USB.. I will be using the USB power block as it's easier to design into the Board and Junction Box.
The remote Water Leak Board sits on the floor of your water closet or mechanical room or even in the bathroom where you might have a leaky toilet. A Gerber file is attached for this one as well.
The Sensor Board is for the piezo sensor and any other sensors you want to implement including motion detection.
int Smoke = D1; //Smoke Detector
int sensorValue = 0;
int buttonstate = LOW;
void setup() {
Serial.begin(9600);
pinMode(D1, INPUT);
}
void loop() {
char message[56];
sensorValue = digitalRead(D1); //Smoke Detector
if (sensorValue == LOW) {
Particle.publish("Smoke","0",PRIVATE);
}
else if (sensorValue == HIGH) {
Particle.publish("Smoke","1",PRIVATE);
}
delay(10000);
}
The remote Relay Board mounts near the solenoid to shut off your water or mechanical room, or even in the bathroom where you might have a leaky toilet. A Gerber file is attached for this one as well.
You might have noticed the sensor boards are all exactly the same in size .I did that on purpose so as to only have 1 box type for all sensors
#include <OneWire.h>
#include "DS18.h"
const int MOTION_TIMEOUT = 5000UL; // 5 seconds of led everytime motion is detected, outside of the debounce time
const int ledPin = D7;
const int relaypin = D2;
const int relaypin1 = D3;
const int MOTION_TIMEOUT1 = 5000UL;
DS18 sensor(D0);
unsigned long oldTime;
volatile unsigned int WaterPulseCount = 0;
volatile unsigned int WaterPulseCount1 = 0;
// conversion from pps to litres, plastic sensor (485 for metal)
const float pulsesPerLiter = 485;
const float pulsesPerLiter1 = 485;
#define WATER_SENSOR_PIN A1
#define WATER_SENSOR_PIN1 D2// Water sensor digital pin
float input_voltage = 0.0;
double VRaw; //This will store our raw ADC data
float Vib =0;
float VibS =0;
float liters = 0;
char liters_S[6];
float Vib1 =0;
float VibS1 =0;
float liters1 = 0;
char liters_S1[6];
char freq[6];
int PezioPulseCount=0;
int PezioPulseCount1=0;
void WaterPulseCounter(void)
{
WaterPulseCount++;
}
void PezioPulseCounter(void)
{
PezioPulseCount++;
}
//
void WaterPulseCounter1(void)
{
WaterPulseCount1++;
}
void PezioPulseCounter1(void)
{
PezioPulseCount1++;
}
//
void setup()
{
Serial.begin(9600);
Particle.variable("Vib", freq, STRING);
Particle.variable("litersS", liters_S1, STRING);
Particle.variable("Vib1", freq, STRING);
Particle.variable("litersS1", liters_S1, STRING);
Particle.variable("VRaw", &VRaw, DOUBLE);
//
pinMode(WATER_SENSOR_PIN1, INPUT);
attachInterrupt(WATER_SENSOR_PIN1, WaterPulseCounter1, FALLING) ;
oldTime = millis();
//
pinMode(relaypin, OUTPUT);
pinMode(relaypin1, OUTPUT);
pinMode(WATER_SENSOR_PIN, INPUT);
attachInterrupt(WATER_SENSOR_PIN, WaterPulseCounter, FALLING) ;
oldTime = millis();
digitalWrite (relaypin,HIGH);
//analogWrite (vibrationSensor,LOW);
}
void loop() {
char message[120];
String data = String (20);
digitalWrite (relaypin,HIGH);
digitalWrite (relaypin1,HIGH);
if (sensor.read()) {
Serial.printf("Temperature %.2f C %.2f F ", sensor.celsius(), sensor.fahrenheit());
Particle.publish("Underside_Temperature", String(sensor.celsius()), PRIVATE);//You can adjust ("Temperature") to say what you want
delay(2500);
}
else {
if (sensor.searchDone()) {
Serial.println("No more addresses.");
} else {
}
}
unsigned long t;
static unsigned int pc;
t = (millis() - oldTime);
if(t >= 1000)
{
//Read water sensor pulse count and process
if (WaterPulseCount != 0) // Do nothing if water is not flowing!
{
detachInterrupt (WATER_SENSOR_PIN); // Disable water flow interrupt to read value
//Calculate litres and adjust for 1 sec offset, if any
liters = (WaterPulseCount / pulsesPerLiter) * (t / 100);
oldTime = millis(); // Reset base delay time
pc = WaterPulseCount;
WaterPulseCount = 0; // Reset the water pulse counter
attachInterrupt(WATER_SENSOR_PIN, WaterPulseCounter, FALLING);
sprintf(liters_S, "%4.3f", liters);
Particle.publish("Vibration_Level",liters_S,60,PRIVATE);
}
}
/*
// ************Water meter****************
t = (millis() - oldTime);
if(t >= 1000)
{
//Read water sensor pulse count and process
if (WaterPulseCount1 != 0) // Do nothing if water is not flowing!
{
detachInterrupt (WATER_SENSOR_PIN1); // Disable water flow interrupt to read value
//Calculate litres and adjust for 1 sec offset, if any
liters = (WaterPulseCount1 / pulsesPerLiter) * (t / 100);
oldTime = millis(); // Reset base delay time
pc = WaterPulseCount1;
WaterPulseCount1 = 0; // Reset the water pulse counter
attachInterrupt(WATER_SENSOR_PIN1, WaterPulseCounter1, FALLING);
sprintf(liters_S1, "%4.3f", liters1);
Particle.publish("WaterFlow",liters_S,60,PRIVATE);
}
}
*/ //
}
So now after you've ordered all your Parts and they Have come in.Lets have a look at them
Comments