WiFi Oil Tank Monitor

10,157

67

56

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

      • Clocks Contest

        Clocks Contest
      • Make it Glow Contest

        Make it Glow Contest
      • Game Design: Student Design Challenge

        Game Design: Student Design Challenge

      56 Comments

      0
      Ludamus
      Ludamus

      2 days ago

      Can I ask what the capacitor does between +ve and ground on the battery does?

      0
      Itrium
      Itrium

      Reply 2 days ago

      Hi, when something in the circuit turns on like the WiFi, there is a surge of current that can affect other parts of the circuitry and cause problems or even a lock up. The capacitor smooths out any spikes on the power supply. Depending on things like cable lengths, layout, age of battery, you may get away with no capacitor. It is safer to include this decoupling capacitor.

      0
      MIKEB
      MIKEB

      24 days ago on Step 6

      I am receiving error in Arduino ESP_WPS.h does not exist
      I could not find the exact zip file to install the proper driver
      I installed ESPSsyncWiFimanager and Thinkspeak libraries, but NG
      Can you tell me exactly which libraries to install to get the proper user_interface.h and ESP_WPS.h files?
      Mike

      0
      Itrium
      Itrium

      Reply 23 days ago

      Hi, You can find the libraries needed by the #include statements towards the top of the sketch. I don’t remember anything quirky about this sketch except the unusual serial speed to read the start up data.

      0
      MIKEB
      MIKEB

      Reply 23 days ago

      Yes, The #include statements indicate which files are to be used, but not the library where these files are included. I searched both the "user_interface.h" and the "ESP_WPS.h" on Github, but nothing showing a specific library, and some are only files. Also when I downloaded the ESP libraries (Zip file) and used the Arduino IDE to install, it gave an error that said "no library found" installation failed.. If we can get the exact libraries for Arduino, that would be great.

      0
      Itrium
      Itrium

      Reply 22 days ago

      The quotes are correct, I’ve no idea why! Try searching ESP8266 RTM memory for more information.
      The WiFi library is used in lots of ESP8266 projects. I can only suggest finding a simple project and getting the WiFi part to load. I’m sorry I can’t be more helpful but it is mostly trial and error getting this stuff to work.

      0
      MIKEB
      MIKEB

      Reply 23 days ago

      Also the #include "user_interface" is in quotes, while #include <ESP8266WiFi.h> is in brackets <> there's a difference, correct? It is the ESP8266WiFi.h that is giving me the installation failed error.

      0
      bubba22
      bubba22

      Question 4 weeks ago on Step 1

      Hi,
      Thank you for sharing. I've put the things together and loaded the sketch but before I connect everything to my computer I wanted to verify the sketch. When I clicked verify, I get this,

      oilemeasurer:4:10: fatal error: user_interface.h: No such file or directory
      #include "user_interface.h" // this is for the RTC memory read/write functions
      ^~~~~~~~~~~~~~~~~~
      compilation terminated.
      exit status 1
      user_interface.h: No such file or directory

      can you direct me to the cause of this error?
      Do I have to have the unit connected via usb to verify the sketch?

      I am using arduino 1.8.19 IDE.

      Thanks.

      --newbie bubba

      0
      Itrium
      Itrium

      Answer 4 weeks ago

      Hi, You need to have "user_interface.h" installed so that you can store the number of deep sleeps. Google "user_interface.h" to find out more.
      You need the USB connected to see the serial prints on the serial monitor when checking out the program. Once it is working, you can remove the USB and view the readings on ThingSpeak.

      0
      bubba22
      bubba22

      Reply 25 days ago

      Thanks Itrium I'll look that up. Sorry I'm new to all this stuff and have a lot to learn. On another note I just want to clarify diode connection on diagram. I see someone also asked the question and still not clear to me about the diode connections at the "cross". Is that just RS1 and diode and, separately just EN and 3.3v?

      Thanks. I appreciate all your help.

      --bubba

      Screenshot from 2023-01-09 10-06-18.png
      0
      Itrium
      Itrium

      Reply 25 days ago

      Hi, There is no connection, the diode wire bridges the 3.3V line. A tip, I found out the hard way that the circuit board is easily damaged by too much resoldering.

      0
      ScoffScoff
      ScoffScoff

      10 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 10 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 10 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 10 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 10 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 10 months ago

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

      0
      Wildflecken
      Wildflecken

      Reply 10 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 10 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).