Benjamin Winiarski
Published © GPL3+

Particle Water Leak Detection System

Water leaks are costly, with flooding causing extensive damage to your home. With this Particle network, get notified when any leaks arises.

EasyFull instructions provided2 hours395
Particle Water Leak Detection System

Things used in this project

Hardware components

Photon
Particle Photon
×1
Water Sensor
×1

Software apps and online services

Particle Web IDE
PushBullet

Story

Read more

Schematics

Connection Diagram

Connect the water sensor to GND and D0
Screen shot 2018 06 30 at 3 57 22 pm cdgkwfbxq4

Code

Particle Firmware Code

C/C++
#include "elapsedMillis/elapsedMillis.h"

String _version = "0.04";

//this checks the flood sensor every 5 seconds
#define FLOOD_READ_INTERVAL 5000

//time from water contact to send notification to the user
#define FLOOD_FIRST_ALARM 15000 //15 seconds


#define FLOOD_NOTIF "FLOOD"

elapsedMillis flood_timer;
elapsedMillis flood_alarm_timer;

int flood_alarm = FLOOD_FIRST_ALARM
int flood_alarm_index = 0;
bool flood_detected = false;
unsigned long flood_next_alarm = 0;

int FLOOD_SENSOR = D0;
int LED = D7;

void setup() {
 pinMode(FLOOD_SENSOR, INPUT_PULLUP);
 pinMode(LED, OUTPUT);
 Spark.publish("device starting", "Firmware version: " + _version, 60, PRIVATE);
}

void loop() {

    flood_check();
    
    if ( flood_detected ) {
        flood_notify_user();
    }
}

// Function to dectect water leak
int flood_check()
{
    if (flood_timer < FLOOD_READ_INTERVAL) {
        return 0;
    }
    
    //the time is up, so reset timer
    flood_timer = 0;

    if (not digitalRead(FLOOD_SENSOR)) {
        
        //if the flood has already detected, there is no need to do anything
        if (flood_detected){
            return 0;
        }
        
        flood_detected = true;
    
        //reset the alarm timer
        flood_alarm_timer = 0;
        
        digitalWrite(LED,HIGH);
    } else {
        
        digitalWrite(LED,LOW);
        flood_detected = false;
    }
    return 0;
}

// Function to notify user of water leak
int flood_notify_user()
{

    if (flood_alarm_timer < flood_next_alarm) {
        return 0;
    }

    
    //the time is up, so reset timer
    flood_alarm_timer = 0;

    //send a notification to user (this one goes to the dashboard)
    Spark.publish(FLOOD_NOTIF, "Water Leak detected!", 60, PRIVATE);

    //send a notification to user (this one goes to pushbullet servers)
    Spark.publish("pushbullet", "Water Leak detected!", 60, PRIVATE);
   
   return 0; 
}

Webhook for Pushbullet

JSON
{
  "eventName": "pushbullet",
  "url": "https://api.pushbullet.com/v2/pushes",
  "requestType": "POST",
  "headers": {
    "Authorization": "Bearer 00000000000000000000000000000",
    "Content-Type": "application/json"
  },
  "json": {
      "type": "note",
      "title": "{{SPARK_EVENT_VALUE}}",
      "body": ""
  },
  "mydevices": true
}

Credits

Benjamin Winiarski

Benjamin Winiarski

2 projects • 0 followers
Aspiring Entrepreneur and IOT Developer
Contact

Comments

Add projectSign up / Login