Build Your Own Laser Range Finder

Hesam Moshiri
|  Created: April 6, 2023  |  Updated: April 21, 2024
laser range finder

Raspberry Pi Pico (RP2040) is a cute piece of hardware. It is equipped with a powerful dual-core RP2040 microcontroller that offers 2M (up to 16M) Flash and 264K SRAM memories. Such specifications for an MCU make it suitable for a variety of hobby and industrial applications.

In this article, I used an RP2040 Zero board, a VL53L0X Laser time-of-flight ranging sensor, and a 2.4” TFT display to build a graphical laser rangefinder unit that can be used to monitor the distance, check the liquid level, etc. The board is also equipped with a relay and a buzzer that allow the user to provide distance-related acoustic signals or activate/deactivate an external device, such as a pump, brake, etc.

The trickiest part of this project was the Pico code. I used the Pico C/C++ SDK V1.5 library and invested a significant amount of time in designing the GUI using the LVGL library and debugging the code. To run all MCU tasks simultaneously, I used an RTOS and engaged both cores of the MCU. The development was carried out using the VS Code IDE, including the GCC ARM 12.2.1 compiler.

To design the schematic and PCB, I used Altium Designer 23. By using the Octopart website, I was able to quickly gather the necessary component information and generate the BOM. It's a cool piece of hardware, so let’s get started!

Specifications

Input Supply Voltage: 5V-Regulated (USB Type-C or wire-to-board connector)
Current Consumption (maximum): 200mA
Measurement Range: Adjustable 30mm to 1000mm (2000mm long range) 
Distance Resolution: 1mm
Sensor Error: 3% (best) to 10% 

A: Circuit Analysis

Below you have the schematic diagram of the device. As it is clear, the heart of the circuit is the RP2040-Zero board [1]. Figure 1 shows the pinout. 

Test of button

RP2040-Zero Board Pinout

Figure 1: RP2040-Zero Board Pinout

A-1: Power Supply

The board can be powered either using a USB Type-C cable (C-Pow connector in the schematic), a mobile-phone charger for instance, or through an XH wire-to-board connector (POW connector in the schematic). The supply voltage in both cases should be 5V.

FB1, C6, C8, and C11 are used to reduce the input voltage noises. The connection point of the Relay’s supply is before FB1. REG1 is the famous 1117-3.3 regulator [2] that stabilizes the voltage at 3.3V. D4 is an LED to indicate a proper supply connection and R8 limits the current to D4. C7 and C9 are output capacitors for noise reduction and output stabilization.  For the full power handling of USB-Type C, CC1 and CC2 pins of the C-Pow connector should be pulled down using R9 and R13 resistors.

D3 is the SS14 Schottky diode [3] to protect the supply and the board when both the USB connection of the RP2040 and the supply of the board (either USB Type-C or XH connector) are connected.

A-2: Relay

The Relay driver circuit consists of Q1 Mosfet (Si2302) [4] and a few other components. R5 is a pull-down resistor to prevent unwanted triggering of the Q1 gate. D1 protects the Mosfet against Relay’s coil reverse currents and C1 damps possible voltage spikes. D2 is a Red LED to indicate the ON/OFF status of the Relay (LM1-5D [5]).

A-3: Push Buttons

To modify the range finder parameters, I have implemented 3 tactile push-buttons (SW1, SW2, SW3). R10, R11, and R21 are pull-up resistors, and C10, C12, and C13 are used to debounce the push-button’s switch noises. In the code, I have implemented an RTOS task just to read the state of these buttons.

A-4: Buzzer

I have embedded a buzzer connector (BUZ on the schematic) to include distance-related acoustic signals to the board. You can enable/disable this feature on the GUI or modify the “Buzzer” task in the code to own your own sound pattern. T1 is the 2N7002 N-Channel Mosfet [6] to turn ON/OFF the Buzzer. R14 is a pull-down resistor to prevent unwanted triggering of the Gate pin of the Mosfet.

A-5: Laser Sensor

The VL53L0X [7] is the laser range finder module of the circuit (Figure 2). The VL53L0X 4-Pin XH pin header is the connector for the module. The RP2040-Zero and the VL53L0X communicate through I2C. Theoretically, it can measure distances up to 200cm away, however, in practice, the effective range heavily depends on sensor configuration, ambient conditions, and target characteristics like reflectance and size.

VL53L0X Time-of-flight Sensor

Figure 2: VL53L0X Time-of-flight Sensor

A-6: TFT Display

I used a colorful 2.4” 40-Pin TFT display. The resolution of the display is 320*240. The controller chip of the LCD is ILI9341. Figure 3 shows a picture of the LCD and pinouts. You must order an LCD type without a touch screen. In the schematic, C2 and C3 are decoupling capacitors for the TFT supply. R2, R3, and R4 define the TFT communication type (selection is 8-bit SPI). 

2.4” ILI9341 TFT display pinout

Figure 3: 2.4” ILI9341 TFT display pinout

B: PCB Layout

Below I share with you a PCB Layout project and an assembly drawings of this laser range finder. It’s a two layers PCB board and the majority of the components are SMD. I set the SPI speed at 40MHz. Therefore, the distance between the LCD FPC connector and the SPI pins of the RP2040 board is short.

Test of button

C. Assembly and Test

Figure 4 shows the fully assembled PCB board. The most difficult component to solder is the 40-Pins FPC connector. If you don’t have experience in micro-soldering and necessary equipment such as quality flux, soldering irons, hot air, and iron tips, please do some practice before, otherwise, it is pretty easy to damage the connector, PCB tracks, or build solder joints between the tiny 0.5mm-pitch pins of the connector.

After you finished soldering the PCB, power the board using a USB Type-C mobile charger or through the “POW” XH connector (5V). Erase the whole memory of the RP2040 MCU using the “flash_nuke.uf2” file, then burn the compiled “Laser.uf2” file into the chip.

Assembled PCB board of the RP2040-Zero Powered Laser Range Finder

Figure 4: Assembled PCB board of the RP2040-Zero Powered Laser Range Finder

You can download all project files, including project source code, from here

 

References

[1]: RP2040-Zero: https://www.waveshare.com/w/upload/4/4c/RP2040_Zero.pdf
[2]: TLV1117-3.3: https://octopart.com/tlv1117-33idcyr-texas+instruments-669250?r=sp
[3]: SS14 SMA: https://octopart.com/ss14-e3%2F5at-vishay-42333616?r=sp
[4]: Si2302 SOT23-3: https://octopart.com/si2302cds-t1-e3-vishay-44452855?r=sp
[5]: LM1-5D: https://octopart.com/lm1-5d-rayex-53719411?r=sp
[6]: 2N7002 SOT23-3: https://octopart.com/2n7002-7-f-diodes+inc.-335069?r=sp
[7]: VL53L0X TOF: https://octopart.com/3317-adafruit+industries-76907295?r=sp
 

About Author

About Author

Hesam Moshiri holds an MSc degree in Embedded Systems Design and is interested in Electronic Design and A.I. He also has experience and interest in content/digital marketing. He owns a YouTube channel named "MyVanitar" that talks about electronic projects and design/measurement tips.

Related Resources

Back to Home
Thank you, you are now subscribed to updates.