I recently got to know a person from Fredericton, New Brunswick, Canada. Just this past year, there was a record breaking flood there, and when I asked her about it, she gave me an eye-opening account about how it has affected her life. As global warming continues to progress, flooding has gone from a rare occurrence to a commonplace issue in New Brunswick. This past May, the water level rose around 5.8 meters, which was never seen since 1973. Citizens were stranded, public services were cancelled, and many had to relocate for weeks.
What struck me was the fact that a huge number of people were negatively impacted even if their home was still partially flood-free. Out of fear of electrocution, the city shuts off power to grids at a time, blacking out whole areas. Given the fact that it takes weeks for a flood to subside, many families are forced to move out as their phones die out or when their food turns bad, even if most of their home is still inhabitable.
To tackle this issue, this proof of concept system uses water sensors to check for flooding at each level of the house, and only shuts off power to the flooded level. This allows families with a secondary power supply to safely access their homes' built-in electrical grid and maintain a decent quality of life during a flood. Moreover, the control unit uses is connected to the internet so that in case of flooding, the homeowner can be notified immediately. This system is made with the assumption that the homeowner is willing to waterproof their circuit breaker and rewire the home so that there aren't any multi-floor sections of wiring.
Flooding is detected by a water level sensor placed at a level below the wall socket. A constant voltage is applied, and as water touches the sensor, it shorts the cathodes, creating a current and outputting HIGH on the signal pin. The sensor is connected to a NodeMCU ESP8266, which registers the voltage and shuts off the power to the floor by applying a HIGH voltage to the corresponding relay module. It also sends a POST request to a PHP server, updating the status of the sensors. This data is accessed by a landing page, giving the user on the clock information about the state of their home. My live demo can be checked out at www.hydrosafe.tk, before it expires 23/07/2019.
0. Preparing the Enclosure (Optional)I didn't want HydroSafe to look like a dying octopus, so I made a basic enclosure for all the parts to be housed in. Take a reasonable box and cut a hole big enough for the extension cord to fit through.
Here, the project is made with 3 floors in mind. As such, 3 holes were cut on the front side to fit the water sensors and 3 holes on the lid for. If the box isn't tall enough for cups to fit snugly under the water sensors, give it some encouragement and prop it up with a Popsicle stick frame.
If using an enclosure, thread all the cables and wires through before connecting them. At about 15cm from the plug, split the extension cable in two, cut one side in half, and strip the cut ends. Screw them into the common and normally open pins of the relay module.
If your module does not have a built-in rectifier diode for protection, add your own between the relay and ESP8266, by connecting a diode facing the relay between the ESP's 5V pin and the relay's VCC pin. Repeat this for the number of independent circuits you want, which in this case is 3. Connect the sensors and relay modules as shown in the schematic.
Note: the sensors are cheap and erode quickly, but it isn't a problem due to the fact that flooding should happen relatively rarely.
To store the data collected into a server, and access the state of the sensors live on a webpage, you will need to get a domain and a server. In this project, I decided to get a free domain off freenom. Keep in mind that the free plan lasts only a year, so the domain will expire if you don't renew it. Here I registered the domain name hydrosafe.tk.
Now to host the domain and get database functionality, you have to find a host. I used 000webhost as it gives me free hosting along with a free database of up to 1GB. It uses FTP to transfer files to the server, which something I am familiar with. You can also use hosts like Heroku or AWS, but for this tutorial will cover how to set up hosting on 000webhost.
To host your domain on your server, you need to point it to the server. Navigate to the nameserver section of your domain registrar control panel and enter the nameservers of your host. For 000webhost, the nameservers are NS01.000WEBHOST.COM and NS02.000WEBHOST.COM. On freenom, do this by logging in with the account used to register the domain, and going to Services > My Domains and clicking on the Manage Domain button, then navigating to Management Tools > Nameservers. Then click the Use Custom Nameservers radio button and enter the nameservers. Click the Change Nameservers button at the bottom of the page.
Now that your domain is pointing to your server, you need to park the domain to your server on the server control panel. This allows the server to redirect your custom domain name to its default domain, which in my case is shadproject.000webhostapp.com. Create a free account on 000webhost and create a new project and name it whatever you like. Remember the username and password, as it'll be used step 4. Click the red Manage Website button, then click the Set Web Address button at the top. At the bottom, click Add Domain > Park Domain. Enter your custom domain address. Finally click Manage > Link Website and choose your default domain.
Congrats! After a few hours (24-48 max) the domain should be linked to your server.
3. Setting Up a DatabaseTo store the data that the ESP is sending to the server, you must create a database to save and organize the data. On 000webhost, click Manage Databases at the top, then click the New Database button. Name it, set a user and password, and create it. Remember the logins for step 4. Then click Manage > PhpMyAdmin.
Click on the top database that you just named, then click New. This creates a new table where the data shall be stored. Name it data and set # of columns to 4. You can change this for more sensors if you'd like. Name the columns and set the types as shown below.
The number in the parenthesis is the value to enter in the Length/Values field. Leave everything after the Length/Values field as default. Click Save, and your table has been created!
4. Creating a Data Collector and Landing PageCopy the index.php file and dataCollector.php file as linked below. Follow the instructions to change the variables.
Download FileZilla or use any FTP client app you'd like, and connect to the server. This tutorial will cover the use of FileZilla. Open the app and click File > Site Manager. Click New Site and name it however you'd like.
Fill in the fields as shown above, and enter your webpage username and password that you've set in step 2. Click Connect.
Navigate to the public_h folder on the server (right side) and navigate to the folder containing your changed dataCollector.php and index.php files on your computer's navigator (left side). Add both files to the server by double clicking them.
Now that we have the server side set up, we can work on the client, which is the ESP module. First, we need to install the ESP8266 add-on with the Arduino boards manager. To do this, open up the Arduino IDE, go to File>Preferences, and paste the link below in the "Additional Board Manager URLs" text box:
http://arduino.esp8266.com/stable/package_esp8266com_index.json
Hit OK, and go to Tools > Boards > BoardsManager. Type esp8266 in the search field, click on the entry, and install it. Now, you can select the NodeMCU 1.0 board by going to the Tools > Boards menu.
Copy the Arduino code attached below and follow the instructions on the description. Customize the code for the number of water sensors and relays. In this basic tutorial, there is no security or credential setup for posting to the datacollector.php page. Connect the ESP to your computer via the micro-USB cable, and upload the code. Make sure you selected the port the board is connected to (in Tools > Port).
After uploading the code, the ESP should regularly monitor the water sensors and post the data to the server if there is a change in the status of the sensors. You can now plug the USB to a power supply (eg charger or bank) and the system should work autonomously. Now, you can plug your devices to any of the protruding extension cords, and plug your main cord into a wall socket (double check your wiring before doing so as you are messing with 120V ac).
Congrats! You have replicated a smart flooding power management system. You can use the extension cords as a normal source of power to emulate the home's outlets, and view the status of the sensors on your domain.
Though this proof of concept does carry out the key features of the HydroSafe solution, it needs to be improved in many ways to make it commercially viable. The main box as well as the circuit breaker would need waterproofing, and the sensor modules would need be be installed in their respective locations in the house. The relays would also need to be much higher duty to handle the greater current of controlling the home's existing grid, and the circuit breaker would need to take 3 or more inputs instead of the single utility line that it was designed to handle. Moreover, it is recognized that extensive rewiring of the home will also have to be done if the electrical system isn't separated by floors. High barriers to entry and legal challenges with hydro companies will have to be faced if this is truly to be implemented.
Future StepsIn the future, the sensor aspect of the system can also be combined with the capability of remotely controlling the breaker box, allowing for greater use of this product on a day to day basis. Also, if modules are installed in many homes, the data collection could be crowdsourced to allow local municipalities to actively track a flood's impact on the community, thus increasing the efficiency of first responders.
Ultimately, though the complexity grows and feasibility decreases as this solution is utilized in the real world, I hope that HydroSafe can be of some use to those who are trying to improve communities' resilience in the face of natural disasters.
Comments