DIY Wi-Fi Water Level Sensor & Meter with ESP8266, Tasmota, Arduino, MQTT, Node-RED, Telegram

PART 1: THE SENSOR

We need this sensor to read the water level inside the tank. For this we’ll be using the US-100 Ultrasonic Distance Sensor module. This sensor is 3.3V logic compatible and has a UART mode where it returns a distance reading that takes into account the current temperature for better accuracy. This sensor is wired to a ESP8266 module which is flashed with Tasmota and powered by POE. More info on the software bits after the photos.

Here is the hardware:

That’s a WEMOS D1 R2 with the US-100 wired. Power is fed in through a 2M length of outdoor-rated CCTV cable that will be plugged into a 12V POE splitter. This WEMOS board can handle 12V input safely but you can use any ESP8266 board with a voltage converter module. I’ve removed all of the pins and DC input on this WEMOS board to make it easier to install.

All installed:

The WEMOS module is hard-mounted with M3 screws and spacers but it’s important that the ultrasonic sensor is not mounted through the metal cans, I used hot glue on the back of the PCB. Applying pressure or fixation to the metal cans will prevent the sensor from working properly, they must sit loose and free.

The POE adapter was also hot glued in a waterproof CCTV junction box:

You can see the lines that I scored for drilling out the holes, they’re 16mm on one axis and 16mm & 39mm on the other axis. Drill out 16mm holes on the two intersections.

This is then mounted to the lid of the water tank, with a small bit cut out for the cable to pass through:

And finally the junction box is hung with a wire, with the cables pointing downwards to discourage water ingress during rains:

For the software, we’re using a custom build of Tasmota that incorporates a Serial to TCP bridge for Node-RED to access the sensor’s readings. This is because Tasmota does not currently support the UART mode of the US-100 sensor. You can compile your own or use the [ICODE]tasmota-zbbridge[/ICODE] pre-compiled binary.

Follow the instructions here:

while setting baud rate to 9600 with the [ICODE]TCPBaudRate 9600[/ICODE] command in the console. Be sure to setup rule1 to activate the bridge on boot with the command [ICODE]Rule1 ON System#Boot DO TCPStart 8888,192.168.0.10 ENDON[/ICODE]. The ip address should that of your self-hosted Node-RED instance (not covered in this guide).

PART2: THE CODE

This is the flow I’m currently using, you can replicate it or modify to your preference:

I called the overhead tank ‘elevated_pot’. You should have MQTT and optionally InfluxDB configured with Node-RED. You can delete the ‘record’ node if you don’t want or need the database.

Here’s the JSON for you to import into Node-RED:

(const String & payload) {
    reading = payload.toInt() / 10;
    if (reading <= 10)
    {
      bar.setLevel(reading);
    }
    Serial.println(payload);
  });
}
void loop()
{
  client.loop();
}

The serial connection is left on since the ESP-01 module has a blue LED connected to the TX pin, so it’s used a visual indicator that the module is working and getting updates.

We’re using the EspMQTTClient library that handles both Wi-Fi and MQTT:

The Grove LED Bar library in the Arduino IDE is out of date, so you’ll need to install it and then overwrite it with the updated unreleased files from github:

Be sure to experiment with the examples to learn more about those libraries.

All configured and working, showing that the tank is 40% full:

Installed in the hallway for everyone to see:

This project has been bouncing around in my head for five or so years now. I’m happy it’s finally done, even if it’s just a prototype.

If I’ve skipped something or something isn’t clear, ask away, I probably did forget a few key details somewhere.


Attachments:

55 Likes

A well described article. I think the forum needs a diy thread as there are many tinkerers here and plenty of knowledge regarding such projects. Thanks @@rsaeon for this very nicely executed project.

There is actually a thread for such articles called the build log on the forum . This article can be moved to that place I guess .

6 Likes

Thanks, it was fun building, documenting and figuring out the coding.

I have most of my incomplete projects in the build log section of the forum.

I’m from a time where the build log section is for in-progress or completed projects.

This is more of a guide, start to finish, with explanations and resources, all in a single post.

Basically, the difference is between “How I did this” vs “How you can do this”

Other guides in this section:

https://techenclave.com/forums/reviews-and-guides.28/?prefix_id=49

4 Likes

Great project as always, I myself wanted to do this for a very long time. Good thing you went with non-contact sensor. I don’t like anything touching my water. Hehe.

[HR][/HR]

What software you used to create this?

3 Likes

That’s Node-RED, you can import the JSON into your install of Node-RED to replicate that flow.

It’s pretty amazing, the tutorials on YouTube don’t evne come close to what’s possible with it.

3 Likes

This is a crazy tool, I need to learn this immediately. I have only seen one video of it yet.

2 Likes

Yeah I wanted to learn this too from a long time to use it to control zigbee devices. Thankfully we now have a member @@rsaeon who knows it well :wink: who can help us

2 Likes

sorry if sound noob…

how if you disclose total cost here, so any one want it to for commercial production can contact you …

3 Likes

I would also like to know the total cost in materials

1 Like

Everything I post here (photos, code, ideas) are public domain, no copyright is claimed and no attribution is requested (I should make this part of my signature or profile). So anyone and everyone is welcome to rebuild this, or even turn it into a commercial product — I’d love to see that actually. Some day, I would probably make this into a product or a kit, but that’s not anytime soon.

This is barely a prototype, there are so many refinements and modifications that can be done to make this a commercially viable product, I already have 5 different revisions in mind.

I put together some parts lists together for both devices with prices for only what is used. There are important notes to consider at the bottom of each one.

For the sensor:

Part Full Name URL Price with GST Quantity Total Cost
Enclosure CIRCUITX PLASTIC ENCLOSURE - MEDIUM PEM03

| 70.00 | 1 | 70 |
| Wi-Fi Module | WeMos ESP8266 D1 R2 V2.1.0 WiFi Development Board |

https://robu.in/product/wemos-esp8266-d1-r2-v2-1-0-wifi-development-board/

| 269.00 | 1 | 269 |
| Ultrasonic Sensor | US-100 Ultrasonic Sensor Distance Measuring Module with Temperature Compensation |

https://robu.in/product/us-100-ultrasonic-sensor-distance-measuring-module-temperature-compensation/

| 199.00 | 1 | 199 |
| Connector, PCB | 6 pin JST XH 2.5mm Side Entry Header |

| 8.35 | 1 | 8.35 |
| Connector, PCB | 2 pin JST XH 2.5mm Side Entry Header |

| 2.78 | 1 | 2.78 |
| Connector, Wire | 6 pin JST XH 2.5mm Housing |

| 4.18 | 1 | 4.18 |
| Connector, Wire | 2 pin JST XH 2.5mm Housing |

| 1.48 | 1 | 1.48 |
| Connector, Wire | 4 pin JST XH 2.5mm Housing |

| 2.79 | 1 | 2.79 |
| Pins, Wire | Crimping Pins for JST XH 2.5mm |

| 0.84 | 2 | 1.68 |
| Wire, Pre-crimped | 10cm JST XH 2.5mm Both side Pre-crimped white wire |

| 5.01 | 4 | 20.04 |
| Cable Gland | Polyamide Cable Gland PG 7 |

https://robu.in/product/polyamide-cable-gland-pg-7/

| 5 | 2 | 10 |
| Power Connector | Female DC Power adapter - 5.5x2.1mm plug to screw terminal |

| 34.81 | 1 | 34.81 |
| Ferrule | Black 0.5 sq. mm Wire Ferrule |

| 1.77 | 2 | 3.54 |
| POE Splitter | Paruht PoE Splitter Active 48V to 12V |

https://www.amazon.in/Pack-Ethernet-Splitter-Compatible-Switches/dp/B0BBQN4WL3/

| 329 | 1 | 329 |
| CCTV Cable | FEDUS 23AWG 3+1 Outdoor CCTV Cable 10M |

| 471 | 0.2 | 94.2 |
| Junction Box | Square IP65 Junction Box for CCTV |

https://www.amazon.in/Inches-Junction-Surveillance-Security-Cameras/dp/B09KRPWT44/

| 405 | 0.25 | 101.25 |
| | | | | Total Cost | 1152.1 |

Notes:

  1. Most of the smaller items on that list have a minimum order quantity of 10.

  2. The POE splitter drops down to under 250 each if you buy a pack of 5.

  3. The junction boxes are much cheaper locally (about half price).

  4. M3 screws, 5mm spacers and self tapping screws are not listed.

  5. Consumables like solder, flux and assets like tools are not listed.

  6. POE cable, POE switch, Wi-Fi access point are not listed.

For the meter:

Part Full Name URL Price with GST Quantity Total Cost
PCB, Prototyping 2 x 8 cm Universal PCB Prototype Board Double-Sided

https://robu.in/product/2-x-8-cm-universal-pcb-prototype-board-double-sided/

| 30 | 0.5 | 15 |
| Connector, USB | USB A-type Plug Male PCB R/A Connector |

https://robu.in/product/usb-a-type-plug-male-pcb-r-a-connector-pack-of-5/

| 35 | 0.2 | 7 |
| Header, Female | 2.54mm 1×40 Pin Female Single Row Header Strip |

https://robu.in/product/2-54mm-1x40-pin-female-single-row-header-strip-pack-of-10/

| 199 | 0.05 | 9.95 |
| Header, Male | 2.54mm 1×40 Pin Male Single Row Straight Long Header Strip |

https://robu.in/product/2-54mm-1x40-pin-male-single-row-straight-long-header-strip-pack-of-3/

| 157 | 0.03 | 4.71 |
| Voltage Regulator | AMS1117-3.3 LDO 800MA DC 5V to 3.3V Step-Down Power Supply Module |

https://robu.in/product/ams1117-3-3-ldo-800ma-dc-5v-3-3v-step-power-supply-module/

| 23 | 1 | 23 |
| Wi-Fi Module | ESP-01 ESP8266 Serial WIFI Wireless Transceiver Module |

https://robu.in/product/esp-01-esp8266-serial-wifi-wireless-transceiver-module/

| 105 | 1 | 105 |
| LED Bar Module | SeeedStudio Grove LED Bar v2.0 |

https://robu.in/product/grove-led-bar-v2-0/

| 449 | 1 | 449 |
| | | | | Total Cost | 613.66 |

Notes:

  1. If you decide on a four-digit numeric display module instead of the led bar module, you’d save Rs 400:

https://robu.in/product/tm1637-4-bits-digital-tube-led-display-module-clock-display-arduino/

  1. Consumables like wires are not listed.

  2. USB charger is not listed

It’s the most impressive piece of software I’ve ever had the pleasure of working with.

However, most Node-RED forums where you can discuss and ask questions have purists that look down upon my usage of the function node.

The philosophy they hold is that a flow should not contain any lines of code, just nodes.

13 Likes

Impressive !! Thanks for sharing

2 Likes

Excellent, There’s always something to learn every time i visit TE. Thank you for sharing your work.

1 Like

Joining a PCB-mount male connection with a wire-type male connector makes for an inexpensive USB type-A male-to-male adapter:

To avoid melting the plastic, lower the soldering temperature to 250C:

And this makes for an easy way to power a LOLIN/AMICA ESP8266 NodeMCU module:

The Ground, VCC, D4/GPIO2 and D3/GPIO0 pins line up perfectly to power/control the TM1637 module:

The headers I used were taller than usual, at 16mm or 17mm, this lets me bend them slightly for centering the display:

Looks pretty spiffy:

More updates later.

4 Likes

Or you could just add a bunch of other stuff and come up with this:

The rear:

The sandwich:

A better look at the pins used, the temperature sensor is a AHT10:

This IR sensor is used as a non-contact button to turn on the water pump:

And this led is used as a indicator to show if the water pump is on:

A 5.1K resistor for the led:

It’s a really nice led:

quartzcomponents describes this led as a 8mm diamond.

And the video of it in action (the animations were fun to code):

5 Likes

Great job, I can sense you are having extreme fun, doing these things and watching all your hardware and software working like clockwork is very rewarding in the end.

1 Like

Another way to visualize the same data, with pixel graphics and custom fonts:

5 Likes

It wasn’t effective. Water found a way in so the POE splitter shorted and died, it’s a pretty gross photo so I haven’t attached it in this post, it’s below.

I got another splitter, gently tapped at the seams with a hammer until the housing separated and then heatshrinked it just because I could.

This time the connector will be inside the box and hopefully fare better:


Attachments:

Fog, condensation, moisture can still get inside, a full proof solution could be a potting compound which you pour in the box and let it dry.

1 Like

damn, great work. I really feel like doing this now. How can someone who has no experience on coding build this? are there any video guides to just follow?
Also, a little addon, I don’t know if this will be too much work, but can we make it so after tank drops to certain level or at a specific time the pump turns on and off by taking into account these readings? I want to make it completely automated so that I wouldn’t even need to keep an eye on the pump! There should also be some fail safe if the sensor were to stop working all of the sudden, like automatically shutting down of pump if water level isn’t going up for the given specific time frame.
I don’t know if this will be too much work but please brainstorm on it!
Again I loved this idea, great work!

One can start with arduino uno, it’s the most popular and easy to learn. Lot of tutorials are available with code, tons of videos on youtube for free. I recommend the official starter kit it has everything to get you going. [Here ](’

https://www.uio.no/studier/emner/matnat/ifi/IN1060/v21/arduino/arduino-projects-book.pdf

)is the PDF of the book that comes with it if want to get a feel for this thing.

It can be done for sure, you can control anything with given parameters. But this can get complex specially for beginner due to reasons

  • Involves AC voltage which is dangerous to be tinkering with.

  • Pump motors are high current they might need a special relay to turn them on and off, and that special relay might need special circuit of it’s own.

  • Turning ON the pump when water level is low is easy but we also have to check if it water is available to pump. A water detection sensor before the pump might be needed.

  • In case water level sensor fails there must be a another manual water level detection method that turns OFF the pump if it is ON when water level reaches max or when water goes out in middle of pumping.

When you use the words “all done automatically” it usually pulls in a lot of edge cases which the product has to take care of and this shoots up the over all price.

[HR][/HR]

I am sure there must be a off the shelf product that you can buy that does all this, so you don’t have to re-invent the wheel.

2 Likes