Monitor for Sump Pump with Battery Backup

I made a sump pump monitor with an ESP32 development board and a submersible level (pressure) sensor. The idea behind this project was to meet several goals:

  • Locally controlled
  • Retains functionality without power or internet
  • No failure modes that can affect the sump pump’s operation
  • Tells me how often the pump is operating
  • Alerts me when either the primary or backup pump is not working
  • Alerts me when the backup battery is not charging or is drained

This monitor operates off the 12V battery that powers the backup sump pump. Here’s the major parts I used, plus miscellaneous wires, resistors, bypass capacitors, headers, DC barrel jacks, solder, etc. Some of the links are just examples; I got some items from AliExpress and others I had on-hand.

This is the schematic I came up with.

They make current-to-voltage converters which I could have used instead of creating the voltage divider circuit, but I didn’t see much point to that. I have no experience with this one, but here is an example if you want to use that option.

I connected it to the battery with a harness that goes from ring terminals to a DC plug, with an in-line fuse:

Doing this project made me realize how absolutely awful I am at soldering. Please don’t feel the need to tell me how bad I am, but I’ll take tips if you have them. The DC barrel jacks soldered to the board aren’t being used; this project went through several iterations and I reworked the board multiple times while I was still changing the schematic. Yes, even after I had it running on a breadboard and thought it was “good enough”. The one smart thing I did was to use headers instead of soldering the ESP32 and ADS1115 boards directly to the perfboard. It allowed easier access during soldering, I didn’t have to worry about overheating those components, and if I screw anything up they are easy to swap out.

This is all the components placed into the project box:

And here it is installed, sitting on the backup battery:

The level/pressure sensor sits in the bottom of the sump. It doesn’t really matter if it is vertical or laying horizontal, as long as it doesn’t interfere with any of the pumps. I have mine vertical, with the wire zip tied to some of the PVC pipe. You can’t see anything with both sump pumps in there, so here’s a picture with the sensor sitting in the sump while I was replacing the backup sump pump. The sensor is circled in red.

The code is quite complicated for all the sensors and monitoring I wanted to have. Here it is, feel free to modify as needed:

2 Likes

Very nice project!

Since the ADS115 gives you more ADC, is it worth adding additional level sensors for redundancy?

I wondered if the sensor clogs easily if there is lots of silt in the water. But maybe a cheesecloth or ultra fine wire mesh wrapped perforated PVC pipe to enclose the sensor solves that?

It’s certainly possible to add another level sensor, but I didn’t think it was necessary. I am using all the channels currently since I have 3 measurements (12V battery, 5V supply, and level sensor voltage) and they are all differential (measuring relative to the 4th channel which is ground). There shouldn’t be a difference since the ADS1115’s ground and the 4th channel ground should be at the same level, so I could probably change that and use the 4th channel for something else. But I think the level sensor going bad and unnoticed during a rain storm is a low probability. I could even add some logic to alert me if the pumpout interval was short and suddenly the pumpouts stop, or if the sump level doesn’t change for a long period of time. But I watch the level on my Lovelace dashboard so it’s not really a concern for me.

As to the sensor clogging, it’s just sensing pressure and there’s really no diaphragm movement, and therefore no flow in & out of the sensor. I’ve had it in there for about 6 months and there’s no buildup of anything to be worried about.

1 Like

I am almost finished the build…again thank you…however, still waiting for the level sensor and 12V siren from Aliexpress but I have encountered a couple of issues when testing that I am hoping you can help with. When hooking up the relay, without the alarm showing activated on the dashboard, the moment the siren relay wire (i.e. orange/4 in your diagram) is attached, the relay clicks and allows 12 volts to pass through and thus, I assume the siren would be going off. I have the output on NO and COM. Additionally, when I press the physical alarm pause button, the dashboard does indicate it’s active but it doesn’t cause the relay to switch the 12V/siren off. I believe that only when the alarm is on should it pass through the 12Vs while the pause button should open the relay and stop the siren. I have rechecked the wiring many times but clearly I have got something wrong. Any thoughts? From a dashboard perspective, everything seems to be displaying fine (obviously, only getting 0 for any measurement readings related to the level sensor) so I am a bit lost at the moment.

The snooze will only silence the warnings, and not the critical faults. If you don’t have the 12V battery connected, then the low battery voltage fault should be active and the siren should be on. So it may be working as designed.

If you didn’t remove it, the code will have the esp32 host a web server. You can visit that IP address with a browser and see which faults are active:

Sump Pump Fault: Backup Pump Not Operating	  OFF	
Sump Pump Fault: Battery Not Charging	      OFF	
Sump Pump Fault: Critically Low Battery	      OFF	
Sump Pump Fault: Primary Pump Not Operating	  OFF

If the “Backup Pump Not Operating” or the “Critically Low Battery” faults are ON, then the alarm will be enabled regardless of snooze status.

Ah so good to know that the snooze only silences the warnings, but that said, if the primary pump is not operating, for example, are you saying that there would be no way to shut off the siren while addressing that issue? For my test, I am using a 12v power supply (versus a battery) to power the unit (supplying a constant 12.089V - sump pump 12v battery voltage and 4.9V - sump pump 5v supply voltage respectively) and all faults are “off” including the “sump pump alarm sounding”. Would the fact that I don’t have the level sensor installed yet have anything to do with it? Is there any logic to the code I can check and/or build in so when I connect the wire to the relay it stays “open” until a fault or a warning occurs?

FYI - I was able to simulate a battery not charging fault while providing enough power to ensure the esp32 continued provide all the available stats with 5V continuing to be supplied to the relay. In this case, connecting the siren wire to the relay did nothing which I found interesting. Based on this, it would appear I may have something flipped as one would expect that at full constant input power of 12V, the siren wire would not be activating the relay. And sorry, in your coding, I found the comment where you indicate that with faults, it is not possible to snooze them.

SOLVED: Based on the findings above, I set the output pin 25 in your code to…Inverted: false (versus true). Now when I drop the voltage, the relay activates and provides power to the siren.

Good to hear you solved it. As to your question about snoozing: The snooze silences the primary pump fault and the battery not charging fault. The other two faults (backup pump fault and battery dead fault) are not snoozable. I did this because I didn’t want to have a scenario where, for example, the primary pump fails, and so I snooze it (so I can fix it later) but then the backup pump fails but that is snoozed as well. And then my basement floods.

That makes perfect sense, thanks for clarifying. I do wonder, however, in the case where the battery is no longer charging, at what voltage will it be when the 12v siren just stops. When I was testing, I recall being somewhere below 10v (need to test again to be sure), when the esp32 disconnected from HA and the relay began fluttering. I would assume the siren, which requires 12v would konk out sooner. Once I have the final pieces (level sensor and siren) to complete the build, I will do some further testing but with what it can provide when the battery is working properly, I am really impressed with what you have done.

I’d expect it’ll be different depending on what hardware you’re using. For me, I set it at 10.8V because that is the voltage that my backup pump is supposed to stop working. I’m hoping both the siren and the ESP still work at that voltage, but I haven’t tested either yet. It’s on my to-do list… :slight_smile:

I have received all the remaining parts and everything is working properly on the test bench. Again, a huge thanks to you for all your instructions, pictures and clarifications along the way. It’s been a great learning experience. That said, my very last question (ok maybe :slight_smile: ) is that I noticed that in one of the pics, you have a capacitor across in the incoming power terminals. I assume this is the bypass capacitor you mentioned but it is not in your circuit diagram. Perhaps a total noob question but is it required in this application and if so, what is the correct size?

I was having issues with noise in my level sensor signal, so I started putting bypass capacitors on a few different components. If your signals aren’t noisy then I wouldn’t worry about it. I put these on before I changed to the 12-to-5V converter (previously I was using an automotive 12V-to-USB converter and powering the nodeMCU through its USB port). I suspect the USB adapter I was using was the source of the noise, but I had made several changes before I noticed the noise issue was solved so I can’t be sure. I think I used a 100nf but I’m not sure, I just used the biggest one I had.

Glad to hear it’s working, post a picture when you get it installed in its final resting place!

edit: here’s what the noisy level sensor data looked like originally:
image

Hi I am am learning electronics and would like to implement this solution. From the schematic it doesn’t look like the ADS1115 is being powered by anything; is this correct?

It’s just my bad schematic-making skills. Every pin on the ADS1115 is connected; I should have put a solid dot on each one. The purple +5V line that looks to go right past the VDD pin is actually connected to the VDD pin and then also to A0.Same with the brown ground line: it connects to both GND and to ADDR.

Thank you so much! This makes sense.
What software did you use to make this diagram?

The online tool at digi-key:

So I am trying to build a similar setup, but using ESPHome and less custom software, simpler hardware. My BOM so far is:

ESP32 Dev board with built in relay (GPIO19). This board also accepts 12V power supply and has a built in DAC (GPIO0). https://www.amazon.com/gp/product/B0B7VPZ6WC/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

Voltage divider … although I am not sure this is need because the DAC seems to read between 0 and 1 rather than 0 - 2.6V. However, just to be safe I am using the divider as to not run 12V directly into the board. I used to multimeter to devise the conversion from the reading to actual voltage. I don’t think this is the most accurate voltage reading but at least should tell me if there is a significant problem with the battery. https://www.amazon.com/gp/product/B01HTC4XKY/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

Different project box. https://www.amazon.com/gp/product/B08N1DD5WJ/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

Different type of siren. https://www.amazon.com/gp/product/B07X8PRBX9/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

I used the DFRobot SEN0311 waterproof distance sensor. While the OPs sensor seems to be the better option, I didn’t want to fuss with resistors, manual code, etc. This was a more out of the box solution for me. SEN0311 DFRobot | Development Boards, Kits, Programmers | DigiKey

FYI, I initially tried a similar noname sensor on Amazon. I couldn’t get it to work even though it seems to be the same as the DFRobot. It was UART (there is a PWM version as well) but still wouldn’t work. So go with the DFRobot unless you want to try to get this to work with the a02yyuw platform or custom sensor in ESPHome. Since this sensor uses UART for communication UART needs to be setup in ESPHome. Below is my ESPHome code for the device (just the parts related to the UART and sensors)…

# Setup UART for ultrasonic sensor communication
uart:
  rx_pin: GPIO3 # Connect to tx on sensor
  tx_pin: GPIO5 # Connect to rx on sensor
  baud_rate: 9600

# Define sensors
sensor:
  - platform: "a02yyuw"
    name: "Water Depth"
    filters:
      - throttle: 30s
      - multiply: -1 # Make result negative
      - offset: 351 # (in mm) I used a ruler to measure depth and tweaked to get correct reading

# ADC (Connected to Voltage Divider)
  - platform: adc
    pin: GPIO0
    name: "Battery Voltage"
    accuracy_decimals: 3
    update_interval: 60s
    filters:
      - multiply: 15.696 #used multimeter to interpolate

# Relay to turn on siren
light:
  - platform: binary
    name: "Siren"
    output: relay
output:
  - id: relay
    platform: gpio
    pin: GPIO19

I also created a couple of custom 3D prints to mount the electronics as well as a mount for the sensor. I will post links when I get them on Thingiverse.

Sensor Mount: DFRobot SEN0311 Waterproof Distance Sensor Mount for Sump Pump by heatvent - Thingiverse

Here are some pictures of the final system. Black plug in back is power from battery and white cable out front goes to the ultrasonic sensor. I think I have something wrong possibly on the V monitoring as it seems to not fluctuate so further testing is needed. You can see with a backup sump pump my sump basin is quite crowded. The sensor is still able to get fairly accurate readings, however. When water is low, I think the accuracy goes down because of interference from the backup pump equipment. If I do any replacement, I will probably get a combination pump/backup and just have one unit … but that is down the road.

Is there a reason this project went with the 4 to 20 milliamp output sensor when I see on AliExpress there are some that output voltage signals from 0 to 5 volts?

I’d assume the voltage output would be a little bit easier to integrate into an ESP home-based project.

Either they’re new or I missed them when I did this. I think 5V might be too high but I just found a 0-3.3V one that is powered by 5V and measures up to 1 meter. That would be perfect for this.