I've been looking for a monitor for my oil tank for a while now. I currently have an old Watchman device that reports how much oil remains in 10% increments. Over the past two years it has proven to be very unreliable and has stopped working completely now.
I have Domoticz running on a Raspberry Pi and I wanted something that would integrate with this. I searched for Z-Wave, ZigBee, RFX etc. compatible devices, but couldn't find anything. I then looked for Internet enabled devices and all I found was one product by Watchman. It still only measures in 10% increments but for a (quite expensive) monthly subscription you can have the device send the data back to the companies servers and notify you via a smartphone app if your oil is low. Needless to say I was disappointed, so I decided to make my own.
Hardware
I grabbed a spare Raspberry Pi, ordered a breadboard (£3), a HC-SR04 sensor (£3), some wires and got to work. The result so far is a prototype that looks like this:
Programming
After getting that working I wrote a Python script to use the ultra-sonic sensor/Raspberry Pi to measure the volume of heating oil remaining in an oil tank and send the value to a Domoticz virtual device.
The script can be found here - https://github.com/kivster/oil-tank-monitor
The script sends N number of pings from the HC-SR04 ultrasonic sensor connected to the GPIO pins on a Raspberry Pi. It measures the time between sending and receiving the ping. If it don't get a successful ping, it takes the measurement again.
It then takes each ping time and calculates the distance to the top of the oil. I found that measurements would fluctuate based on how hot the room was (I'm testing this in my house). I remembered from GCSE physics that the speed of sound changes when air temperature changes. To address this I factored in the current air temperature for speed of sound calculations.
Each calculated distance to the top of the oil is added to an array of distances. The array is sorted in ascending order and outliers eliminated by keeping only the "middle" third of distances in the array. An average is taken of the middle third of distances. The averaged oil tank space is subtracted from the height of the tank in order to calculate the height of the oil. With the height of the oil the litres of oil and percentage of oil remaining can be calculated.
Right now the oil tank capacity is hard-coded and I fudge the percentage of oil remaining from that, without considering the tank shape. The next thing to do is to add accurate calculations of oil volume remaining in my tank based on the shape of the tank. I have a very odd shaped tank, so this is going to be tricky! Calculating this for cuboid tanks would be easy so I'm going to start by adding the calculations for those, followed by cylindrical and oval tanks.
Finally the script sends the value by json to a virtual device on a Domoticz home automation server, where it is plotted on a graph and can be alerted on.
I'm currently working on a case for this device and a way of attaching it to a threaded hole on the tank. I'm thinking of using UPVC plumbing supplies to come up with something. Also, depending on how successful I am at powering this, I may consider an Arduino version in the future.
I'll be posting progress here and on my GitHub repo. If anyone has questions about the hardware or software I'd be happy to answer them. Once I have a final design, I may even consider making these for people.