Wifi Home Heating Oil Monitor

This bit of Home Automation has been on my list for a long time. I usually find out that the home heating oil (kerosene) has run out when an orange light is illuminated on my boiler. At that stage, we’ll probably be without heating in the house for a day or two. So, I was looking at ways to measure the level of home oil in the tank that would give me a constant level indicator, and also not break the bank.

There were hydrostatic sensors at a couple of hundred bucks at the top end of the scale, and then float switches that looked like they’d break after a few weeks. So after a bit more research, I came across the HC-SR04 Ultrasonic Range Finder. Good for measuring distance up to 2 metres. My tank is 1 metre deep, so that’d be ideal. I ordered a couple off eBay.

Hooking these up to an MCU is fairly straightforward, there’s a trigger pin and an echo pin, and all the MCU needs to do is measure the time it takes for the echo to come back after the trigger pin is activated. There’s loads of sample sketches on the net to do this. I loaded up one sample onto a Wemos D1 Mini, and it worked straight off. It seemed to be pretty accurate as well. I chose the WeMos D1 Mini, as it has WiFi built in, and it’ll be talking across the back yard to the router in my kitchen, about 100ft. I didn’t want to have to run any cables.

So, first task was to build the SR04 into a box for mounting on the Oil Tank. I can’t seal it completely, but At least I can protect the electronics somewhat. I had an old plastic enclosure that was suitable.

I drilled two 16mm holes in the cover, and hot glued the sensor in place. I’d be hot-glue’ing this box into place in the oil tank later.

I have the transducers a good dab of hot glue, as can be seen in the picture above. I’m not sure how it will react if it gets a splash of kerosene, but they’re cheap enough to replace regularly if I need to.

Next, on to mounting the transducer into the oil tank. I didn’t want to drill any holes, so I hot glued it into the inside of the lid. This also has the advantage of taking it out of harm’s way when the delivery person is refilling the tank. It’s mounting position is such that when the lid is closed, the transducer is pointing straight down towards the centre of the tank (it’s cylindrical).

I didn’t have a small waterproof box for the WeMos D1 Mini, so I used an IP56 plastic box I had lying around. Kinda a waste of space, eh? 🙂

There’s two cables coming into it. One is the 4-wire cable from the ultrasonic transducer, and the other is a 5 volt feed from a power supply in a wall socket inside.

Even without an external antenna, the signal strength is still at 60%. Plenty good enough.

I added an extra GND and 5V to the WeMos, to make wiring a bit easier. There’s the 5V supply from inside, and also the feed to the ultrasonic transducer.

The software I’m using on the WeMos is (again) the Sonoff sketch by Theo Arends. I’ve modified it to allow use of the HC-SR04 so that the distance measured will appear on the web interface, and is also transmitted via MQTT, along with the other telemetry that it typically sends (signal strength, up-time, etc).

The On/Off functionality is not relevant in this use case, as there’s no relays. The important bit is below that, the SR04 Distance. I also physically measured the distance from the transducer to the surface of the kerosene with a ruler, and it was 48cm. Exactly what the software was telling me. A very good start.

Next steps is to add an algorithm to convert the distance from the transducer to the surface of the kerosene into litres (it’s a cylindrical tank, so there’s a bit of math involved), then graph it as part of my EmonCMS system, which has graphs of a lot of other stuff in the house, temperatures, humidities, electricity usage, etc. It’s all running on an Up-Board, a small, single board computer from Aaeon. The feed from the Sonoff software goes through Node-Red for processing, then on to the EmonCMS system for storage and graphing.

Finally, I’ll set a trigger level to send me a text when the oil goes below a certain level. That should save us from the typical couple of cold days in the future! 🙂

 

–edit–

I found that the sensor was quite noisy, but never reading beyond the actual level. Here’s the graph. I’ve added a smoothing algorithm, so it only records values that are increasing (to the right of the spikes in the graph. This resets back to zero when the distance read is > 90cm, as the lid on the tank is probably open, and being refilled (happened at the spikes).

Note: Values displayed are distance from transducer to surface of the kerosene, so value will increase as level goes down.

This entry was posted in Home Automation.