Introduction: Remote Water Tank Level Sensor V2.0

This project is a re-boot from a 2-year-old project to accomplish the same. The goal is to have an internet-enabled sensor mounted to a water tank which measures the amount of water in the tank and records it online. When the tank gets low, an SMS is sent to me to alert me. Additionally, at any time, I can send an SMS to inquire how much water is in the tank.

Who would want such a thing? The target here is a vacation home which is not on public water. We don't want to leave guests without water, but every tank refill is expensive - and each refill is the same price whether they put in 10 or 1,000 gallons. So, we can save a lot of money by knowing the water tank level in real time. Plus, the collected data helps us understand how much water we should expect guests to use, thereby learning how low we can let the tank go.

I made a similar system a couple years back, before Google's NEST acquisition and "IoT" became such a common term. In re-doing this project, I was happy to see how much all of the tool sets had improved! I think the result is a much more stable, higher-performance, less buggy system.

Step 1: Confirm the Requirements

All good designs start with a good list of requirements. Before spending any more time and money on this thing, let's make sure it meets your needs.

Overview

The Water Tank Level Sensor (WTLS) is a system of hardware and software which records and reports how much water is in a water tank. It includes a distance sensor mounted in the top of the tank which is connected to a small microcontroller via cable. The microcontroller reads the distance measurement from the sensor and then transmits that measurement over wireless internet to a server which stores the measurement with capabilities for graphical and tabular display of historical data. Also, the measurement is compared against alert levels and sends an alert SMS if the water level is low. In addition to this alert SMS, there are a few other SMS commands and responses that the system can receive and respond to.

The Hardware

The WTLS consists of a sensor from Maxbotix ($270) and an Electric Imp microcontroller ($50). These are the main pieces of hardware. Appropriate waterproof connectors for the wires are sourced from Amphenol and are the bulk of the remaining hardware cost, which also includes cable tie-downs, jam nuts for the sensor, header and connector for the Electric Imp, and plastic project box and mounting screws (~$50).

Total project budget: $370.

Note: I will mention a variation of the project which cuts $100-$150 from the budget at the cost of a completely watertight sensor-to-cable connection

The Software

The software performs the following functions:

  • Remote upgrade of software without physical sensor access.
  • Read the sensor measurement
  • Send an error SMS if the sensor measurement is clearly bad. Have a way to turn on and off these error warnings.
  • Record sensor measurement at a regular interval (“Period”) which is user-defined, but defaults to every 15 minutes.
  • Display historical data from the sensor, processed so that it shows total gallons in the tank (not just distance) as a function of date/time. This should be displayed on a web browser and the length of data displayed should be variable between a month and a single day. A user should be able to look at prior months as well.
  • Record and display the time delay between when the sensor took a reading and when that reading was saved.
  • Ensure a sensor reading doesn’t get “frozen” and recorded more than once
  • If the gallons of the water in the tank drops below a user-prescribed level, send an alert SMS. Send only 1 alert SMS per user-prescribed level, until tank is re-filled. Allow for multiple user-prescribed levels where this happens
  • When the tank is re-filled, re-enable all of the alerts so that SMS’s will be sent when the tank is low again
  • Receive the following commands via SMS and do the following:
    • "level” – SMS back the most updated measurement, and how long ago it was taken
    • “period=30” – update the period for recording to 30 minutes. This should work with not just 30, but any number from 10 to 1440.
    • “enable” – enable error SMS messages
    • “disable” – disable error SMS messages
    • “help” – SMS back this list of commands

Timeline

It will take 4-5 weeks to get all the necessary hardware. The sensor is the longest-lead item, and most of the fabrication can be done before it arrives, in a few hours total. Software development and debug is quick if you use my exact software (and it works for you). For reference, it was probably 6 to 8 hours of development time for me to write and test. Site installation can be done in an hours or less.

Step 2: Buy Parts

Next up: buy the parts. Here's the full BOM, with some ordering notes below and then tools list below that.

Bill of Materials

Optional Cable extension BOM:

  • Extra cable for sensor - Digikey - $1.78/m
    • Alternate cable - Digikey - $26.84 per 50 feet
  • Watertight connector (male); Amphenol LTW Series PN 12-04BMMA-SL8001 - same as above
  • Watertight connector (female); Amphenol LTW Series PN 12-04BFFB-SL7001 - same as above
    • Alternate watertight connector (female); Amphenol LTW Series PN 12-04BFFA-SL8001 - same as above

Ordering Notes:

Items marked with a * can be omitted if you don't want to put your electric imp into a project box. Since there's no way to mount that breakout board, I recommend the project box.

The sensor is purchased directly from the manufacturer (Maxbotix). I've attached a screen shot of the Maxbotix cart. This can be tricky, since the base part number of the sensor does not specify the housing type. If you want to see a major cost savings and can sacrifice some environmental protection, then just order the base sensor (or the MB7380 to save $40 more and not have the self-cleaning feature) without the Cable Attach Option or Sensor Cable. Make sure you buy the "Optional Cable Extension BOM" without the female connector, though.

Everything but the sensor comes through distributors. I've listed suggested distributors for all of the parts; occasionally some distributors will be out of stock of certain parts, so watch for that. I suggest using octopart.com to find other distributors who have the part in stock. I've also listed a few alternative part numbers for the connectors to help with finding things in stock

I haven't done the install yet, so I'm leaving off details for ordering the installation screws, nuts and cable hold-downs until I have verified parts.

Bill of Tools

  • Special tool: 1 3/8" paddle bit or hole saw and drill (used to drill a hole in the tank to mount the sensor)
    • Note: I had previously recommended a 1 5/16" hole saw (McMaster 4066A24) and corresponding arbor and shank (McMaster 4066A79), but I now worry this might be too tight for the sensor. I did not try it, so I do not know. The 1 3/8" paddle bit I used worked very well.
  • Generic tools:
    • Hacksaw or Dremel tool for cutting FR4 (any old hacksaw will probably do)
    • 3/8" chuck drill with the following bits: 3/32", 7/64", 3/16", 1/2"
    • Xacto or other small razor knife
    • Soldering Iron (fine electronics kind) and electronics-grade solder
    • Thumb tack (for marking FR4)
    • Wire stripper - I recommend one with a fixed-size 22 AWG stripper feature so that you do not accidentally cut some strands of conductor and weaken the wire at a crucial spot.
    • Crimp tool - generic small-crimp tool such as the one pictured. While I haven't tried it, I bet this one from Digikey would work well.

If your drill chuck size is different, make sure to get an appropriately-sized arbor and shank for the hole saw.

Step 3: Blink-up the Electric Imp and Set Up Software

You can do this step once you have Electric Imp (e-imp), e-imp breakout board, USB cable and USB power block.

Follow the directions on the e-imp website or on Sparkfun for doing a blink-up. Basically, set up an account at electricimp.com, download the blink-up smartphone app, enter your e-imp username, Wifi network name and password into the app, and place your phone against the e-imp after you power it up. Note you'll need the jumper installed to power it up from the USB - or use a temporary jumper like a piece of wire.

I had to try to blink-up twice, but it worked perfectly the second time. It works of the e-imp blinks green.

Now, log into ide.electricimp.com and you should see your electric imp. You can check the MAC address to make sure. Make a new model and associate it with your e-imp. Paste my software into your agent and device windows. My software is available on my Github repository under MIT License, so enjoy!

There are a few fill-in-the-blanks in the software on the agent side. First, enter your phone number and phone number whitelist (everyone who's allowed to text in to the sensor) into the top of the agent code.

Next, you have to create two more software accounts:

  1. Twilio. Create a new account and get a phone number. Note your AccountSID and Auth Token and copy them into the e-imp agent code. Also, copy your Twilio phone number.
  2. Thingspeak. Create new account and set up a new channel and name field1 "distance" and field2 "delay". Copy the Write API key into the e-imp agent code.

Note: don't share your Thingspeak API Key or Twilio Auth Token with anyone and treat them as you would a password.

Second note: it's possible that once you finish doing the above, your system will actually function. Since you have no sensor connected to the e-imp, it shouldn't send gobs of useless data to ThingSpeak, but it may text you to tell you the sensor is offline. You may want to comment out your ThingSpeak API key for now just to be careful.

Step 4: Mount the Electric Imp Breakout Board

Time for fabrication! The next 3 steps are the fabrication steps. You can start this step after the following parts have arrived: project box, FR4, #4 screws, Electric Imp, Electric Imp breakout board, USB cable, USB power block and PCB header.

First off, let's note that most of this step exists because there are no mounting features on the e-imp breakout board! Who's bright idea was that one? The best idea I had was to glue it down to a bigger board that could fit mounting features. If anyone re-spins that breakout board to be bigger and have mounting holes (ideally, spin it with a PCB size, shape and hole pattern than matches a COTS plastic box!) - please let me know.

Anyway, moving on.

Here are the steps:

  1. Cut the FR4 to fit within the box as shown (note that I bought the wrong size of FR4 and had to glue 2 pieces together, oops). Note that the FR4 extends to the box edge on the long sides of the box, but does not extend all the way to the edge on the short sides. Approximate FR4 size should be 3 1/4" by 4 1/8"
  2. Drill 4 mounting holes in the FR4 using a 7/64" bit. Determining hole location is a bit tricky; I used a marker to put ink on the stand-off faces, then pressed the FR4 piece down to pick up some ink. Then, I used a thumb tack to mark the FR4 at the center of each stand-off face.
  3. Mount the FR4 board into the box using the #4 screws.
  4. Holding the Electric Imp breakout board flush to the long side of the FR4 board inside the box, use a thumb tack to mark the FR4 through the Electric Imp breakout board holes marked: Pin8, Pin9, CD, 3V3, GND, Bat, USB, and the unlabeled hole between Bat and USB. See photo. If you went out of order and already did step 5, then use a piece of paper to transfer dimensions to the FR4 (see photo).
  5. Solder in PCB Header. Make sure you put it in the last 5 holes: Pin8 through GND. Also, solder in 3-pin header and place jumper on USB side (if the header and jumper didn't come installed).
  6. Remove FR4 board from box. Use 3/32" drill bit to drill 8 holes in FR4 corresponding to the 8 markings made in step 4.
  7. (optional) Cut a small piece of FR4 and glue to to the back side of the main FR4 piece so that it covers up all 8 holes. This is to add strength to the FR4, but it's probably not necessary.
  8. Check Electric Imp breakout PCB fit on to the FR4 board. It should sit flush against the board with the PCB header stubs sitting comfortably in the holes you just drilled. Mount the FR4 board back into the plastic box and hold the breakout board in place. Use the thumb tack to mark the plastic box where the mini-USB port is.
  9. Remove FR4 board and breakout board from plastic box and drill out a hole in the plastic box for the mini-USB. Use a 3/16" drill bit, then finish it off with a Xacto knife.
  10. Mount FR4 board back in the box. Ensure USB cable plugs into the breakout board through the new hole when you are holding the breakout board in place. If it works, go ahead and superglue the breakout board down to the FR4. And while you're at it, request Sparkfun or Electric Imp make a breakout board with mounting holes next time!!
  11. Your box should look like the photo now.

Cost-saving option is to skip the project box entirely and just run the sensor cable (or extender cable) directly to the PCB header connector. You save the cost of the box, FR4, superglue, panel mount connector and one of the inline male connectors (the items marked with * on the BOM back a few steps). Plus you save some fabrication time. But then there's nothing mounting the e-imp. Perhaps you could use some double-sided foam tape to hold it down somewhere, but over time dust and exposure to possible damage may threaten your otherwise awesome system.

Step 5: Cut Hole in the Box

You already have the min-USB hole in the box, so just one more hole to go. For this step, you'll need the panel mount connector in addition to the items previously. For tools, you'll need a drill with 1/2" bit and Xacto (or other small razor) knife.

  1. Mark the center of where you want the panel connector using a thumb tack. Place the connector on the same box face as the USB connector. Locate its center point as follows:
    1. vertical: halfway between FR4 top surface and top edge of box (without lid)
    2. horizontal: halfway between the box corner and the edge of the e-imp that has the PCB header.
  2. Remove everything from inside the box and drill a hole for the panel mount connector using a 1/2" drill bit. Don't use any bit larger than a 7/32" because you want to maintain the flats on the connector hole. If you drill out the hole in the box too large, then mating the connector later will be nearly impossible because the panel mount connector will spin in place.
  3. After you drill the under-sized hole, you'll need to use the Xacto knife to widen it in the horizontal dimension. Work slowly and check fit with the connector often.

Step 6: Build the Wire Harness

We have a simple 4-conductor wire harness to build here which goes from the panel mount connector to the PCB header connector. For this step, you'll need the 22 AWG wire and PCB header connector and terminals, in addition to the items from previous steps. For tools, you'll need a soldering iron, wire strippers/cutters and crimp tool.

Here are the steps:

  1. Solder 4 22 AWG wires to panel mount connector.
  2. Crimp the other end of the wires to the PCB connector terminals. You'll need a crimp tool for this. See photo. Note that these terminals do not crimp to the insulation, only to the bare conductor. So, strip the conductor, crimp on the terminal.
  3. Insert the terminals into the connector. Note the tine on the terminal comes through the little hole on the connector. There should be a faint "click" when the terminal is inserted. Insert the right terminals into the right positions! See notes on pin counting below.
    1. Connector pin 1 = 3V3 power in e-imp
    2. Connector pin 2 = GND on e-imp
    3. Connector pin 3 = e-imp Pin 9 (sensor TX, e-imp RX)
    4. Connector pin 4 = e-imp Pin 8 (sensor RX - not currently used)
  4. Screw down the FR4 board, put in panel connector and tighten its nut. Connect PCB header connector to PCB header.
  5. Screw lid on to box (or leave it off for debugging the next steps).

Now you have a wireless sensor receiver box.

Notes:

  • Don't use solder on the terminals. It will create a stress point at the place in the wire where the solder ends. This is especially problematic because we don't have much clearance from connector to box lid, which further would stree such a point on the wire.
  • If you don't have a crimp tool, you can very carefully use a needle-nose pliers or xacto knife to fold in one crimp tine at a time...but I highly recommend a crimp tool.
  • The PCB connector will fit through the hole you put in the box and through the panel connector nut.
  • Use the attached photo to count connector pins and know which connector pin is "pin 1". Reference "female connector".
    • "Front View" is the view as if you were the mating connector.
  • Do not put a terminal in the middle position of the PCB header connector. We don't use the "CD" pin.
  • The box is not watertight due to the mini-USB hole, so make sure it stays indoors. If you want an outdoors version, use a watertight USB connector (or a different watertight power connector).

I am considering an upgrade to power this system from a battery pack. I am looking at this pack in particular. This pack has USB output and if we use a box with a clear lid, it would be solar-powered. I think that would be very cool. I am worried that the battery might turn its output off, though. If anyone gives it a try, please let me know!

Step 7: Put Connectors on Sensor and Extra Cable

Ok, now you need the Maxbotix sensor. Despite the warnings on the website, their lead time for me was only about 1 week. You also need the Amphenol connector(s) and extra cable, if you're using it. For tools, you'll need a soldering iron.

If you did not get the Cable Attach Option and Sensor Cable from Maxbotix, you should have gotten some 4-conductor 22-AWG cable. You'll have to attach this cable yourself to your sensor. You can either directly solder it or you can use the PCB header connector that we use on the e-imp breakout PCB. Neither is environmentally sealed, unfortunately.

In this step, we'll put the connector on the Maxbotix sensor cable. If you're inserting your own cable in between the Maxbotix sensor and the box, you'll follow this same procedure to put the connectors on that extra cable. Note that you may need to run the extra cable through a hole in a wall somewhere before putting the second connector on.

Note that the Maxbotix sensor needs a MALE connector (since the panel mount connector is female). On the xtra cable, you'll need a male connector on one end and a female on the other end.

Here's the process:

  1. Open connector and run cable through cable gland pieces
  2. Strip back cable jacket and wires
  3. Solder wires to connector pins (red=1, black=2, blue=3, green=4)
  4. Close and tighten connector and cable gland (tighten connector first, then cable gland)

And here's the critical wiring table:

  1. Circuit 1 = Connector pin 1 = E-imp pin 3V3 = Maxbotix V+ pin 6 = Maxbotix Red wire
  2. Circuit 2 = Connector pin 2 = E-imp pin GND = Maxbotix GND pin 7 = Maxbotix Black wire
  3. Circuit 3 = connector pin 3 = E-imp pin 9 = Maxbotix Pin 5 Serial Output = Maxbotix Blue wire
  4. Circuit 4 = Connector pin 4 = E-imp pin 8 = Maxbotix Pin 4 RX = Maxbotix Green wire (this circuit not currently used)

Notes:

See photo to identify which terminal is "pin 1" on the connector(s). Note that "Front view" means the view as if you were the mating connector (NOT when viewed from the soldering side of the connector).

Step 8: Connect and Test

I recommend before doing your actual site install, that you connect and test the system.

Here's my testbench: our e-imp box and sensor connected and on a coffee table.

First, when you plug it all in to power, you should see your e-imp blinking to green eventually. If it doesn't blink at all, you may have wired something incorrectly. Then, put your ear next to the sensor and you should hear faint clicking. This means the sensor is working.

Next, it's time to test functionality. I used some coasters to hold the sensor at the edge of the table, aimed for the wall. I then could move the table closer and further from the wall to simulate the tank filling and emptying. I tested all the various scenarios of tank refill and made sure I received appropriate error messages when the tank emptied, etc.

Step 9: Install and Run

Final step! Let's get this installed and running.

I used the drill and 1 3/8" paddle bit to drill the hole through the tank - works like a charm. The sensor was held in with a locknut on each side of the tank wall (1 inside, 1 outside) - that also worked like a charm. I oriented the locknuts so that they both could bite into the plastic, then used a wrench to tighten the outside one and the inside one bit in and snugged up.

What's that other hole you ask? A relic of water tank level sensor 1.0. Turns out it's next to impossible to enlarge an existing hole with a paddle bit... oops. The other relic is a 4-conductor sold copper wire (telephone-style) which was left running from inside the house to outside near the tank. I re-used this wire, so I had to solder some connectors on each end.

I ran the cable off of the top of the tank and installed some plastic coaxial cable staples (the plastic u-shaped ones with a small nail in one arm of the U) to hold the cable in place in case of wind. Then, I installed the inline connector to connect the cable from the sensor to the cable that was already in place running from outside the house to inside the house.

Notes for connector install:

- first, the connector is MUCH easier to install on solid copper wire than stranded

- second, make sure the distance from cable jacket to connector body (see red line on the drawing) is short enough that the back shell of the connect can seal against the cable jacket

Then, I plugged it all in, did a new blink-up of the electric imp (since I was on a new wifi network) and it worked!

Good luck! If you build something similar, please comment below and let me know about it!

Addendum

After some time, I noticed some noise in the data stream. The sensor would occasionally jump by a meter or more, then would jump back either minutes or hours later. I am still trying to figure out what is causing this. I have a few guesses, but would also appreciate ideas or comments on the issue! When I figure it out, I will post details and modify the instructable as needed.