Tank level Monitor - contact free

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

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 monotoring 

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 tog
ether 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.  

Demo using SignalK display

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.