Ultrasonic water level sensor

Disclaimer: I know nothing about electronics but can be taught!

I have a couple of lengthy threads here on this forum but am starting a new one due to a rather significant change in my application.

In late 2018 I built a system to control a water pump in a well that is 1000 feet from its associated storage tank. It uses Particle Electrons attached to NCD MCP23008 relay boards. The firmware running on the Electrons simply turns the pump on or off as a function of the tank’s water level, signaled by a float switch. All works great.

Now I want to embellish the system with the ability to remotely monitor the water level between its high and low levels. Based on the recommendation of others here, I started looking at an AMS5812 pressure transducer. This device would connect to the MCP23008 via the I2C interface and connect to the water tank via a silicone tube. Unfortunately, several issues have got in my way, not the least of which are 1) the requirement to keep the sensing tube under water at the bottom of the tank, 2) the need to keep the tube from freezing and 2) the risk of contaminating the potable water if there should ever be damage to or a leak in the tube. Just too mechanical for me to feel comfortable.

Consequently, I am thinking that it might be better to switch to an ultrasonic sensor. They are cheap ($5+/-), apparently reliable and accurate, connect to the electronics via wire, do not reside underwater at the bottom of the tank but above the high water mark, etc., etc.

There are lots of tutorials online on how to build an ultrasonic water level gauge using Arduino, but so far I have not yet found any info on how to achieve the same objective with an Electron.

My desire is to interface the sensor to my existing Electron using either a direct connection to my MCP23008 if possible or, I suspect more likely, some kind of PCB/shield that is powered off the MCP’s I2C interface. Appropriate firmware would be added to the existing code running on the Electron.

If there is no way to interface to my existing Electron, I can acquire an Arduino and build an entirely independent system, but that would add additional cellular charges which I’d prefer to avoid.

Is there anyone out there that can offer some guidance or point me to any online resources that I have not yet found?

Many thanks in advance!

Hi,

We actually sell a tank level sensor that has a range of 5 meters here:


As long as your tank is less than 5 meters tall this would be exactly what you are describing. However I fully understand this is a much more expensive solution than you were probably looking for. This device is more for our industrial user base. It sounds like you might fit more in our Doc Brown user base :smirk:
This however is nothing more than an ultra sonic sensor device like you’re describing, just more refined than a standard Arduino based device. My recommendation would be to source an I2C ultrasonic distance sensor(just google that and you’ll find them). This can be connected to the I2C port on the MCP23008 board, however be careful to ensure that the I2C ultrasonic sensor is 5VDC tolerant on the SCL and SDA lines used for the I2C data communication. You should be able to source a 3rd party Arduino library for the sensor online, if you can find a Particle library that would be even better but honestly porting an Arduino library to Particle is cake.

Hopefully this helps.

Yes, I did see that Travis and, indeed, it’s way beyond my price range. And there is no significant value to me in the wireless capability. Furthermore, the while the water tank holds 1600 gallons, it’s wide but not tall; the high water mark is only about 4 feet above the bottom.

I have located dozens of ultrasonic sensors and a decent subset of those are of the waterproof variety, but I haven’t yet found one that has a I2C interface. But then, I’ve never included ‘I2C’ in my search parameters. I’ll do that now…

Follow-up question Travis:

The waterproof sensors I’ve found so far (e.g. https://smile.amazon.com/dp/B082KYFYZS/?coliid=I1TOALXF4I26UY&colid=14JY8575AU243&psc=1&ref_=lv_ov_lig_dp_it), have a 6.5 foot cable. It is not mentioned whether that is I2C but I doubt it due to the length being considerably longer than the I2C protocol supports.

Since the distance from my water tank to the weatherproof enclosure that contains my NCD relay board and Electron is about 20 feet, the first thing I need to do is splice an extension into that cable. I asked if that could be done (via a question I submitted on Amazon) and was informed that yes, I can.

Once I can reach the enclosure, I need something to convert the signal to I2C so I can interface to the relay board. Does that make sense? Is the 4-pin connection on the sensor’s associated PCB look like I2C? If not, does NCD have anything like that?

That appears to be a bare bones sensor in the sense that it does not have any sort of IC that converts readings for you. The way it works is you send a signal to the trigger line, then begin monitoring the echo line, once you get a signal on the echo line you determine the amount of time it took from when you triggered the trigger line to when the echo line signaled. From that duration you can determine the distance. So you could use something like an Arduino board to do nothing but this task, and have it implement I2C as a slave device and connect it to the Electron. The Arduino can monitor the sensor, convert what it sees to a distance, and then transmit that information over the I2C connection to the Electron. It sound like a lot but it’s really not that bad. I’d recommend looking at the Arduino documentation for Wire which is the I2C protocol.

Sorry for the delayed response by the way. We’re running a skeleton crew here so everyone is working their butt off.

Thanks,
Travis

Thanks again Travis. I’ll check the Arduino option. But you say this sensor appears to be “bare bones” yet it comes with a PCB with a 4-pin interface that I thought might be I2C. I’ve posted a question about that on one of the many Amazon listings for the device.

From the limited information on the product page I can see the 4 pins are +5VDC, GND, Trigger, and Echo. This means the device is not I2C. I2C has SCL SDA GND and +V.

Yup. Kinda figured that. But while I’ve got you, is a Particle Photon interchangeable with an Electron on NCD’s relay shields? I’m looking for a way to create apps at home where I do not have access to the AT&T cellular network required for the Electron, i.e. develop on a Photon and, once ready, port the code to an Electron later.

Hi,

Yes, Photon modules are compatible on all of our IoT interface boards. So you can develop on a Photon and then transition to an Electron when you need to.

Outstanding! Be safe Travis.

Following up Travis. I ordered and have received a waterproof ultrasonic sensor (with associated PCB) and an Arduino Uno. I have also ordered a Photon, due here next Monday. My plan is to connect the sensor to the Arduino and, via I2C, the Arduino to my recently-purchased backup NCD relay shield.

I have found code for the Arduino that reads the sensor’s output and have tested it; it works! I have also found code for both the Arduino and the Photon to manage serial communications between them, but everything I’ve seen so far assumes that the two devices can be directly wired together. However, the Photon will be inserted into my NCD relay shield and I cannot directly connect to specific Photon pins; I have to communicate via I2C.

So my problem is to figure out what code I need to run on the Photon to retrieve that info from the Arduino via I2C. While I continue to look all over the Internet for same, do you have any insight to offer?