WiFi Oil Tank Monitor

8,723

62

45

Introduction: WiFi Oil Tank Monitor

About: Finding a simple solution to a problem.

    There are several ways to check how much fuel is left in the heating oil tank. The simplest way is to use a dipstick, very accurate but not much fun on a cold winter’s day. Some tanks are fitted with a sight tube, again giving a direct indication of oil level but the tube yellows with age making reading difficult. Worse still, they can be a cause of oil leaks if they are not isolated. Another type of gauge uses a float which drives a dial. Not particularly accurate and the mechanism can seize up over time.

    Those with deep pockets can buy a remote sensor which can be viewed inside the house. A battery driven sensor, usually ultrasonic, transmits the oil depth to a receiver in the house. A stand-alone mains driven receiver may be used to view the oil level or the receiver may be connected to the internet for remote monitoring.
    What is needed is a battery driven WiFi connected sensor that can monitor the tank for years at a time and send email reminders when the oil level gets low. Such a device is described in this Instructable. A sensor measures the oil depth by timing how long it takes for light to reflect back from the oil surface. Every few hours an ESP8266 module polls the sensor and transmits the data to the internet. The free ThingSpeak service is used to display the oil level and send a reminder email when the oil level is low.

    Supplies

    The main components used in this project are listed below. The most expensive item is the depth sensor, a VL53L1X module which can be found online for about $6. Be careful not to select the previous generation VL53L0X, although cheaper, it has inferior performance and requires different software. The other key item is the ESP8266 module. The versions with onboard voltage regulators and USB interface are certainly easier to use but at a premium of higher standby current, not ideal for battery operation. Instead, the basic ESP-07 module is used with the option of an external antenna for extra range.

    The components used in this project are:

    • AA battery holder
    • VL53L1X ranging module
    • BAT43 Shottky diode
    • 2N2222 transistor or similar
    • 100nF capacitor
    • 2 x 5k resistors
    • 1 x 1k resistor
    • 2 x 470 Ohm resistors
    • FT232RL serial adapter module
    • AA size Lithium Thionyl Chloride Battery
    • ESP-07 microcontroller module
    • Sundries, wire, box etc.

    Step 1: Choice of Sensor.

    Ultrasonic sensors are generally used for oil level measurement both commercially and in DIY projects. The readily available ultrasonic HC-SR04 or the newer HS-100 are often used in homemade monitors at a cost of about $1 or so. They worked fine on the bench but gave random readings when pointed down the oil tank vent pipe to locate the oil surface. This was probably due to reflections from the different surfaces in the steel tank, a plastic tank may work better. As an alternative, a VL53L1X Time of Flight optical sensor was tried instead. The readings from the tank were much more stable and so this type of sensor was pursued as the alternative.
    The data sheet for the VL53L1X gives information about the resolution of this sensor under differing measurement conditions, see the picture. Using a sampling time of 200ms gives a resolution of a few mm. No doubt the data sheet numbers where taken under the best possible laboratory conditions and so the sensor was given a quick test to check the resolution. The sensor was positioned over the oil tank vent pipe and a few thousand readings logged using a timing budget of 200 ms. A distribution plot of the readings in the tank confirms that this sensor can measure the oil level with a resolution of about +/- 2mm.
    Over longer time period, there is a daily trend where the oil level drops by a few mm overnight and recovers during the day. The most likely cause being the oil contracting as it cooled overnight and expanding again in the warmth of daytime. Perhaps the story about buying oil by volume on a cold day is true after all.

    Step 2: Circuit Diagram

    The circuit diagram shows how the ESP-07 module is connected to the VL53L1X. An FT242 USB adapter is temporarily connected to the ESP-07 for uploading the software and checking the operation. When the ESP-07 is put into deep sleep, the current drops to about 20 uA, a wake up signal resets the device via the diode.
    It is possible to put the sensor into standby using the XSHUT pin but it proved easier to power the sensor on and off using a transistor. When the ESP-07 wakes up, the sensor is powered up and then switched off once a reading is taken. This also has the advantage of eliminating the VL53L1X standby current.
    When it comes to uploading a new program, a 5k resistor needs holding between ground and GPIO0 as the unit is powered up to enter flash mode. After uploading the code, power the device on and off to run normally.

    Step 3: Battery Power

    A single AA size lithium-thionyl chloride (Li-SOCI2) battery is used to power this project. Searching the internet should find suppliers of this type of battery for as little as $2 each. The big advantage of these batteries is the stable 3.6V over the life of the battery, ideal for powering the ESP8266 chip without requiring extra voltage regulation.
    A tank of heating oil lasts many months and so the oil level only needs checking a few times a day at the most. Measurements on a completed monitor gave a deep sleep current of 22uA. The voltage waveform across a 0.5 Ohm resistor in the battery circuit indicated an average current of 75 mA for 6.9 seconds when awake.
    Over a year, the circuit will use 193 mAh in sleep mode. If oil level measurements are taken every 7 hours then 180 mAh are used every year. On this basis, a 2600 mAh battery will last over 6 years.

    WARNING

    DO NOT HEAT BATTERY TO ABOVE 100'C TO AVOID EXPLOSION. CHECK DATASHEET AS THIS INCLUDES SOLDERING

    Step 4: Software

    The Pololu Arduino VL53L1X library is used to initialise the range sensor and access the distance readings. Code for sending data to ThingSpeak comes from their Moisture Sensor example and some extra code drives the transistor that powers the sensor. The ESP8266 can only deep sleep for up to 70 minutes and wake itself up. The way round this problem is to allow the chip to wake up and immediately put it back to sleep, keeping a count in memory.
    As the monitor connects to your WiFi network, you will need to include your WiFi SSID and password into the code. Also, if you use ThingSpeak, then add your API code.
    The Arduino sketch for uploading is attached in the text file. It will need copying into your Arduino IDE. Before flashing the code, connect GPIO0 to ground via a 5k resistor before powering up.
    The code for connecting the ESP-07 to the WiFI network is widely used in other projects. In this case, a much longer time was needed in the connecting loop for checking that a connection was made. About 500 ms is generally used but 5000 ms was required in this WiFi setup, worth adjusting if there are connection problems.
    Details about receiving email reminders from ThingSpeak are described in the Water Softener Salt Monitor Instructable.

    Step 5: Assembly

    The components for the monitor are connected “birds nest” style around the ESP-07 module, sleeving anything that may short out. The module is easily damaged by too much heat and so these connections need soldering once and quickly. The monitor is assembled in two stages. First of all the sensor and ESP-07 are wired up with a temporary USB adapter to program the ESP-07 using the Arduino IDE. Using a short sleep time of 10 seconds will soon show if the chip is connecting to the WiFi network and sending readings to ThingSpeak. Once everything is working correctly, the chip is reprogrammed with the desired sleep times. The red LED should be levered off the module to minimise current consumption. Also, if an external antenna is connected, the ceramic antenna link also needs removing. Do not operate the chip without an antenna, the power will fry the chip rather than go into space.
    The second stage involves removing the USB adapter and mounting the components in a box.
    The VL53L1X module was mounted inside the tank vent cap using two nylon stand off spacers. Make sure the sensor has a clear view of the oil surface, no leaves, cobwebs or spiders in the way. Also, keep the connecting wire well away from the sensor to prevent spurious reflections.

    Step 6: Installation

    The vent cap is replaced on the oil tank making sure it is level and no obstructions from the sensor to oil surface. The monitor is mounted next to the vent, small magnets were used to keep the box in place. This won’t work with plastic tanks!
    Now sit back and check the oil level from the comfort of your home.

    Battery Powered Contest

    Participated in the
    Battery Powered Contest

    Be the First to Share

      Recommendations

      • CNC and 3D Printing Contest

        CNC and 3D Printing Contest
      • Lamps Challenge

        Lamps Challenge
      • Rice & Grains Challenge

        Rice & Grains Challenge

      45 Comments

      0
      ScoffScoff
      ScoffScoff

      8 months ago

      Hi, thanks so much for a great write up - this is exactly what I've been looking for. I've been trying to avoid a mains powered device due to location, and looking at a solar rechargeable solution was adding a bit too much complexity for me as i am a relative newbie to electronics. I have bought the relevant parts now and am keen to start making some progress. I have a couple of Lolin/Wemos D1 Mini Pros, an ESP32 Devkit V1, and some regular D1 Mini boards. I believe the D1 Mini Pro is going to be the most suitable as I can use the external antenna like you have done with the ESP-07. I understand moving the tiny 0 Ohm resistor is required for this.

      I hope someone can answer just a couple of basic questions for me to help get me started please?
      1) Just double checking - with the BAT43 diode, the colour band (cathode) connects to GPIO16, and the anode connects to the RST pin is that correct? I couldn't see anything in the sketch relating to GPIO16 - how does this work to reset the board? I can see GPIO15 is used to turn on and turn off the VL53L1X in the sketch.
      2) The positive from the battery goes to the 3.3v, yet the battery is 3.6v. Is the 3.3v pi regulated down to 3.3v from the input voltage, like when a 5v USB power source is connected to the USB port of the D1 Mini pro board? If not, I take it the 3.3v pin can tolerate the 3.6v with no issues? Or is this where the 5k and 1k resistor and the capacitor play a part? Sorry this is probably obvious but I am still new and trying to learn about all of this, as well as Home Assistant at the same time, so it's quite a learning curve!
      3) My D1 Mini Pro board doesn't have an 'en' pin, just the RST pin and a physical RST push button. On the reverse of the board is an LDO_EN jumper, which I've read that If bridged, disables the 5v regulator when you want to use battery rather than USB power. If I bridge this jumper, can I just ignore the red wiring going to the en pin in the circuit diagram? Do i need to make any other alterations to wiring?

      Thanks for any help - can't wait to get this put together and start taking readings!

      0
      Itrium
      Itrium

      Reply 8 months ago

      Hi, The ESP-07 was used because it is a skeleton board with no extra components like the USB socket interface, all which take power. Although they would work, the battery would not last long. The big problem with the 07 board is having to use an external UART to program up the 07.
      The diode is correct as you describe it. Pin GPIO16 is the default pin used by the ESP8266 to provide the wakeup signal. This pin sends a pulse to the reset pin to start up the device.
      The ESP8266 maximum supply voltage is 3.6V. Strictly speaking, this is running on the limit but it works for me.
      If you are new to using these ESP8266 boards, could I suggest you try a basic setup with one of the boards you have and try reading the sensor without all the sleep/ wakeup stuff. You will be able to see if it works in your tank for example. Then you could see if the WiFi connects ok. You may even decide it is simpler to run a 5V supply to the unit and get continuous readings rather than every few hours.
      Enjoy the journey…


      0
      ScoffScoff
      ScoffScoff

      Reply 8 months ago

      Hi, thanks very much for your reply and all the information provided, that's a big help. I may well pick up an ESP-07 board or this particular project and keep my other boards for other projects - I'm sure there will be more! Due to the location of the tank I can't get a mains supply to power the board so I'm going to need to use the battery solution. While I wait on the ESP-07 board arriving, I'm going to look at how to physically mount the sensor - I'm thinking about using the 6" plastic inspection cover inside the main large access cover (my tank is a plastic bunded tank). I don't know how much the oil vapor will affect the sensor, so I'm looking into perhaps using a small lexan disc and mounting the sensor to that, on top of the 6" cover, as I believe the laser will pass through this ok and it is oil vapor resistant. Then if the cables from the sensor are long enough and can pass beneath the main inspection cover, I can sit the waterproof box with aerial outside on top of the tank. I know the tank is a 1300 Litre model, and have the outer measurements, but not the internal tank measurements, but hopefully I can work out a near enough volume remaining based on the distance readings....

      20220319_161704.jpg20220319_161831.jpgScreenshot_20220321-215800_Samsung Internet.jpg
      0
      Itrium
      Itrium

      Reply 8 months ago

      Hi, Don't dismiss a powered version too easily, it only needs some bell wire run along the oil pipe from a 5V USB plug socket. I do that for the green house for ambient monitoring. The only reason for long intervals between oil reads is to give a long battery life. This is not a limitation for a powered version and you could include a fast usage oil detector. Good for leaks or theft!
      I have wrapped my sensor in a single layer of clingfilm and not had any oil vapour problems. It occasionally gets knocked when hedge trimming or spiders like putting webs on it but that is another story. Other than that, it was been running happily for the last 18 months.
      It looks like the strengthening in your tank may give some shallow readings, I guess this will need some experimenting for the best position. Also, relating the oil depth to volume could be interesting, if you could clock the run time of the boiler,. this should give an idea of oil usage.

      0
      Wildflecken
      Wildflecken

      Question 8 months ago on Step 2

      Hi Thanks for adding the battery comments.
      I now have all the bits to start.
      are all the red wires on the right of the diagram connected together, or is the red 'cross' not a connection.
      Thanks in advance
      Mark

      0
      Itrium
      Itrium

      Answer 8 months ago

      Hi, The cross is not connected. The diode in the cross is the reset connection for wake up.

      0
      Wildflecken
      Wildflecken

      Reply 8 months ago

      Glad I asked, didn't think it was, but best to check.

      0
      tytower
      tytower

      2 years ago

      Looks good and definitely useful however I would solder the battery connections or the connections will corrode quickly . Only 6 months maybe.
      .

      0
      Wildflecken
      Wildflecken

      Reply 8 months ago

      I have seen 'tagged' cells with wires on that are solderable (but not to close to the cell itself).
      Not only should one NOT solder this type of battery, the thionyl chloride liquid electrolyte is poisonous, and listed on the chemical weapons list (wiki-p). Just don't do it.
      Silica gel is a good idea. Two tiny holes in the bottom, is not a bad idea, at least it will let anything out. Slathering battery terminals in petroleum jelly (Vaseline) is an excellent if messy idea (gloves).

      0
      Itrium
      Itrium

      Reply 8 months ago

      These batteries are quite safe if used according to the datasheet. Just don’t short them out or expose them to temperatures higher than 100’C. Versions are available with solderable terminals but they are harder to find.

      0
      Itrium
      Itrium

      Reply 2 years ago

      Thanks for the comment. I guess it will depend on how ‘waterproof’ the box stays. The battery manufacturer warns against soldering to this type of battery (bursting issue) but supply wire ended versions for PCB mounting. Maybe spot welding would work if you have the equipment.
      As the climate here is damp, I was thinking of putting a bag of silica gel in the box to keep things dry.

      0
      garethmcquillan
      garethmcquillan

      1 year ago

      Thank you for this. It is going to be extremely useful.

      I am struggling with one thing... when the code is run, as soon as the ESP connects to WiFi, I get an exception. Here is my serial monitor:

      ets Jan 8 2013,rst cause:2, boot mode:(3,7)
      load 0x4010f000, len 3460, room 16
      tail 4
      chksum 0xcc
      load 0x3fff20b8, len 40, room 4
      tail 4
      chksum 0xc9
      csum 0xc9
      v00046250
      ~ld
      622888339
      Connecting to Wi-Fi
      Connected
      --------------- CUT HERE FOR EXCEPTION DECODER ---------------
      Exception (0):
      epc1=0x4020107d epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
      >>>stack>>>
      ctx: cont
      sp: 3ffffdf0 end: 3fffffc0 offset: 0190
      3fffff80: 3ffe85c8 3ffee7a2 3ffee7e0 4020107d
      3fffff90: 3ffe85c8 3ffee7e0 3ffee654 4020118c
      3fffffa0: 3fffdad0 00000000 3ffee90c 40204448
      3fffffb0: feefeffe feefeffe 3ffe85e4 40100ebd
      <<--------------- CUT HERE FOR EXCEPTION DECODER ---------------


      Using the exception decoder, I get the following:

      Exception 0: Illegal instruction
      PC: 0x4020107d
      EXCVADDR: 0x00000000

      Decoding stack results
      0x40204448: loop_wrapper() at C:\Users\XXXX\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266\core_esp8266_main.cpp line 198

      When I go to the "core_esp8266_main.cpp", line 198 I see the code in the attached screenshot.

      Any help appreciated! G

      123.png
      0
      Itrium
      Itrium

      Reply 1 year ago

      First let me say that I am not C expert, I grab pieces of code and tag them together rather than any deep knowledge.
      I had a similar problem to this where the WiFi connect was called as a subroutine like in this sketch but it crashed rather than return to the main program. I got round this problem by running the WiFi connect in the main flow instead of having a neat subroutine. It may just need something like a time delay but I did not explore further as this fix worked.
      Give this a try as a possible solution.

      0
      robertplacido
      robertplacido

      1 year ago

      First, thank you. This is very helpful. Question: is the 5k resistor in the diagram for the upload of the program or is it permanent? If it is for the upload, you have it going to GPIO105, did you mean to go to GPIO100?

      0
      Itrium
      Itrium

      Reply 1 year ago

      The 5k from GPIO105 to ground is permanent. A separate 5k is connected between GPIO100 and ground during power up to put the chip into flashing mode. My Instructable on water softener salt level uses a similar circuit and you may find this helpful.

      0
      garethmcquillan
      garethmcquillan

      Reply 1 year ago

      Hi, regarding the permanent 5k resistor, do you mean GPIO015? As GPIO05 is connected to the SCL of the sensor? GPIO015 is connected to the transistor and is used to switch on the sensor - this has the permanent 5k resistor attached also? Thanks

      1
      Itrium
      Itrium

      Reply 1 year ago

      Hi, you are right. The pin driving the transistor base should be labelled GPIO015.
      The oil monitor has been in place for about a year now and a couple of problems have arisen. I upgraded the router during this period and the monitor could not connect at this time resulting in a flat battery. The software needs some. sort of counter adding to put the chip back to sleep after a few attempts at connecting.
      The other problem is that the tank is nearly empty now and the sensor alignment is quite critical. There have been a few instances where it gets knocked out of true giving silly readings. Otherwise, the concept seems ok.

      0
      JudgeyK
      JudgeyK

      1 year ago

      Hi All,

      Is there anyway somebody could help me with the circuit diagram, I've not really done any electronics and find my soldering the wires like the wiring drawing with all the junctions ?

      If somebody could post clear photographs of each of the connections / soldering areas and how its been done would be really useful, I have purchased all the bits but not confident on how to read this diagram, so photo's of each bit would be really appreciated.

      I have tried but seem to have wires everywhere which doesn't look the photo in the box...

      0
      Itrium
      Itrium

      Reply 1 year ago

      Hi, The circle is the symbol for an NPN transistor. I think you need someone local who has experience in electronics to help you with the circuit diagram. Flashing the software can have its own set of problems.
      Failing that, it will be a long haul going up the learning curve and the Arduino Uno may be a better place to start. There are plenty of tutorials on the web about these topics but nothing beats trying it for yourself.

      0
      JudgeyK
      JudgeyK

      Reply 1 year ago

      Thanks Itrium, I like to learn the hard way, that way I don't forget it, is there anyway you can take photos of your wiring, or even a little video, I'd really appreciate it.