Jerry Zhang
Created July 2, 2019 © CC BY

Water Leakage Monitor

Particle Mesh-powered water leakage monitor for an entire building or entire community that can be used in a mesh network.

IntermediateFull instructions provided4 hours37
Water Leakage Monitor

Things used in this project

Hardware components

Argon
Particle Argon
×1
Xenon
Particle Xenon
×1
Boron
Particle Boron
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×1
Aluminum Foil
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Diagram of the Water Leak Sensor

The two green wires connect to pieces of aluminum foil placed near each other but not touching. Once water connects the circuit, the switch closes.

Code

Standalone Device Code

Arduino
int sensor = D6; // Plug the sensor into pin D6 on the Particle device
int led = D7; // Pin D7 can be connected to an LED indicating status (optional)

bool leak = false; // make sure that the leak status is only changed once. a reset is required to change it back.
bool setupDone = false; // make sure that the status isn't published until setup() has been run

void setup() {
	pinMode(sensor,INPUT); // sets sensor pin to an input pin
	pinMode(led, OUTPUT); // sets led pin to an output pin
	digitalWrite(led, LOW); // sets the LED to off
	Particle.publish("status", "OK", 60, PRIVATE); // starts the status as OK
	setupDone = true; // indicate that setup has completed
}

void loop() {
	if (setupDone && digitalRead(sensor) && !leak) { // if the sensor returns true, setup has completed, and a leak hasn't already been detected, update status
		Particle.publish("status", "LEAK", 60, PRIVATE); // changes status to LEAK from OK
		leak = true; // sets variable of leak to true
		digitalWrite(led, HIGH); // turns led on
  } else if (setupDone && digitalRead(sensor)) { // for testing purposes: runs anytime the sensor returns true, even if a leak has already been detected.
      Particle.publish("test", "LEAK", 60, PRIVATE); // posts "LEAK" to "test"
  }

}

Mesh Network Code

Arduino
int sensor = D6; // Plug the sensor into pin D6 on the Particle device
int led = D7; // Pin D7 can be connected to an LED indicating status (optional)

bool leak = false; // make sure that the leak status is only changed once. a reset is required to change it back.
bool setupDone = false; // make sure that the status isn't published until setup() has been run

void setup() {
	pinMode(sensor,INPUT); // sets sensor pin to an input pin
	pinMode(led, OUTPUT); // sets led pin to an output pin
	digitalWrite(led, LOW); // sets the LED to off
	Mesh.publish("status", "OK", 60, PRIVATE); // starts the status as OK
	setupDone = true; // indicate that setup has completed
}

void loop() {
	if (setupDone && digitalRead(sensor) && !leak) { // if the sensor returns true, setup has completed, and a leak hasn't already been detected, update status
		Mesh.publish("status", "LEAK", 60, PRIVATE); // changes status to LEAK from OK
		leak = true; // sets variable of leak to true
		digitalWrite(led, HIGH); // turns led on
  } else if (setupDone && digitalRead(sensor)) { // for testing purposes: runs anytime the sensor returns true, even if a leak has already been detected.
      Mesh.publish("test", "LEAK", 60, PRIVATE); // posts "LEAK" to "test"
  }

}

Credits

Jerry Zhang

Jerry Zhang

11 projects • 15 followers

Comments