Tank level Monitor - contact free

Tank level monitoring the Internet of Things on Board (IoToB) way

After test with the fixed aluminium tank it turned out that the sensors were unable to get readings through the many mm thick aluminium. A major setback. A new sensor claimed to get a measurements through the tank wall. As this is also a on/off the ESP board and software should be more or less the same. The new sensor did not manage to get a reading through the 5mm thick aluminum wall so I had to buy a commercial solution from Gobious. It's reasonable priced compared to a cost of about 22 Euro for sensors that failed to read through metal walls, three of these sensors cost on third of the Gobious solution. The Gobious works fine and comes with a nice panel mounted on the wall above the toilet, it's however, not a build it yourself solution. My solution with simpler sensors works nice for plastic tanks.

Building the actual server for installation on board. The picture below show progress in the build process. Most parts are in-house, only the connectors on the circuit board to the

are missing. The size of the box is rather small and all parts and connections need to be fitted with care. The module used is a ESP8266 based module ESP12E, for more information se the Wikipedia page on ESP8266.

The power converter on the left not only isolating the 12V service supply, but also provide 5V for the ESP-12 module and sensors. It's a 3W converter, enough to power the wifi at peak power during initialization, in addition to the four inductive sensors.

The picture show the fitting the box, circuit board, a simple vero board from China. Template for the holes are important, any mistake and the holes end up as they did here. Next

step is to fit a capacitor to the 5V rails and the 12V intake lines and fit it all into the box. The picture to the far right show the finished box.

The picture to the right show the finished product with four inductive sensors ready to be installed onboard. The four sensor cables are not waterproofed as this will sit high up in the technical room close to the holding tank. If this gets flooded I have more serious problems at my hand than the level of the blackwater tank.

The software to go with this box is found on the github page. In addition some schematics and more detailed technical documentation are also included there. The software lists the pins on the ESP card, some modifications of input pins were needed in order for everything to work correctly. If you plan to replicate this, please the documentation and possibly read the comment in the source code.

Next step is installation to measure the blackwater tank on board. Non contact methods are the only sensible method for measuring the level of the blackwater holding tank.

Older - prototyping and development

The sensors and measurements are just like before as described below. However, the sensors are connected to an ESP2866 based ESP12E module. This module sends the results using the SignalK protocol to the OpenPlotter SignalK server. In this was there are no cables to draw around the boat and no problems with isolation from the high power 12 Volt service supply. The IoToB unit is totally isolated from the center yacht server (running OpenPlotter). The picture below show a prototype using a ESP12E module. It currently use only 3 inputs leaving pins left to drive a RGB LED, which show the levels in colour. The indicator LED is used to test the usage of the non common GPIO ports like TX and RX etc.

The code to read the sensors and send the message to SignalK is uploaded to github together with all the other sketches.

Hardware for monitoring

Monitor water level with a non intrusive detector like this, do a search for "Non-contact Level Switch" at aliexpress.com. It's a simple on or off device so two or more are needed. One at half and one at quater (or 3/4) full depending on fresh or waste water. On and off sensors interface very easy to the GPIO pins on the Pi, then it's just a question of reading the pins and display the water level. With the relatively low prices and power consumption one might place an array of these to get finer grain readings. The specifications use the term inductive and also used water, both suggest that they will only work with water. I have not tested them with diesel or oil.

A negative might be that it will require a number of IO pins on the server, and the RPi has a limited set of these. An alternative might be to use a small Arduino board to collect the signals and send them over a serial line to the server.

The picture at the left show the sensor responding to the water (+some fruit juice) added to the glass. These nice sensors turn on or off when water is in proximity or not. One might easy add two or more of these to monitor the water level in fresh, grey or blackwater tanks. The more sensors the more accurate estimate of the filling level. It's evident that the sensor is triggered by convenient red led.

Adding extra IO ports to Raspberry or ESP12 module.

However, adding more sensors require more IO connections of which there are a limited number of on the Raspberry.

Luckily, there is a nice and simple solution to this. The chip called PCF8574 from Texas Instruments. This chip provide 8 digital IO outputs and attach to the I2C bus. With the possibility to set 8 different I2C addresses a total of 64 digital bidirectional IO pins become available. There is a sister chip (see application sheet using PCF8574A) that has a different I2C start address (0x38 as opposed the the 0x20 for the 8574) which can bring it up 16 chips and 128 IO ports in total. This provide a solution to the limited number of IO pins and a range of sensors can be fitted on each tank.

The chip it self is easy to use, but it's more practical with a module that contains pins etc for simple connections. The picture on the right show a prototype setup used for testing


the hardware. It also provide the ports to plug them together in a train, in principle up to 8 PCF8572 and 8 PCF8574A to a total of 16 yielding a total of 128 IO pins. Any more than this need a computer system like Arduino which can do the job as a multiplexer.

Programming this device is fairly simple as there are only on and off pins to be set. Below is a simple python (v2.7) code to set pin one on and off and to read the other pins and display their state. From this it should be a simple job integrating this into measurement of tanks a was the intention of this chapter.

import smbus,time

# Use I2C bus 1 and instanciate an object

bus = smbus.SMBus(1)

# PCF8574A address, 0x38(56) and 0xFF All pins configured as inputs

bus.write_byte(0x38, 0xFF)

while True:

data = bus.read_byte(0x38)

data = (data & 0xFF)


for i in range(0, 8) :

if (data & (2 ** i)) == 0 :

print "I/O Pin %d State is LOW" %(i)

else :

print "I/O Pin %d State is HIGH" %(i)



This code uses pin zero to turn a led on and off to indicate that the hardware is working, hence the 0xfe word written.

Typical output of the code above, pin 1 is connected by a jumper to 0V so it's always low :

I/O Pin 0 State is HIGH

I/O Pin 1 State is LOW

I/O Pin 2 State is HIGH

I/O Pin 3 State is HIGH

I/O Pin 4 State is HIGH

I/O Pin 5 State is HIGH

I/O Pin 6 State is HIGH

I/O Pin 7 State is HIGH


Integration into Openplotter should be fairly simple, my first attempt is just writing a simple Python script that reads the sensors and send the results off to SignalK without using the framework of Openplotter, the code is found at github.

Next step would be to integrate the PCF8574 port extender chip into Openplotter. It need a proper config file to deal with all the different variants of IO pins. Using this chip it's possible to have up to 128 digital IO pins. This can cover far more than just tank level monitoring.