Arduino Height Measuring Using VL53L0X Laser Sensor

by RonFrtek in Circuits > Arduino

443 Views, 2 Favorites, 0 Comments

Arduino Height Measuring Using VL53L0X Laser Sensor

Arduino Height Measuring Using VL53L0X Laser Sensor

Make a Height Measuring tool using a sensor VL53L0X.

The VL53L0X is accurate up to plus or minus 2-3mm (depends on the surface reflection).

This project is just to show how to make it work on a smaller objects. Sensor can measure up to 2m so you can adjust the projects according to your needs. This approach could also be used to measure the water/liquid height.

How It works: On the Arduino start the VL53L0X remembers the full distance in mm then after the object is placed under it will subtract the New distance from the first one and the result will be the height of the object in mm.

Note: the accuracy mainly depends on the surface reflection of the ground and the object that is measured.

Watch the video!

What You Will Need

oled.jpg
vl53l0x1.png
VisuinoAdvrtisementElegooV4.jpg
336-3361370_arduino-uno-r3-png-png-download-arduino-uno.png
FEGPLRJKK5FQW91.jpg

  • Arduino UNO (or any other Arduino)
  • VL53L0X Time-of-Flight ranging sensor
  • OLED I2C Display
  • Jumper wires
  • Visuino program: Download Visuino

The Circuit

FCF06MBKAV2S44Q.jpg

  • Connect OLED Display pin (VCC) to Arduino pin (5V)
  • Connect OLED Display pin (SCL) to Arduino pin (SCL)
  • Connect OLED Display pin (SDA) to Arduino pin (SDA)
  • Connect VL53L0X sensor pin (GND) to Arduino pin (GND)
  • Connect VL53L0X sensor pin (VCC) to Arduino pin (5V)
  • Connect VL53L0X sensor pin (SCL) to Arduino pin (SCL)
  • Connect VL53L0X sensor pin (SDA) to Arduino pin (SDA)
  • Connect OLED Display pin (GND) to Arduino pin (GND)

Start Visuino, and Select the Arduino UNO Board Type

FVM9U8IKT5SOQAJ.jpg
FPPYYQBKT5SOQAK.jpg

The Visuino: https://www.visuino.eu needs to be installed. Start Visuino as shown in the first picture Click on the "Tools" button on the Arduino component (Picture 1) in Visuino When the dialog appears, select "Arduino UNO" as shown on Picture 2

In Visuino Add Components

2022-01-01_16-34-23.jpg
2022-01-01_16-35-16.jpg
2022-01-01_16-36-55.jpg
2022-01-01_16-37-59.jpg
2022-01-01_16-38-49.jpg
2022-01-01_16-40-03.jpg
2022-01-01_16-40-52.jpg
2022-01-01_16-42-19.jpg
2022-01-01_16-42-56.jpg
2022-01-01_16-43-44.jpg
2022-01-01_16-45-02.jpg
2022-01-01_16-45-53.jpg
  • Add "Clock Generator" component
  • Add "VL53L0X" component
  • Add "Start" component
  • Add 2X "Max Analog Value" component
  • Add "Remember Analog Value" component
  • Add "Subtract From Analog Value" component
  • Add 2X "Compare Analog Value" component
  • Add "Analog On/Off Switch" component
  • Add "Average Analog Period" component
  • Add "Analog Value" component
  • Add "Analog Multi-Source Merger" component
  • Add "OLED I2C" component

In Visuino Set Components

2022-01-01_16-34-44.jpg
2022-01-01_16-49-21.jpg
2022-01-01_16-50-46.jpg
2022-01-01_16-52-07.jpg
2022-01-01_16-53-45.jpg
2022-01-01_16-54-59.jpg
  • Select "ClockGenerator1" and in the properties window set "Frequency" to 3
  • Select "SubtractFromValue1" and in the properties window select "Value" and click on the Pin Icon and select Float SinkPin
  • Select "CompareValue1" and in the properties window set "Compare Type" to ctBiggerOrEqual and "Value" to 5
  • Select "CompareValue2" and in the properties window set "Compare Type" to ctSmaller and "Value" to 5
  • Select "AveragePeriod1" and in the properties window set "Period (uS)" to 3000
  • Double Click on the "DisplayOLED1" and in the "Elements" window:
    • drag "Draw Text" to the left side and in the properties window set "Size" to 2 and "Text" to HEIGHT
    • also drag "Text Field" to the left side and in the properties window set "Size" to 2 and "Y" to 40
  • Close the "Elements" window

In Visuino Connect Components

2022-01-01_17-04-00.jpg
2022-01-01_17-03-33.jpg
2022-01-01_17-03-13.jpg
Laser-Height.png

  1. Connect "Start1" pin [Out] to "LaserRanger1" pin [Clock]
  2. Connect "ClockGenerator1" Pin [Out] to "LaserRanger1" pin [Clock]
  3. Connect "Start1" pin [Out] to "RememberAnalog1" pin [Remember]
  4. Connect "LaserRanger1" pin [Distance] to "RememberAnalog1" pin [Recall]
  5. Connect "LaserRanger1" pin [Distance] to "SubtractFromValue1" pin [In]
  6. Connect "LaserRanger1" pin [Distance] to "MaxValue1" pin [In]
  7. Connect "MaxValue1" pin [Out] to "RememberAnalog1' pin [In]
  8. Connect "RememberAnalog1" pin [Out] to "SubtractFromValue1" pin [Value]
  9. Connect "SubtractFromValue1" pin [Out] to "CompareValue1" pin [In]
  10. Connect "SubtractFromValue1" pin [Out] to "AnalogSwitch1" pin [In]
  11. Connect "SubtractFromValue1" pin [Out] to "CompareValue2" pin [In]
  12. Connect "CompareValue1" pin [Out] to "AnalogSwitch1" pin [Enable]
  13. Connect "AnalogSwitch1" pin [Out] to "AveragePeriod1" pin [In]
  14. Connect "AveragePeriod1" pin [Out] to "MaxValue2" pin [In]
  15. Connect "CompareValue2" pin [Out] to "AnalogValue1" pin [Clock]
  16. Connect "CompareValue2" pin [Out] to "MaxValue2" pin [Reset]
  17. Connect "MaxValue2" pin [Out] to "AnalogMultiMerger1" pin [0]
  18. Connect "AnalogValue1" pin [Out] to "AnalogMultiMerger1" pin [1]
  19. Connect "AnalogMultiMerger1" pin [Out] to "DisplayOLED1" > "Text Field1" pin [In]
  20. Connect "LaserRanger1" I2C pin "Out" to Arduino Board pin I2C [In]
  21. Connect "DisplayOLED1" I2C pin "Out" to Arduino Board pin I2C [In]

Generate, Compile, and Upload the Arduino Code

FBR42I2KXBU01YW.jpg

In Visuino, at the bottom click on the "Build" Tab, make sure the correct port is selected, then click on the "Compile/Build and Upload" button.

Play

If you power the Arduino module, the OLED Display will start to show the distance 0, after you put the object under the sensor it will start to show the object height.

Note: when you power the Arduino there should not be any object under the sensor, this will allow the sensor to first measure the full distance to the ground, then you can place the object under the sensor.

Congratulations! You have completed your project with Visuino. Also attached is the Visuino project, that I created for this Tutorial, you can download it and open it in Visuino: https://www.visuino.eu