Oil tank depth gauge

32 replies [Last post]
magill
Offline
Joined: 27 Apr 2012

Hi
I'm currently putting together a roomnode with an ultrasonic module in an effort to measure oil depth in my tank.
I have modified the roomnode.pde to accomodate the module and am using the "light" part of the payload to transfer the data (in litres).I am getting sensible readings for lower values (over my kitchen sink) but this being a byte variable is limited to 255. I could factor it by say 4 and then correct at the rx end but that is not always possible. I've messed with changing the variable type but am getting strange results. I'm not great with linux and don't know where to look for the software that interprets the incoming data.I could also send percentage full ie 0 to 100% but am still curious as to how larger numbers could be accomodated.
thanks
John

g7pkf
Offline
United Kingdom
Joined: 11 Jan 2011
Cannot help you BUt

this is something i am very interested in.

 

especially now oil is in use :)

brett
Offline
Providence, United States
Joined: 9 Jan 2010
tweaking the resolution of data sent from a node.

You are almost there.

-From the RoomNode.pde Sketch you would tweak the number of bits from 8 to say 16.
struct {
    int oil:16;     // oil sensor: 0..32767
    byte moved :1;  // motion detector: 0..1
    byte humi  :7;  // humidity: 0..100
    int temp   :10; // temperature: -500..+500 (tenths)
    byte lobat :1;  // supply voltage dropped under 3.1V: 0..1
} payload;

From the roomNode.lua code (The receiver)

local oil, mo, hu, te, lo = jeenode.bitslicer(data,16,1,7,-10, 1)

If you want to move from a BYTE to say a WORD then just change the "byte light" and increase the number of bits in the receiver too - something like this and make this receive a new node type by renaming the classes and filename.

Like what I recommended here when I was talking about a new "boilerNode"

http://www.homeautomationhub.com/content/temperature-measurement-hahnodes

Brett

magill
Offline
Joined: 27 Apr 2012
oil tank gauge
Thanks for that Brett
I got it sorted. It's working well and I can give details to anyone who's interested.
I attach a photo. The ultrasonic sensor is HC-SR04 from Ebay. I've also added a humidity/temp module (DHT 22 also from Ebay)
AttachmentSize
OilTankSensor.jpg 31.61 KB
g7pkf
Offline
United Kingdom
Joined: 11 Jan 2011
Very interested

any further info appreciated. (wiring code etc)

 

Parts ordered from ebay :) and roomnode from Derek :)

Dean

magill
Offline
Joined: 27 Apr 2012
oil tank

Hi Dean
I attach the 3 files you need plus a rough drawing of the wiring required.
OilNodeApplet.lua and oilnode.lua go in the plugboard folder.
roomnode_oiltank.pde sketch to be uploaded to your roomnode.(you'll need DHT22 library)
You need to change the tank dimensions.Hope it is rectangular as the calculation for cylindrical tanks is quite complex.
I had to enlarge the hole in the top of my oil tank to accomodate the ultrasonic sensor. I have temporarilly put all the kit in a plastic lunch box with an airtight lid until I come up with a more permanent housing. The humi/temp sensor needs to be exposed to the elements but sheltered from direct rain.
I have written an android app for my phone to monitor these parameters, along with heating etc.
I'm happy to help with any queries.
Good luck
John
Update... there may be issues with battery life. Might have to consider larger battery pack or run 5V from a PSU in adjacent garage.

AttachmentSize
OilNode.jpg 9.59 KB
oilnode.lua 1.01 KB
OilNodeApplet.lua 779 bytes
roomnode_oiltank.pde_.txt 5.81 KB
g7pkf
Offline
United Kingdom
Joined: 11 Jan 2011
Thank you

The roomnode arrived yesterday ()thanks Derek() still waiting for sensors from china :)

Electronics is "my thing" coding isnt but i do have a programmer (and associated bit that goes with it) and AVR studio 4

 

and i have no idea what the DHT22 libary is (but i have downloaded it :)

 

all i have ever used the programmer for is to copy chips (when firmware updates come out) and i simply read the hex eprom and elf files then write them out to the new chip.

 

Looks like i am going to have to start reading how to get the code into the Chip :)

My tank is a 2500L bunded so its sort of rectangular but i am not too worried if its not 100% accurate-got to be better than my watchman with 10bars on it.

 

Dean

magill
Offline
Joined: 27 Apr 2012
oil tank gauge

Hi Dean
You are now into the Arduino world and need to download the free "Arduino development environment" at

http://arduino.cc/en/Main/Software. I'm using version 0023. You can program the roomnode directly from your PC using the

FTDI cable and choosing "UNO" as your board. Before you do this set up your node ID, RF etc. I only used the DHT22

because I had one, you may choose to ignore it.(I'm still messing with the code as the present setup is still eating

batteries)
I am very happy to program the chip for you if you like.
John
BTW what shape is your tank? Do you have it's inner dimensions.

g7pkf
Offline
United Kingdom
Joined: 11 Jan 2011
Thank you

Going to send you a chip. BUT i am also going to try and program my own and then compare.

 

can you send me your address? (will include a sae) my email is dean AT packetradio.co.uk

 

my tank is apx 2.2*1.1*1.1 Metres (2500L) and this is my second roomnode.

 

No rush still waiting for china stuff.

 

to reduce power could you not restrict TX to once an hour to help? (and increase TTL ) luckily i have power fairly near my tank :)

magill
Offline
Joined: 27 Apr 2012
oil tank gauge
Dean
I attach new (rough) drawing of the wiring. The transistors are any old NPN and PNP.
The purpose of these is to switch on the sensor only when doing measurements using the AIO pin to do this. Transistors are required because sensor is a 5V device.I also feed the temp/humi sensor from AIO on port 4 again only when reading values. Finally I have added a potential divider on port 2 which will return the exact battery voltage (using a scale factor in the sketch) I have reduced the measurement interval to 30 mins
John
AttachmentSize
oilnode.lua 1.03 KB
OilNodeApplet.lua 782 bytes
oil-tank.pdf 16.82 KB
g7pkf
Offline
United Kingdom
Joined: 11 Jan 2011
Thank you

Still debating if to go down the battery or run a cable route...

thinking the battery route for testing and cable route as a pernament soloution.

 

will let you know how i get on and will take photo's of construction.

 

Dean

magill
Offline
Joined: 27 Apr 2012
oil tank gauge

The sketch for the chip is different as it has to accomodate the transistor interface.

If you think that eventually you will run power to it, I will burn that version and you can test it with a battery pack anyway.

John

g7pkf
Offline
United Kingdom
Joined: 11 Jan 2011
John/Derek can you confirm please

Check my wiring?

 

seems my ultrasonic "looks" different to yours.

 

http://www.packetradio.co.uk/gallery/index.php/HAH/vi-Gallery-Image-7203...

 

And Derek have i got the electrolytic round the right way? just being 100% certain :)

 

http://www.packetradio.co.uk/gallery/index.php/HAH/vi-Gallery-Image

magill
Offline
Joined: 27 Apr 2012
looks good

The sensor seems to work down to approx 4.3 v but spec is 5v. I put a 10k resistor in the echo lead to protect the 328 chip. I'm not sure if it is necessary.

John

g7pkf
Offline
United Kingdom
Joined: 11 Jan 2011
Hmm did you spot the delibarate mistake?

I have wired all the sensors to the wrong side of the board :(

g7pkf
Offline
United Kingdom
Joined: 11 Jan 2011
Hmm

Somethink strange on XFX viewer.

 

http://www.packetradio.co.uk/gallery/index.php/HAH/photos/hahnode2

 

John i must ask do you have your oil tank in your living room?

 

Joking aside been testing and it looks really good, values are pretty accurate.

 

now all i need to do is weatherproof box it, run cable set it up on Gui and explain to wife 0=no heating :)

 

Dean

magill
Offline
Joined: 27 Apr 2012
oil tank gauge

Dean

I think I will move it to the living room so that I can observe it to see where all the oil is disappearing to.

I'm glad you have it sorted. You can tether it to COSM and watch the level drop!

John

g7pkf
Offline
United Kingdom
Joined: 11 Jan 2011
Thank you John

Its working well :) just installed it on the oil tank this afternoon-late.

 

one question do you find oil level drops when the temp drops? only by 20L from a 16degree to 10degree temp change?

 

what/how do you find the accuracy over time/temp?

 

Once again thank you. running on 3 d cells at the moment as it was getting too cold to run a cable tonight (and SWMBO would have wabbled- she was iffy about me drilling holes in tank lid as it was! )

 

Dean

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
Thermal contraction?

Dean, is this possibly just thermal contraction?! Not sure what the thermal expansion coefficient is for fuel oil but on a 2500l tank you are only seeing <1% change on 6degrees which doesn't sound unreasonable to me. If this is the case you should be able to factor this out to give you a reading at a fixed temp?!

just a thought. 

 

Garry

magill
Offline
Joined: 27 Apr 2012
Garry is quite right. The

Garry is quite right. The thermal coefficient of expansion of diesel is 800 * 10 -6 which means that the fuel will expand by .08% per 10 degree rise.

Dean if you want I can modify the code to factor this in.

John

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
I make it

0.8% change in volume for 10oC change, but either way I'm sure this is the cause and as John says easy to factor out. 

 

Factor = 0.0008 per oC

Factor for 10oC = 0.008 = 0.8%

 

i might be wrong it's been a while since i did stuff like this in anger ;) 

magill
Offline
Joined: 27 Apr 2012
Garry you're quite right it

Garry you're quite right it is .08% per degree and 0.8 for 10 degrees. Anyway that equates to 16 litre expansion of 2000 litres with 10 degree rise.

There are other factors eg expansion of container, speed of sound v temp (for echo) and ultimately the quality of the cheap and cheerful device.

Anyway I can unhappily watch my oil drain away on my phone, Joggler, and for a real treat look at the COSM graph.

John

PS You could always display the cost in £s intead of litres and maybe her indoors will turn the heating down!

g7pkf
Offline
United Kingdom
Joined: 11 Jan 2011
PS You could always display

PS You could always display the cost in £s intead of litres and maybe her indoors will turn the heating down!

 

I wish.

 

Yep forgot about expansion of liquids-set fire to physics lab when at school, used a bunsun instead of hot water-the petroleum went up well big hole in roof day off school!!

 

thanks all, quite happy to watch it expand and fall-might put a heater undertank so it uses less fuel---(JOKE)

 

 

Dean

magill
Offline
Joined: 27 Apr 2012
correction factor

Just realized you can add this correction factor to the "oilnode.lua" the script now is:

module("oilnode", package.seeall)

require("xap.bsc")
jeenode = require("xap.jeenode")
Nodule = jeenode.Nodule
class = require("pl.class").class

class.OilNode(Nodule)

-- create BSC endpoints
function OilNode:build(...)
   Nodule.build(self, ...)

   -- Creates the endpoints: self[key] as in self.light, self.moved etc..
   -- If the user has configured that they want them that is.
   self:add {key="oil", direction=bsc.INPUT, type=bsc.STREAM}
   self:add {key="moved", direction=bsc.INPUT, type=bsc.BINARY}
   self:add {key="humi", direction=bsc.INPUT, type=bsc.STREAM}
   self:add {key="temp",  direction=bsc.INPUT, type=bsc.STREAM}
   self:add {key="lobat", direction=bsc.INPUT, type=bsc.BINARY}
end

function OilNode:process(data)

   local oi, mo, hu, te, lo = jeenode.bitslicer(data,16,1,7,-10, 1)
   te = te  / 10
    oi=math.floor(oi/(1+(.0008*te)))
   -- The keys here must match the key values from the self:add{key=x}
   Nodule.process(self,{oil=oi,moved=mo,humi=hu,temp=te,lobat=lo})
end

 

notice the new line

 oi=math.floor(oi/(1+(.0008*te)))+0

the "+0" bit is where you can put a plus or minus value to correct for inaccurate sensor height.

good luck

John

g7pkf
Offline
United Kingdom
Joined: 11 Jan 2011
Thanks John-now got it live on cosm

It now live on Cosm

 

https://cosm.com/feeds/43841

brett
Offline
Providence, United States
Joined: 9 Jan 2010
And a hell of a lot cheaper

And a hell of a lot cheaper and capable than this water ultrasonic level meter too !

http://www.jaycar.com.au/productView.asp?ID=XC0331

I say POOEY too this item and HELLO JeeNode.

Brett

magill
Offline
Joined: 27 Apr 2012
lua code broken

Brett

If you get a minute, it will probably be obvious to you but on upgrade I get

lua: /etc/plugboard/oilnode.lua:8: attempt to call field 'OilNode' (a nil value)
stack traceback:
	/etc/plugboard/oilnode.lua:8: in main chunk
	[C]: in function 'require'
	/etc/plugboard/JMjeenodeApplet.lua:11: in main chunk
	[C]: in function 'require'
	/etc_ro_fs/plugboard/plugboard.lua:23: in function 'fun'
	/usr/share/lua/5.1/pl/tablex.lua:365: in function 'foreach'
	/etc_ro_fs/plugboard/plugboard.lua:75: in main chunk
	[C]: ?

I attach offending luas
thanks
John
AttachmentSize
JMjeenodeApplet.lua 886 bytes
oilnode.lua 1.06 KB
brett
Offline
Providence, United States
Joined: 9 Jan 2010
Depending on what build you
Depending on what build you are on as you never indicated (what after the upgrade meant)

If you are on 307

class = require("pl.class").class If you are on the BETA 307.2 then its like this

class = require("pl.class")

The penlight library had some internal changes when I uplifted it.

Brett
magill
Offline
Joined: 27 Apr 2012
a little confused

I have done 2 firmware upgrade in the last 2 weeks. I have 2 liveboxes so I probably got mixed up.

I know I did an upgrade to 307.1 and did the "pl.class" mod. and it worked. I then did another upgrade. Has the firmware regressed to 307

Sorry for my ineptitude

John

brett
Offline
Providence, United States
Joined: 9 Jan 2010
John,You only get the point

John,

You only get the point release BETA's by explicity updating to them.  307.1 has a bug with jeenodes and you need to update to the latest beta 307.2 - normally if you are on a beta is because you want to test something I just released but it may/may not work as expected, as so happened with 307.1 it was a bad build.  307.2 is good (so far).

There are differences in the PL library that may affect hand coded classes.

Brett

g7pkf
Offline
United Kingdom
Joined: 11 Jan 2011
Excellent

Been running this since october.

 

apart from having issues with power (my bad) it is working perfect.

 

the other day i got 500l delivered and my readings went from circa 190 to 700 Litres. so it is pretty accutrate. sometimes it goes full scale 2500 (it blips) but suspect this could be interferance from my watchman (that i run in the same tank)

 

so thank for the excellent desgn etc and if anyone is "thinking" about doing one i thoroughly recommend it.

 

dean

magill
Offline
Joined: 27 Apr 2012
Thanks Dean
My has been working ever since as well except for a period when it suddenly registered zero oil. It's at my holiday home and immediate reaction is that oil has been stolen. Turns out that rain had got into my makeshift container and soaked the electronics. I dried everything thoroughly and all came good!
John
g7pkf
Offline
United Kingdom
Joined: 11 Jan 2011
Mine is not even in a box!

i use the stuff below and coat all exterior sircuit boards with it (pir light etc) the boiler jeenode ultrasonics etc are just coated with this stuff no box!

 

I was doing proof of concept for a work project.

 

i will get round to boxing it one day :)

 

http://cpc.farnell.com/_/rust-guard/rust-guard-500ml/dp/SA02493?Ntt=rust...

Hardware Info