Sump pump alert with Moteino & HC-SR04

UPDATE: This project has been replaced/updated with SonarMote. See this blog post for a more rencent implementation of what you see here. The alerts are now implemented as simple events on the Moteino Gateway.

Here’s another project I wanted to do for a long time. I wanted a sump pump flood warning alert system in place, for peace of mind when I’m gone from home for prolonged periods. For whatever reason I thought this was going to be more difficult but no, it’s almost as easy as pie!

All I needed was a HC-SR04 sonar sensor and a USB 5V wall supply. The sensor only works at 5V so this method of powering the Moteino was very convenient since I already have an outlet close by for the sump pump.

The sensor has 4 pins clearly marked: VCC, GND, TRIG and ECHO. I connected VCC to VIN on Moteino, ECHO goes to D3 and TRIG to D4.


I used some of the code this instructable to get started and added my wireless code to handle packets and blink the LED and was done in no time. The setup was very simple, I estimated a good spot underneath the sump pump cover where there are no obstructions inside, cleaned it up, taped some velcro, secured the wires and that was pretty much it.

 Moteino_HC-SR04_SumpPumpAlert_cover Moteino_HC-SR04_SumpPumpAlert_installed

I added a few lines of code to my main Python script running on the RaspberryPi.
By the way, here’s how my RaspberryPi setup looks like, including the ATXRaspi power controller, the power button and the gateway Moteino (it’s an older R1 but just as good for as a gateway):


The Python script logs the data to EmonCMS and here’s a graph of how that looks like, the Moteino reports the distance to the water surface, so the spikes means the sump pump just kicked ON, and as water rises the distance decreases until the pump starts again:


It’s been a rainy spring so far here and I knew my pump kicks ON quite often, now I can see it in real time, and setup alerts if the water rises too much. Seems like the pump is always pumping water out when it rises to 32cm below basement surface. So setting an alert to something like 20cm below surface should be enough since I don’t expect the water to ever rise so much as long as the pump works. The alert code will send me a SMS message when this happens, here’s a test level, I set the live value at 20cm:


You can of course setup other types of alerts – like audio alerts or maybe a LED visual indicator (less useful when you’re not in your basement).

Fun/Scary fact: The sensor is very accurate even though there’s a variance of 1cm between some readings (resulting in a sawtooth graph) as water rises. Based on the graphs, how often the water is pumped (every ~23 minutes), and how big the reservoir is, I figured my sump pump removes roughly about 18.5 liters every cycle, or about 1158 liters (306 gal) every day, wow!

So now there’s an extra level of peace of mind when I leave on vacation. I guess being gone for even 1 day could mean disaster if the sump pump breaks down at the same time!

Time to think about how to gather/store all that water instead of throwing it away, after all, I pay something like $11 for every 1000 gallons of city water.

Source code is on GitHub:

24 thoughts on “Sump pump alert with Moteino & HC-SR04

  1. Hello,

    Yesterday I ordered 4 Moteino’s from you. One of my projects is similar to this sump pump monitor (which I am also going to do too), which is an automatic rain barrel collection / soil moisture sensing / auto garden watering system.

    What I want to do is to measure how full my rain barrels are. However being too cheap to spend the $$ sonar sensor, I asked Mr. Google about this, and he gave me This website which uses nothing more than 2.2k resistors cable-tied to a pvc pipe. Then the water level shorts out the resistor stack and then the arduino reads the voltage. Granted its not as precise as your method, and I plan on using 10 resistors, which will give me 10% accuracy, but that will be fine for me.

    Best of all, its cheap, and I can get everything locally. Again thanks for the Moteino – its a great product

    — Mike

    • I got my ultrasonic sensor from Amazon for about $5 but it came from china so it took about 2 weeks. Anyway I think it was a good deal and I have the results/accuracy I’m looking for…

  2. We had several people in our neighborhood have basement floods because the power went out during a major rain storm (even with underground power lines!). You could consider adding either a GSM module or a “keep alive” check from a remote server to make sure your home has power (could be as simple as a script that pings your home IP and sends an SMS if it fails).

    • There’s many layers of extra protection you can add. The most obvious would be to add a backup pump and/or battery backup to your sump pump in case electricity goes out.

  3. I missed how the SMS messages get sent? How does that work? Nice project!

    • The python script sends an email to your mobile carrier (special email address corresponding to your mobile phone) with the message which ends up as a SMS message on your phone. See the script for details.

  4. I’ve been looking for something like this. I have 2 sump pumps in my crawl space that I would like to track the volume of water being pumped out, and also check for pump failure. My only experience with a Raspberry Pi is that I have one in my living room with XBMC hooked up to my TV. In my set up, I would need two sensors for sure, but could I hook it all up to one Raspberry Pi? What else would be different in my case? I wouldn’t necessarily want or need the power controller as I’d leave the Pi on all the time since it would be in my crawl space. Again, I don’t have a lot of experience in coding but I’d love to set this up.

    • Depending on how much load you got on your current Pi, it may handle the incoming data just fine. You will need to install EmonCMS if you want to keep track of historical data. That can be a challenge. Otherwise if you just want to watch for a water limit the python script I supplied should be fine. You would then need 1 receiver Moteino, and 2 transmitter Moteinos with a ultrasonic sensor each, and one 5V wallwart power supply each (assuming you have power available, otherwise you could run these from a 5V battery source as the sensors will only run at 5V, not more not less).

  5. HI, I noticed that you provided 5V through the FTDI PWR-IN, does that pin goes through the regulator?, I have an Adafruit FTDI friend that is 5v 3.3 logic level, can I use this to program the moteino or do I need to converted to 3.3V.


    • Yes the FTDI friend will work just fine for programming and power. The 5V/power pin on the FTDI connector is the same as the “VIN” side header pin, they both go through the regulator. The “3.3” pins are regulated 3.3v.

  6. Quick question, I am completely new to Raspberry Pi. Until now I didn’t have a solid reason to get one. Could someone give me a complete punch list to create this sensor along with some links on where to buy the items? I appreciate the help!

    • Moteinos are available in the LowPowerLab Store. You will need two – one will be a transmitter and the other a receiver. The ultrasonic sensor and raspberrypi are available on on ebay, amazon, element14 etc. You will need a 5V power supply – I used a phone charger. Details how to wire it are included above.

  7. I love this idea and it made me think about a need I have. I would love to make one of these but for air flow to put in the furnace on the opposite side of the filter to tell you when to change your filter. Any ideas on if that can be done?

  8. I wonder if you could use this creatively as a warning system on an aquarium sump as well. But not for the water level getting to high (though that would have some use). Rather for when the sump gets too low due to evaporative losses, and the tank could use a topping off before the level get so low, the pumps run dry and damage themselves.

    Just a thought…

    • You could use the same system, maybe link it with a water valve that allows water to fill up the thank.

  9. If it’s ground water, just pump it into a cistern outside. Use the water for watering your lawn and/or garden. I’m sure if you filter it a bit, you could use it to wash your car, or something like that too.

  10. Hi, I have been playing with ideas for a project like this and found this page. My idea was to use a non contact current sensor that will monitor the sump pump usage along with monitoring the water depth. That way both can be logged/displayed – I have the pump monitoring part in place using an Arduino.

    My question is regarding the Ultrasonic sensor. If it is placed inside the sump tank – due to high moisture/humidity levels – how long will the sensor last. There will be some form of sedimentation on the sensor due to moisture. Can the sensor be sealed in plastic/glass to overcome this? Would its distance sensing mechanism still work when enclosed in plastic/glass?

    • I am not sure, but so far it works ok. You can probably coat it with epoxy but not the two sound barrels. That should keep moisture away from the circuitry.

      • The electronics can always be sealed. It is the sound barrel that I am worried about. It looks like a miniature tweeter (or an small microphone). I’ll cover the sound barrel with cling wrap/plastic film and experiment with how that affects the distance measurement.

  11. I would like to do this project as it will be fun learing and useful.
    Instead of the RPi, I have a linux machine in the range of the transmitter moteino. Do you have any suggestion how the gateway moteino can be hooked up to this machine?

    • You can use a standard FTDI adapter if you have one (there’s also one available in the store). It emulates a serial port on your computer which you can then read from a python script as illustrated. The link for drivers is on the product page in the shop. Good luck.

Comments are closed.