Introduction: Basement Flood Alarm - Arduino

After my basement turned into a swimming pool, I thought it time to use my shiny new Arduino skills!

This tutorial covers sensor selection, installation, wiring, and programming choices. These are specific to my house, but at least some of the points covered will be usable by others.

Step 1: Equipment

  • Arduino (I used an Uno)
  • AC power supply

Indicators

  • Piezo buzzer, magnetic speaker, or other audible device
  • Indicator LEDs, if desired
  • Current-limiting resistors for LEDs, if used (I selected 220 Ohm)

Sensors

  • Float switch
  • 10 KOhm current-limiting resistor for float switch
  • Resistive moisture ("raindrop") sensor(s)
  • Comparators if desired (my sensors came with LM393).
  • You may wish a current-limiting resistor for moisture sensor if you use no comparator. 10K worked for me.

Cables and connectors

  • Signal wire. I used 22 AWG 2-conductor stranded.
  • Screw terminal connectors for breadboard (optional)
  • Cable connectors (I used Scotchlok(R) type UY for telecom)
  • Crimp lugs (optional)

Miscellaneous

  • Breadboard, PCB, or Arduino shield
  • Cable ties and/or clamps
  • Sensor mounting materials, as appropriate

Step 2: Sensor Detection and Alarms

The float switch is anticipated to be either on or off, and is wired in series with a 10k resistor.

Gnd -> 10k -> switch -> Vcc

The float switch is closed if the float is low (no flooding) and opens at high water, If the signal is measured between the resistor and switch, the signal is 1 at low water, 0 at high water. This matches the behavior of the LM393 comparators, and the program can therefore check all sensor pins in the same way.

The prototype's alarm is a small piezo buzzer, but I'll dig a speaker out of a junked PC to give better volume. There are a couple of instructables geared toward obtaining better volume and a piercing signal from a piezo buzzer or speaker by amplifying with a transistor.

For troubleshooting purposes, I added LEDs to detect "no alarm" and "alarm" states.

Step 3: The Sketch

/* Arduino Uno or Nano

Sketch is written assuming that digital pins 2, 3, on up are used for the detectors.

Three digital pins--10 to 12--are used for indicator LEDs and audible alarm.

Float switch is open at low water, closed at high.

10k resistor in series with float switch, read across the resistor.

Gnd -> 10K Resistor -> Switch -> Vcc

Resistive moisture sensors Use comparator module, digital signal. Analog output not used.

*/

//Constants

const int sensorStartPin=2; // Lowest digital sensor pin number on Arduino board

const int noSensors=3; // Number of sensors connected, incl float switch

const int ledAlarm=11, ledOK=10; // Green and red LED visible indicator (opt.)

const int audibleAlarm=12; // Pin to actuate speaker, siren, etc.

const int testDelay=0; // Slows reading frequency for testing

// Variables

int pin; // Scratch--Current pin in count

int sensorState; // Current pin's sensor reading

void setup() {

// Declare sensor pin modes

for(pin=sensorStartPin; pin < noSensors+sensorStartPin; pin++) {

pinMode (pin, INPUT); // Set sensor pins to input mode }

// Rest of pins are output mode

pinMode (ledOK, OUTPUT);

pinMode (ledAlarm, OUTPUT);

pinMode (audibleAlarm, OUTPUT); }

void loop() {
// Reset status indicators--no alarm condition

digitalWrite(ledOK, HIGH); // Green led on

digitalWrite(ledAlarm, LOW); // Red led off

digitalWrite(audibleAlarm, LOW); // Audible alarm off

/* Step through sensor pins, looking for digital state

Comparators return 0 if moisture detected, 1 when dry.

Float switch closed when water level is low, open when high (floating)

Wired to pull digital pin low when float switch is closed, thus

matching moisture sensor state. */

// Step through sensor pins

for(pin=sensorStartPin; pin < noSensors+sensorStartPin; pin++) {

sensorState=digitalRead(pin); // Read current pin (water=0, dry=1)

delay(testDelay); // Slows reading frequency for testing

while(sensorState==0) { // While alarm condition exists...

digitalWrite(ledOK, LOW); // OK (green) off

digitalWrite(ledAlarm, HIGH); // Alarm light (red) on

tone(audibleAlarm, 4000, 500); // Beep 4 KHz for 1/2 sec

delay (500);

sensorState=1;

}

delay(testDelay);

}

}

Step 4: Cable Connection Notes

Connections

The moisture sensors have Thompson-type male pins. I cut and stripped female-male Thompson jumpers, and joined to the alarm cable with crimp connectors, using a short length of wire to add bulk (the crimp connectors are rated for 22 gauge minimum). I will coat the connection area with petroleum jelly and insulate with heat shrink, Harbor freight assortment P/N 67530, $4)).

Cables are joined to the sensor pigtails with Scotchlok(r) type UY telecommunication connectors. These are filled with a moisture-resistant gel and handle a variety of wire gauges, require no stripping, and are easy to install.

At the Arduino end, I connect the signal cable to a breadboardable screw terminal block. This seemed to be the least expensive secure option--tinning the wires and plugging them in to the breadboard seemed an invitation to have them fall out when jiggled. Crimp lugs may be used.

The terminal blocks I selected will not, I find, fit some breadboards. Additionally, they must be eased in very carefully, lest their pins bend. They also permanently deform the breadboard connectors.

As I am terrifically shaky and therefore can no longer solder, I did not build a custom PCB. My basement, though unfinished, is--generally--dry. (If this were installed in a crawl space, though, I'd solder to a prototyping shield or make a circuit board and enclose it in a reasonably watertight case, such as a food storage box.) My mill and lathe are in that corner, though: if the (metal) chips fly where they may, I can simply place a box over the board as a low-tech solution.

Step 5: Sensor Selection and Placement Notes

Overview

My basement does not have a sump, but rather an open drain in the middle of the unfinished portion, connected to the house's main drain. Thus, when my sewer line was blocked by a root, everything backed up. Urgle-gurgle.

I placed detectors in the following locations...

  • The basement drain. A/C condensate and water heater overpressure pipes both drain here.
  • The water heater drip pan
  • The washing machine area

Sensor selection

I purchased two types of sensors: resistive moisture ("rain", or "raindrop") and float switch. My drain will normally accept the full output of a garden hose without overflowing. The theory is that water flowing across the floor--say from a burst pipe--will trigger the resistive moisture sensor, but the float valve is present in case the drain backs up again.

The float valve is completely sealed and will hang over the drain mouth until the house falls down. However, it will get inundated by (possibly) filthy water poured into the drain. I will smear a silicone-based lubricant on its shaft, and expect to check its proper operation periodically.

The drain mouth, water heater overflow pan and the washing machine will each get a resistive moisture sensor. These are printed on bare circuit boards, connectors are exposed. I expect to replace them every few years when corrosion gets the best of them or they are damaged. I will smear petroleum jelly on the connectors themselves.

Placement

The float switch projects over the drain mouth, mounted on a small piece of 1/8" plywood. We'll see if the signal wires survive accidents.

The moisture sensor near the drain mouth will be the most exposed, and is therefore screwed to the concrete floor to keep it in place, using 1/8" plastic shim to keep it from direct contact with the possibly moist floor. The existing drainage PVC pipes will act to shield the sensor and cables from feet, to some extent anyway.

The water heater sensor is placed on the bottom of its drip tray; the washer sensor will lay directly on the rubber mat under the washer's drain hose. The latter will be fixed in place by double-sided tape.

Cables

The moisture sensors came with LM393 comparators, having 4 output pins, and these could be located on the breadboard mounting area, or sensor end of the cable. The former makes much more sense: not only are they out of dirt and harm, but only two conductors need to run to the sensors.

I selected 22 gauge 2-conductor alarm cable, relatively inexpensive and readily available. The max run is 45 feet, and I selected this gauge to keep voltage drop under the recommended 1.5%. I could have reused old CAT5 patch cords or bulk cable for the shorter runs.

Concrete screws secure the cable clamps (Harbor Freight assortment, P/N 6751) to the floor and cinderblock walls.

Step 6: Location and Alarm Notes

I will try leaving the breadboard in the basement. I'd like to have an alarm upstairs, though. Fortunately, the living room is almost directly above the unfinished basement; I can easily run a cable.

I have mostly finished hacking my fireplace gas valve and adding remote control capability and a thermostat (Instructable to follow once I finish modifying the code). I'll tie in the flooding alarm and other fun sensors. Projects include "Garage door left open", basement door closed notification (the cat's litterbox is there), lights left on, and more.

Step 7: Future Enhancements

I plan to add a w5100 Ethernet module and perhaps WiFi as well. I'd need a static IP service, a Temboo account, and some service such as IFTTT (If this then that) in order to receive an email, text message, or other communication.

Cellular is not an option--my house's drywall has metal mesh(!) and the walls are cinderblock anyway,and I am therefore living in a Faraday cage: cellular reception is terrible and spotty. Besides, I don't want to be saddled with yet another monthly fee.

In case of false alarm--pouring a bucket of water down the drain, for instance--the moisture sensor alarm will trigger. It's not worth my effort to add a "silence for a few minutes" button, as I'd simply unplug the board in that case, but you may wish to add one to avoid being scared out of your skin.