Main »

Liquid level sensor using a laser time of flight sensor

Started 21st December 2016

I measured the depth of water in the crawl space under my house using a capacitive sensor (see Sensor) and an ultrasonic ranging module (see HCSR04). Then at the end of 2016 I became aware of the ST Microelectronics laser time of flight sensors.

As a young lad playing with tiny radio transmitters I had thought why not use radar to see how far away objects in my work-space were. Even for me back then the calculation was simple and the answer is that light travels fast, really really fast. At the time I doubt anyone had electronics which could measure how long light takes to cover a foot (as 300 mm was known then).

We'd been out on the vast school playing field and measured the (far lower) speed of sound with our ancient technology ("I will blow my whistle and Pilling will wave his flag when he hears it") and failed to get anywhere near the right value.

So amazing new technology, I had to give it a go.

Two versions currently are available on ebay, the VL53L0X and the VL6180X "Time-of-Flight Distance Sensor". The VL6180X is short range (10 cm) and the VL53L0X longer (1 m). The ST home pages are: VL53L0X and VL6180X.

Home pages on SparkFun VL6180X and Adafruit VL6180X and VL53L0X. SparkFun supply a library for the VL6180X which I set off using.

The ebay version (shown below) contains level shifters and a voltage regulator which means it can be connected to a 5 V or 3.3 V Arduino.

VL6180 break out board, David PillingVL6180 break out board, David Pilling

The SparkFun library is very simple to use and trivial to splice into the rest of my sensor code. Results are noisy, but if enough are averaged they are accurate. There's no problem of monotonicity like with the unmodified ultrasonic ranging module.

Downloads:

What happened
At the end of 2017 the water in the crawl space rose above the VL6180 sensor and fatally damaged it. As I had a VL53L0X sensor I reworked the code to use that.

I rejected the Adafruit library as too complicated and used the Pololu library. Previously I have used a customised version of the wire and twi libraries (to disable pull ups) in this version I used the standard one and added code to handle the pull ups.

I 3D printed an arm to hold the VL53L0X sensor some 250 mm above the ground level. I have a plastic box filled with gravel which the electronics sit on top of. It is important to have enough ballast so that as the water level rises the box does not float.

Downloads:

I set off wanting to measure single mm of water, and ended three years later with inches (25.4 mm units) of it, a worrying trend.

Liquid level sensor, David PillingLiquid level sensor, David PillingLiquid level sensor, David PillingLiquid level sensor, David Pilling
Liquid level sensor, David PillingLiquid level sensor, David PillingLiquid level sensor, David PillingLiquid level sensor, David Pilling

Comments
I had a couple of comments from people detecting water levels, one of them was along the lines "does water reflect light", which I batted aside, "of course water reflects light, what do you think Polaroid sunglasses are all about", eventually I read a comment by C. Wayne Wright here (a You Tube video about the VL53L0X) which makes the good point that reflection from water is specular, angle of incidence equals angle of reflection, so the sensor has to be perpendicular to the liquid. I've not come unstuck with this because my water is so mucky; there's often a white film on it which will give diffuse reflection.

I used a lot of freely available software. Credit to the people who wrote it and made it available.

Software sources:

Other resources:

Click to return to index

David Pilling's Wiki

Set view

Page last modified on March 12, 2019, at 12:36 AM - Powered by PmWiki pmwiki-2.3.31 (pmwiki-2.3.31)

^