Reader small image

You're reading from  Raspberry Pi Home Automation with Arduino - Second Edition

Product typeBook
Published inFeb 2015
Publisher
ISBN-139781784399207
Edition1st Edition
Right arrow
Author (1)
Andrew K. Dennis
Andrew K. Dennis
author image
Andrew K. Dennis

Andrew K. Dennis is a full stack and cybersecurity architect with over 17 years' experience who currently works for Modus Create in Reston, VA. He holds two undergraduate degrees in software engineering and creative computing and a master's degree in information security. Andy has worked in the US, Canada, and the UK in software engineering, e-learning, data science, and cybersecurity across his career, and has written four books on IoT, the Raspberry Pi, and supercomputing. His interests range from the application of pataphysics in computing to security threat modeling. Andy lives in New England and is an organizer of Security BSides CT.
Read more about Andrew K. Dennis

Right arrow

Chapter 7. Water/Damp Detection – Check for Damp/Flooding in Sheds and Basements

In the previous chapter, you learned how to control blinds and curtains. In this chapter, we will be building a damp detection device. This will bring together some of the ideas from other chapters and teach you the next steps used to expand the system.

The purpose of the damp detection device is to alert you when an area becomes damp or is at risk of flooding. A common method of checking for signs of flooding and dampness is to run a damp heat test. This involves checking a combination of temperature and humidity to see whether an area is susceptible to dampness, for example, if some insulation has become wet.

For this project we will use:

  • The Raspberry Pi

  • The Raspberry Pi to Arduino bridge shield

  • An Ethernet shield

  • An LED

  • An Arduino Uno

  • The AM2302 sensor

  • The Seeed Grove water sensor

A brief note on dampness


Dampness in basements and sheds can lead to long-term damage, cause mold to grow, and also be an indication of flooding.

Note

The US CDC website at http://www.cdc.gov/mold/dampness_facts.htm recommends that humidity levels should be kept at about 50 percent in order to prevent molds from growing.

Therefore, it stands to reason that a high humidity level in a basement may be a sign of a problem. Thus, checking humidity levels will be a major factor in our damp and flooding detection device.

Let's get started with building the damp detection system.

Damp detection system


In this project, we will build a thermometer and a humidity sensor using an Arduino Uno and the AM230. This device will write the recorded data to the Raspberry Pi and store it in our control database.

Once we have this system up and running, we will look at some ideas on how we can expand the damp detection system to use the Cooking Hacks shield.

Let's start with building the Arduino circuit.

Arduino circuit

Our damp detection system is scalable, so we can build multiple damp detection units, and place them in separate locations such as the shed and the basement.

The Arduino thermometer/humidity circuit is the same as what we built for the thermostat. The following diagram illustrates it:

Building the circuit is simple, and you should be familiar with it by now. Attach your Ethernet shield to the Uno and then simply hook up the AM2302 to digital pin 4, the 5V pin, and the GRD pin. This completes the device's setup.

Now that we have built the circuit, let's write the Arduino...

Database updates


On your Raspberry Pi, use the following command to connect to the SQLite3 database that you created in Chapter 4, Temperature Storage – Setting Up a Database to Store Your Results:

sqlite3 control.db

We are now going to add a humidity column. Run the following SQL statement:

ALTER TABLE Temperature ADD COLUMN Humidity FLOAT(8);

This code modifies the temperature table and adds a humidity column. The column is set to accept values in float format. Next, we need to add the basement/shed to our room table:

INSERT INTO RoomDetails (Room) VALUES ('Basement');

Note

Remember to update the Arduino sketch with the ID of the room you insert.

Now we have a place to store the humidity data. Next, we need to create a new version of the request.py code from Chapter 4, Temperature Storage – Setting Up a Database to Store Your Results, to write the value to the database.

Python code


The following Python code is a modified version of the request.py code that we used previously.

Create a new file, damp.py, in a text editor of your choice and add the following code. Remember to change the IP address given here to that of your Arduino:

#!/usr/bin/env python
import sqlite3
import urllib2
import json

def main():
    req = urllib2.Request('http://192.168.3.6/')
    req.add_header('Content-Type', 'application/json;charset=utf-8')
    r = urllib2.urlopen(req)
    result = json.load(r)
    room = result['thermostat'][0]['location']
    temperature = result['thermostat'][1]['temperature']
    humidity = result['thermostat'][1]['humidity']
    my_query = 'INSERT INTO temperature(roomid,temperaturec,datetime, humidity) \
                VALUES(%s,%s,CURRENT_TIMESTAMP);' %(room,temperature, humidity)

Here, we can see that we are storing the humidity value returned in the json object in a variable called humidity.

Next, we insert this value into the query that writes the...

Using the humidity reading


We now have a system that reads the humidity of the room in which the Arduino is located. Based on the temperature and humidity data, we can get to know whether the room is damp or there is a chance of flooding.

It would also be useful though, if the Raspberry Pi could alert us in some manner that the room is experiencing high humidity. Perhaps, we could use this data to turn on a dehumidifier.

Adding an LED alert

We are going to start by attaching the Cooking Hacks shield to the Raspberry Pi. Once this is connected, we will attach an LED to the shield's digital pin 2. The following diagram illustrates the setup:

Connect the long pin of the LED to digital pin 2 on the Arduino bridge shield. You can use a breadboard and two wires in order to complete this setup. Next, attach the other leg of the LED to the GRD pin on the bridge shield.

Once you have the LED attached, you can consider writing an application to switch it on and off.

Blinking LED code

The following application...

Water detection


Of course, testing for humidity might not alert us to a major leak problem. During a severe rainstorm, the basement could be flooded quickly if it relies on a sump pump and that breaks down.

One device we could use with an Arduino or attach to the Raspberry Pi via the bridge shield is a water sensor.

Seeed Studios offer such a device (http://www.seeedstudio.com/depot/Grove-Water-Sensor-p-748.html) that can be connected to either the analog or digital pins on your microcontroller.

With this device hooked up, the following example sketch can be run to check whether device is working correctly.

Note

The example sketch is available on GitHub, at https://github.com/Seeed-Studio/Grove_Water_Sensor.

Integrating this module with your existing damp detection circuit is simple. Attach the device to one of the digital pins on your Uno. Next, add the following code to your damp detection device sketch:

boolean waterDetected() {
  if(digitalRead(WATER_SENSOR) == LOW) {
     return true;
 } else...

Summary


In this chapter, we explored a number of ways to detect damp and flooding. You were introduced to using the humidity functionality of the AM2302. Using this information, we wrote the humidity values to the database we created in Chapter 4, Temperature Storage – Setting Up a Database to Store Your Results.

Next, we used the Cooking Hacks shield to turn an LED on and off. Following this, we examined how we could use the LED to alert us about a dampness problem by checking the values stored in the database once an hour.

After building this system, we considered reusing the relay functionality from Chapter 3, Central Air and Heating Thermostat. This would then allow us to switch a dehumidifier on and off as needed.

Following this, we looked at a method of testing for water. This involved using a water sensor and modifying our code to send the concerned data back from the Arduino. Finally, we discussed a number of ways we could create an alert system to notify us that flooding could be taking...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Raspberry Pi Home Automation with Arduino - Second Edition
Published in: Feb 2015Publisher: ISBN-13: 9781784399207
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Andrew K. Dennis

Andrew K. Dennis is a full stack and cybersecurity architect with over 17 years' experience who currently works for Modus Create in Reston, VA. He holds two undergraduate degrees in software engineering and creative computing and a master's degree in information security. Andy has worked in the US, Canada, and the UK in software engineering, e-learning, data science, and cybersecurity across his career, and has written four books on IoT, the Raspberry Pi, and supercomputing. His interests range from the application of pataphysics in computing to security threat modeling. Andy lives in New England and is an organizer of Security BSides CT.
Read more about Andrew K. Dennis