Measure Oil Level (or any liquid) and alert - hardware + firmware/code

@ventz, This is a neat project.
I copied/pasted the chart from the Tank Size WebPage that @thefloyd linked to Here, straight into MS Excel and created a trendline for each tank.

You could use a #Define Statement (or similar) at the beginning of the Code for the User to Select their Tank Size, and calculate the gallons directly in the Loop.

y = Gallons ,  x = Inches
Below are the Equations from Excel:
TANK :  EQUATION
275H :  y = 10.909x - 10.023
275V :  y = 6.8046x - 13.626
500  :  y = -0.005x3 + 0.3626x2 + 4.9946x - 4.7142
550  :  y = -0.0056x3 + 0.3993x2 + 5.2575x - 4.2845
1000 :  y = -0.0099x3 + 0.7115x2 + 9.8384x - 8.7038

Decent fits for a quick stab…

1 Like

Nice!

@Rftop - this is awesome. Thanks!
(I’ll definitely give you guys credit when I modify the firmware eventually with the equations!)

The other thing I need to figure out is the “base” distance away from the sensor that ends up being the “full”.
What makes this hard is that full (on a 275 tank for example) could be anywhere from 250 to 266 gallons. Usually they shoot for 250-255 but you never know. So I need to subtract the distance between the sensor height and the “top” of the oil line and call that the base start.

ps: this is why I love the Particle community – it’s because of things like this! :slight_smile:

I think the bottom of the height range is more important to the user than the top (“full”).
Once you’ve measured the height of Sensor Above the floor of the tank (45.9" in your code), you are calculating true Gallons Remaining, regardless of what’s considered “full”.

It’s completely valid to report 255 gallons remaining (of a 275 tank) as 93% full, instead of 100%.
You need the extra 4" at the top of the tank for the Sonar’s Min Distance anyway… take the win.

Thanks again for sharing your project !

Do you guys think Oil heating is used more in some parts of the country than others? Obviously, its not going to be needed as much in warmer parts of the country but I’m just curious how widely used it is today. I’m used to seeing Propane tanks around here.

@RWB - Absolutely. In fact, from the research my co-worker did, that’s exactly the case (propane if natural gas is not available/if you are “disconnected” from city/town grid)

The oil market for home heating is super small per the US department of energy. This is a great summary:
https://www.eia.gov/energyexplained/index.cfm?page=heating_oil_use

Some info pulled out:

  • “About 6 million households in the United States use heating oil as their main space heating fuel”
  • “Most of the U.S. households that use heating oil are located in the Northeast”

It essentially comes down to these states:

Wow, that’s way less than I expected to see :slight_smile:

Thanks for the info!

Most people just use a cheap $1 sonar sensor, the NewPing library and a $4 wifi microcontroller to measure oil level. You can also do this with a Photon. I have maybe a thousand users doing this. VERY popular, and has been for about 5 years now.

Do you have a design you share with others? Or where can we get more info on what you’re talking about?

Sounds interesting.

It’s just a simple cheap HC-SR04 or like sensor and using the NewPing library:

https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home

There’s not much in the way of design. Connect the sensor, use one of the sample sketches, and expand it to use Photon to communicate. I typically make custom react native mobile apps to interface with my Photon IoT projects to get real-time stats, controls, and notifications.

For an example, I have an Android app on the play store (search for RestroomAvailability) that ties in with Photon. That app uses magnetic switches for input, but it’s just a slight change to interface with a sonar sensor instead.

On the NewPing forum, there’s lots of conversations about using it to measure tank levels. There’s a link to the forum in the above wiki link.

1 Like

@teckel - Those (HC-SR04 ) are what I am using in my project too (this post).

If you get them as “one unit” on amazon, they can be $7-10. If you get them in a science lab pack of 5-10 units, they can be as low as a few bucks.

It seems like there are a few nice benefits to the newping library, and looks like @ScruffR and others ported it to Particle:


(but from that post, not sure if it’s actually working as expected)

I’ll check it out.

It’s interesting because I know others have done this to measure water levels, but when I searched, I found only 2 people having reported “functional/semi-full” solutions. One guy who did something very similar to me with PVC for the build/mounting + an arduino (if I remember, this was the hack-a-day thing – I also think he ran the sensor to the tank, and everything else was external w/ cat5), and another person who used the cheap ESP8266 but to measure water level in a fish tank. Obviously the concept is the same, but I didn’t really find much around oil – especially the tank measurements encoded (as data/table/function/etc).

To your point - yes, you can get an esp for ~$4-5, but usually from china and then you wait+shipping costs. If you get a ton of them in bulk, it gets closer to $3-4 delivered. I know you can get something like this for $8-9: https://www.amazon.com/HiLetgo-Internet-Development-Wireless-Micropython/dp/B010O1G1ES/ref=sr_1_3, but then you have to deal with everything from wifi connectivity, tethered firmware updates, and writing all of your own REST notifications, variable publishing/retrieval/etc. It’s just too much of a pain for saving $8-10.

For me at least, the Photon is well worth the 40-60% cost purely for the remote API/remote updates/ease of interacting with remote points/REST/etc. If that was not available, I would probably go for the HiLetgo which seems in between the Photon and some of the more “raw” esp8266 (from banggood, ebay, etc)

Anyway, the concept (or code) is not really unique. I was just hoping to achieve 2 things with the project/post:
1.) provide a cheap way for someone to build an attachment for their oil tank (PVC build) which is semi elegant and compcast
2.) provide all of the code so that someone could just copy and paste it and start getting notifications about their oil levels without having to worry about any specifics.

It pained me to see companies charging hundreds of dollars for the hardware solution + a monthly fee (when over ethernet) for the “data/notification service”.

1 Like

The NewPing library nativity supports Particle, as I’m a Particle Photon user as well.

I would also use a Photon instead of an EPS8266. Also makes it uber simple to make mobile apps/Alexa skills to interface with. But if making a marketable product, EPS8266 would be the way to go to greatly lower costs.

But, HC-SR04 sensors are less than $1 on eBay. An even better sensor is the US-100 at $3. Basically, an entire system can be had for $5 if you know the absolute basics of microcontrollers and programming.

3 Likes

@teckel - Oh nice. I’ll switch over to it then.

What’s better about the US-100? (Is it significantly better? - I see them on available on Amazon and can pick up a a few)

Well this is interesting – from that article, and the test they conducted, and I quote:

“The US-100 sensor seems to behave worse than the HC-SR04, although none of them can be considered accurate”

The only difference I saw was the temp compensation on the US-100 when you use Serial data mode.

What I and others have experienced is that the US-100 yields better results in worse conditions. For example, when being used as a ground sensor in a quadcopter. The US-100 is a good margin better than the HC-SR04 in this situation. Also, there’s been a TON of defective HC-SR04 sensors in the past as everyone and their brother makes them in China with zero quality control. So the US-100 also work when some HC-SR04’s don’t. I have over 20 ultrasonic sensors and all kinds of different models, so I’ve seen my share of issues.

3 Likes

That’s good to know. Yea, I ran into something similar with the HC-SR04 – the really cheap ones had a huge failure rate (3-4/10). At least most came DOA, versus dying while using them :slight_smile:
At the end - I found that the science/lab companies that sold them were pretty reliable. From the last bag I got (I think 8-10), all seem to work so far.

On a different topic - someone on instructable specifically asked about handling calculations in sound variation for extreme temperature drops, so I’ll mention this sensor (US-100) since it has a built-in temperature sensor and automatically handles that.

Made some pretty significant improvements to the code if anyone is following this/has created their own.

summary:
1.) Found a bug in the calculation table - fixed
2.) large cleanup of the alerts and added so that at each level it nulls the previous alerts – just in case you reboot/deep-sleep and flush the previous data
3.) added a re-fill alert, so that you will know when they automatically re-fill your oil

1 Like