WiFi Oil Tank Monitor

5,887

52

32

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.

    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.

    Click to see my oil tank level.

    Battery Powered Contest

    Participated in the
    Battery Powered Contest

    Be the First to Share

      Recommendations

      • Home Cooked Speed Challenge

        Home Cooked Speed Challenge
      • Robots Contest

        Robots Contest
      • 3D Printed Student Design Challenge

        3D Printed Student Design Challenge

      32 Comments

      0
      JudgeyK
      JudgeyK

      5 months 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 5 months 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 5 months 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.

      0
      Itrium
      Itrium

      Reply 5 months ago

      Hi, I don't really want to disturb the unit on top of the oil tank while it is running so well. The circuit diagrams are the clearest way to see how it is all connected. What I will do is split the circuit as used for flashing and when it is in operation. Also, I will replace the diode and transistor with pictures to show the correct orientation.
      There is nothing special about the layout, I solder the parts together on the fly, not very neat but seems ok for a one off. The ESP8266 module is easy to damage by excessive soldering, the components under the lid can come adrift and kill the module. I try and solder quickly and only once. Give me a day or so to update the circuit diagrams.

      0
      JudgeyK
      JudgeyK

      Reply 5 months ago

      Hi Itrium,

      Just an update, I have managed to get the ESP8266 Code uploaded and have everything connected, but when I power up it says failed to detect sensor in the serial monitor...

      18:05:46.214 -> ets Jan 8 2013,rst cause:2, boot mode:(3,0)
      18:05:46.249 ->
      18:05:46.249 -> load 0x4010f000, len 3584, room 16
      18:05:46.249 -> tail 0
      18:05:46.249 -> chksum 0xb0
      18:05:46.249 -> csum 0xb0
      18:05:46.249 -> v2843a5ac
      18:05:46.249 -> ~ld
      18:05:46.317 -> 2940668882
      18:05:46.317 -> Failed to detect and initialize sensor!
      18:05:49.547 ->
      18:05:49.547 -> --------------- CUT HERE FOR EXCEPTION DECODER ---------------
      18:05:49.547 ->
      18:05:49.547 -> Soft WDT reset
      18:05:49.547 ->
      18:05:49.547 -> >>>stack>>>
      18:05:49.547 ->
      18:05:49.547 -> ctx: cont
      18:05:49.547 -> sp: 3ffffdf0 end: 3fffffc0 offset: 01a0
      18:05:49.547 -> 3fffff90: 3ffe84cc 3ffee620 3ffee49c 402011b9
      18:05:49.547 -> 3fffffa0: 3fffdad0 00000000 3ffee70c 402046ac
      18:05:49.547 -> 3fffffb0: feefeffe feefeffe 3ffe84f0 40100eed
      18:05:49.547 -> <<18:05:49.547 ->
      18:05:49.547 -> --------------- CUT HERE FOR EXCEPTION DECODER ---------------
      18:05:49.547 -> "@⸮rjrA(!⸮S⸮u⸮P⸮⸮XKz~⸮⸮Q*!⸮QI⸮⸮I*E⸮1⸮-⸮)⸮P⸮YJ!{⸮A⸮!⸮n⸮*E"⸮h⸮⸮A,pJ
      ⸮⸮A,pZ
      ׬5⸮!zI\1

      ...

      0
      Itrium
      Itrium

      Reply 5 months ago

      Hi, Great progress! It looks like the sensor is not responding. You could connect the sensor VCC and GND direct to the battery to see if it is detected knowing there is power on the sensor. The transistor circuit needs checking if that works. The transistors can come with different pinouts, EBC or ECB, have a look at the 2N2222 datasheet or the datasheet for whatever transistor you used. Check it is an NPN transistor, not a PNP. On some Chinese stuff I have found the SCL and SCA have been swapped, worth a try swapping.
      What is your technical background? I've no idea if I am pitching these comments at the right level...

      0
      JudgeyK
      JudgeyK

      Reply 5 months ago

      Hi Itrium,

      I'm a software developer, C#, .Net etc, which is probably why I got the Arduino IDE and everything working ok, never really done much with Arduino, don't a fair bit with Python and the Raspberry Pi.

      There was no datasheet with that cam with that cam with the 2N2222 Transistors, thy just came in a bag. but I did download the 2N2222 basics sheet which said looking at the flat surface the pins from left to right 1,2,3 1 = Collector, 2 = Base and 3 = Emitter so that's how I wired them matching your C B E, so do you think its worth swapping the C & E around ?

      Kind Regards

      Ken

      0
      JudgeyK
      JudgeyK

      Reply 5 months ago

      Hi Itrium,

      Ok, It now detects wifi, connects, detects the sensor, however, every reading from the sensor Tank = 0, but the Strength is working and changing, -49, -51, -50 etc, also I set it to the 10 seconds and the loop also only seems to work once, so I have to disconnect the battery each time to get another reading, but like I sy, Tank always = 0 ?? ( Nearly there though ! )

      0
      Itrium
      Itrium

      Reply 5 months ago

      Hi, I have a background in silicon chip design so we come from opposite ends of this problem. Any thoughts on the code would be appreciated, I bolt together pieces that work from other people rather than try to write it from scratch.
      It seems the reset loop is not working. Is the BAT43 diode the right way round? You could try a manual reset, quickly connect IO16 to ground to give a reset pulse.
      The reset function often works with a wire link instead of the diode, try a temporary short across the diode to see if that works.
      The sensor comes with a protective plastic film across the optics, this needs removing if it is still there.
      This is proving a real test for an Instructable. If you have time (I am assuming you will have it working soon), could you let me know which parts need clarifying for an easier build.

      0
      JudgeyK
      JudgeyK

      Reply 5 months ago

      Spot on Itrium, didn’t realize that little thing had a right way and a wrong way 😂, ok so loop is working great now, but still reading 0, there is no protective cover I can see on the sensor. If I change the sensor timeout to 4000 and the timing budget to 33000 I get a strange reading of 85 even though it’s about 620mm from the floor, and it only reads once and then after the 6 sleeps reports exception stack. I’ve attached photo of sensor, it was sold to me as a VL531L1X.

      Would love to have a discussion about updating the instructions once we get this working, I know it would do be invaluable if it could be aimed at the everyday person who has some intelligence but never done electronics before....

      Kind Regards

      Ken

      7FA07A14-2E46-47F4-B1DC-01C66F6A39DC.jpegimage.jpg
      0
      JudgeyK
      JudgeyK

      Reply 5 months ago

      ** UPDATE **

      Ok all working, I had to change the code to work, not sure if its anything to do with the latest version of Pololo library (1.3.0)

      I changed the sensor.read() to ;

      sensor.readSingle(false);
      while ( sensor.dataReady() == false) {
      // Wait for dataReaady = True
      }
      int tank = sensor.read(false);

      I am now getting readings, but they're not very accurate ?
      _______Distance(mm) __Reading ____% Dif
      Test 1 _________640_______596_____6.875
      Test 2 _________200_______191_____4.5
      Test 3 _________400_______385_____3.75
      Test 4 _________500_______487_____2.6
      Test 5 _________100_______113_____13


      0
      Itrium
      Itrium

      Reply 5 months ago

      Have you had a look the Pololu write up and datasheets on the VL53L1X? That might be helpful at this stage for ideas.
      The read problem could be the sensor not having enough time to settle, a delay may be needed to give it more time. I remember changing to the transistor switch to power the sensor down instead of using the XSHUT pin because of start up and shut down problems. You may have more knowledge in this area than me.

      Accuracy never bothers me, something that can be corrected with calibration. What matters is resolution, stability and repeatability. Resolution looks good at 1 mm. Repeatability is running the sensor with a fixed distance to get an idea of short term scatter in the readings. In my test I got about +/- 2 mm (see Instructable). Stability estimated from the spread in the readings every 7 hrs is much higher at about +/- 5 cm. I suspect this is a temperature effect, either tank
      expansion or the electronics. A bit of correlation work measuring air and oil temperature should sort that out... one day!

      Anyway, it looks like you are on the home run 😊

      0
      JudgeyK
      JudgeyK

      Reply 5 months ago

      Hi Itrium,

      So does this instructable take into account the transistor switch change ?

      The only thing I'm not sure how to do now is remove the external antenna link, but also, do I really need to remove the red LED, how much power does that take ?, what would it reduce the 2 year lifespan down to if I left it on ?

      Kind Regards

      Ken

      0
      Itrium
      Itrium

      Reply 5 months ago

      Hi, The deep sleep current will rise from about 22 uA to about 300 uA if the red LED is left on. The battery life will drop to around 9 months.
      It will ping off if you lever it off with a fine screwdriver, careful you don’t get an eyeful.
      The antenna link is next to the aerial socket. This will also ping off. Alternatively, if you may want to you replace it, place a soldering iron on top of the link and slide it off when the solder melts, very small and fiddly process. The external aerial gives much better range if you need it.
      The transistor is used as a switch. In the off state, the leakage current is a few nano amps so you can forget it. Using XSHUT still gives a standby current 5-20 uA. Powering the sensor on and off proved much simpler (to me anyway) than trying to stop and start it in software.

      0
      Itrium
      Itrium

      Reply 5 months ago

      The sensor looks exactly like the one I used. I have attached the sensor library details, there are other versions about now, see if you used a different one.
      Another option would be to get the sensor working with some short code just to make sure it is working.

      Library.jpg
      0
      JudgeyK
      JudgeyK

      Reply 5 months ago

      Hi Itrium,

      Se my update below... Using the same but latest version.

      Regards

      Ken

      0
      JudgeyK
      JudgeyK

      Reply 5 months ago

      Great Thanks Itrium, I did get it all together, looks very messy, got the code in and compiling in the Arduino IDO, but it won't just connect to uplod th code ;

      Failed to connect to ESP8266: Timed out waiting for packet header

      I shorted the TXD nd RXD and could see the send coming back so I know FT232RL is trying to send, I also did put the 5k in the 100 hold and touch the ground and then put the battery in but makes no difference.

      0
      Itrium
      Itrium

      Reply 5 months ago

      Hi,It will look neater after removing the FT232. Have you checked all the usual stuff, selected the generic 8266 module, baud rate - I used 74880 to show boot up code, right driver for FT232 - the interface chips vary with manufacturer, voltage set to 3.3V, google for the problem on the web.
      It takes a lot of trial and error to get this stuff working but you will get there.


      0
      JudgeyK
      JudgeyK

      Reply 5 months ago

      Hi Itrium, seems your reply came in after mine below...

      0
      ruggbg
      ruggbg

      7 months ago

      I am trying to compile the sketch but it isn't finding sys/cdefs.h
      This is an include in c_types.h file.
      Where can I find this library file?