I recently stumbled across the VL53L0X and VL53L1X TOF distance sensors. These sensors can determine distances with millimeter accuracy using a laser. In addition, they have a range of up to 4m (VL53L1X9 or 2m (VL54L0X). I found the sensors very interesting and of course I ordered a few directly. It doesn’t hurt to have something practical in stock. 🙂
After they had arrived and I played around with it, it struck me that it could also be used to detect the level of my coffee cup. A quick test at the sink and a further test at the rain barrel then showed that this also worked with clear liquids. And that gave me the first idea for practical use: a level sensor for the rain barrel.
I had never dared to do so because I found previous systems either too expensive, complicated or inaccurate. But now it was time.
I described what you need and how you can proceed when building your own laser level sensor in the following article. 🙂
- 1 Safety instructions
- 2 Affiliate links / advertising links
- 3 Requirements
- 4 Collect required parts
- 5 Print the required 3D parts
- 6 Cut threads in the housing
- 7 Prepare the distance sensor
- 8 Connect the distance sensor to the Wemos D1 Mini
- 9 Install the distance sensor
- 10 Install the Wemos D1 Mini and insert the USB cable into the housing so that it is watertight
- 11 Seal the housing watertight
- 12 Programming the firmware
- 13 Assembly suggestion
- 14 Evaluation in NodeRed
- 15 Additional information
I know the following hints are always a bit annoying and seem unnecessary. But unfortunately, many people who knew it "better" from carelessness lost their eyes, fingers or other things or hurt themselves. In comparison, a loss of data is almost not worth mentioning, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Even the coolest project is worth no injury or other annoyance. https://www.nerdiy.de/en/sicherheitshinweise/
The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and shop via this link, Nerdiy.de receives a commission from the online shop or provider concerned. The price doesn't change for you. If you do your purchases via these links, you will support Nerdiy.de in being able to offer further useful projects in the future. 🙂
Hints for our lovely english readers: Basically, many of the articles on Nerdiy.de are translations from the original german articles. Therefore, it may happen here and there that some illustrations are not available in english and that some translations are weird/strange/full of mistakes or generally totaly wrong. So if you find some obvious (or also not obvious) mistakes don't hesitate to leave us a hint about that in the comment section.
Also please don't get confused, that instead of a "dot" often a "comma" is used as decimal separator. 🙂
Before you start this article, you should have worked on the basics of soldering. You can find information on this in the following article.
In the following list you will find all the tools you need to implement this article.
In the following list you will find all the parts you need to implement this article.
Collect required parts
You need the parts shown below to build the level sensor.
Print the required 3D parts
Download all required STL files:
Cut threads in the housing
So that the USB cable for the power supply can also be inserted watertight into the housing, you should use a cable gland. This is the only way to permanently prevent water from penetrating the housing over time.
To be able to mount this cable gland in the housing, a thread must first be cut into the housing. The cutting of internal threads is also explained in detail in the article Mechanics – Cut internal thread.
As usual, place the tap as straight as possible and cut the thread. Remember to turn back half a turn after each turn to break off the chip.
As soon as you have completely cut the thread with the tap, the whole …
… thing should look something like this.
Now you can screw the cable gland into the freshly cut thread.
This way you will quickly notice whether the thread is completely cut or not.
If you kept the tap straight while cutting the thread, you can now also see that the sealing ring is pressed evenly against the housing everywhere and thus also seals well.
Prepare the distance sensor
Now it is time to prepare to install the actual sensor. This communicates with the microcontroller via the I2C bus and therefore requires a total of four lines.
Prepare the connection line by stripping the ends of the individual lines 5mm each and tin it with a little solder.
Then you can also prepare the actual sensor by first tinning the contacts “VCC”, “GND”, “SCL” and “SDA” with some solder.
At this point you can also remove the yellowish protective film from the sensor surface.
Now you can solder the cables to the corresponding contacts as shown.
When fully prepared, the whole thing should look something like this.
Connect the distance sensor to the Wemos D1 Mini
Now of course the sensor still has to be connected to the microcontroller.
To do this, you should first prepare the contacts again. To do this, tin the contacts “5V”, “G”, “D2” and “D1”.
Then you can solder the previously prepared connection cable to the microcontroller.
Set up this should roughly …
… look like this.
Install the distance sensor
The unit consisting of microcontroller and sensor must of course now be installed in the housing in a watertight manner.
To do this, you first position the M3 nuts as shown …
… under the holder inside the housing.
The nuts should be positioned so that they …
… lie exactly under the holes through which the screws are later inserted.
Now the small sealing ring is inserted into the recess.
Then you can put the sensor on it and fix it with the M3 screws. Remember to tighten the screws but not too tight. Because after “fixed” comes “off”! 🙂
Now you can check again that the sensor has a clear view …
… to the outside.
Install the Wemos D1 Mini and insert the USB cable into the housing so that it is watertight
After the sensor is installed in the right place, all other components must now be stowed watertight in the housing.
Thats how your sensor should look like so far. 🙂
The size of the micro USB connection is a bit critical: it has to be small enough to fit through the nut of the cable gland.
If necessary, you can also use a file to edit the connector so that it fits through the nut.
As soon as the micro USB connector is pulled through the nut …
… and you start to tighten the nut …
… you will quickly notice that there is still a lot of space between the rubber seal and the USB cable.
This is clearly too much space to prevent water from entering the housing.
Therefore, you should unscrew the screw grommet again, pull out the USB cable approx. 2 cm and wrap this area tightly with self-sealing tape.
So you can enlarge the diameter of the USB cable …
… and thus fix the USB cable watertight in the screw sleeve. Now the USB cable should also be mechanically secured against being pulled out.
Now you can deal with the rest of the installation: Before the microcontroller is stowed in the housing, you can secure the contacts of the sensor with a little hot glue against short circuits.
Of course you can do this later – after a first test – as soon as you are sure that everything is working correctly.
You can do the same with the contacts of the microcontroller.
Then the microcontroller can be connected to the micro USB connector …
… and can be inserted into the housing as shown.
Möglicherweise müsst Ihr die Überwurfmutter der Schraubtülle dazu nochmal lösen. 🙂
Finished the whole thing should look like this. 🙂 🙂
Seal the housing watertight
The almost final step: Now that all components have been installed in the housing, you must also seal it watertight.
Currently your sensor should …
…look like this.
At this point you can of course jump one chapter further and program the microcontroller first. The housing can also be closed after programming and the first tests. 🙂
Four M3 nuts are now required to close the housing.
Place them from below in the designated assembly spaces in the corners of the housing.
Then turn the housing over without the nuts falling out of their assembly locations.
Then you can insert the sealing ring into the bulge on the top.
Now put the cover plate on and guide the screws through the holes provided.
When tightening the screws, you should always tighten the opposite screws. For example, first at the top right, then at the bottom left, then at the top left and finally at the bottom right.
The screws should be tightened so that the gap between the housing and cover is the same everywhere.
Programming the firmware
In principle, you have many options with the firmware. You can equip the ESP8266 installed on the Wemos D1 Mini with your own firmware, but you can also use the popular firmware “Tasmota” or “ESPEasy”.
Personally, I find ESPEasy the most personable because you have more setting options here. For one or the other, however, this is exactly an argument to prefer the Tasmota firmware, which in my opinion comes with a little more “simply functioning” default settings.
Currently (28.05.2020) there is also the problem that the plugin for ESPEasy does not work reliably. That’s why I currently recommend using the Tasmota firmware if you don’t want to install your own firmware. 🙂The ESPEasy plug-in for the VL53L0X now works quite reliably. Instructions on how to configure this plugin can be found in the following paragraph.
How you can read out the VL53L0X sensor with ESPEasy and the appropriate plugin is described in the following article.
Unfortunately, the sensor is not included in any of the regular automatic builds of the Tasmota firmware. That means you have to compile the firmware yourself after you have activated the use of the sensor.
To save you this step, I have prepared the compiled .bin file and uploaded it into the Nerdiy.de-GitHub. You can find them under the following link: https://github.com/Nerdiyde/tasmotaBuilds/blob/master/tasmota_27052020_incl_vl53l0x.ino.bin
How you can flash.-Bin files on an ESP8266 is described in the article ESP8266 – with the “Esptool” flashing .bin files under Windows.
Here is a small assembly suggestion how you could mount the sensor on a rain barrel, for example.
You should definitely make sure that the sensor is not overwashed if the rain barrel overflows. Although the sensor is very well protected against splashing water, it is better not to immerse it in water. 🙂
The simplest is, of course, to drill a hole in the top of the barrel through which the sensor has a clear view of the water surface.
The sensor can also be attached to the edge and measure the distance to the water surface.
Evaluation in NodeRed
It is one thing to measure the level of your rain barrel. Another is to receive this data, prepare it and, if necessary, convert it.
Because so far you only get a distance from your sensor. This is not really a volume that you actually want to measure. Therefore the water level still has to be converted into a volume. This depends on the shape and dimensions of your rain barrel and is not always easy to calculate.
In the future I will add flows in this part that will simplify the conversion of these values. 🙂
I hope everything worked as described. If not or you have any other questions or suggestions, please let me know in the comments. Also, ideas for new projects are always welcome. 🙂
P.S. Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you appreciate it that I share these information with you, I would be happy about a small donation to the coffee box. 🙂