In this tutorial, we show how to make a water leakage detector that is powered by pcDuino. When water is detected, pcDuino will send out email to the target email.
To detect water, we use the moisture sensor from DFRobot. There are three pins of moisture sensor, GND, VCC, and S. S is connected to A2 of pcDuino, and GND of the sensor is connected to GND of pcDuino, while VCC of sensor is connected to 5V of pcDuino.
Now, lets look at code part.
1. Download Python library:
1
|
|
2. After that, we will see the library files under pcduino. Create a directory named ‘waterdetect’ under directory ‘Samples’, the following is the code:
01
02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#!/usr/bin/python
|
The following is the project file:
waterdetect.tar
We will set up to run python script as daemon at boot time.
To do this, you must create this file and save it in /etc/init.d/. The file name we choose is ‘waterdetect’:
01
02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
#!/bin/sh -e
|
Do not forget to give execution rights to your python server and to the service script :
1
2 |
$ sudo chmod 755 /etc/init.d/waterdetect
|
You can start or stop it using:
1
2 3 4 5 6 |
$ sudo service waterdetect start
|
and define it as a startup service using:
1
|
$ sudo update-rc.d waterdetect defaults
|
We install the detector at the washer machine:
When there are water spill, we got the email:


