How to use a ToF laser ranging sensor with Arduino and Wisblock

WisBlock RAK12014 ToF module
The WisBlock RAK12014 ToF sensor module adopts ST VL53L0X, the world’s smallest ToF ranging sensor

Laser ranging has many applications in production and life, such as ranging, positioning, obstacle avoidance, and so on. Time-of-Flight (ToF) ranging, as a type of laser ranging technology, is often used for real-time object detection in robots, autonomous vehicles, and traffic management because of its accuracy, fast response, and low power consumption. The face detection function of mobile phones also uses this technology.

This article will introduce the WisBlock RAK12014 ToF laser ranging sensor module, and use the WisBlock development board to demonstrate how the module works.

What is a ToF laser ranging sensor module?

A ToF laser ranging sensor module uses laser pulses to measure the distance between itself and a target object. The WisBlock RAK12014 ToF laser ranging sensor module is based on STMicro VL53L0X, the smallest ToF ranging sensor in the world.

The WisBlock RAK12014 provides accurate distance measurement and can measure distances up to 2 meters. Its 940nm VCSEL transmitter (Vertical Cavity Surface Emitting Laser) is completely invisible to the human eye, and coupled with the built-in physical infrared filter, it has a longer ranging distance, and stronger immunity to ambient light. In other words, the sensor provides accurate distance measurements regardless of the target’s reflectivity.

RAK12014 ToF module Wisblock
RAK12014 ToF sensor module connected to WisBlock modular hardware development platform

RAK12014 module’s key features and specifications:

  • Range up to 2 meters
  • I2C interface for device control and data transfer
  • Shutdown (reset) and interrupt GPIO
  • Power Supply – 2.6~3.5 V
  • Dimensions – 10 x 10 mm

The RAK12014 module contains a 24-pin connector compatible with the sensor socket of the WisBlock baseboard. The RAK12014 module can be installed on a WisBlock base (eg RAK5005-O) module through this connector. The pin order and pin definitions of this connector are shown in the figure below.

RAK12014 pinout
RAK12014 pinout

Note: Only I2C pins, SHUT (reset), INT, 3V3_S, and GND are wired to the connector of this module.

RAK12014 example: display distance on an OLED Display

We’ll use RAK12014 in a very typical application: displaying the measured distance on an OLED display.

In this example, we’ll connect the RAK12014 to the RAK 5005-O base, and the distance measurement and the OLED will be controlled through an Arduino sketch running on the RAK4631 module.

Arduino project with Wisblock, OLED, ToF sensor, nRF52840 core board

List of WisBlock items and cables used for this project:

  • Rakwireless RAK12014 ToF sensor
  • Rakwireless RAK4631 nRF52840 BLE xore module for LoRaWAN
  • Rakwireless RAK5005-O WisBlock base board
  • Rakwireless RAK1921 OLED display
  • Jumper cables and a USB cable for power
STM32 ToF connection diagram
Connection diagram

Here are the specific steps to implement this project:

  1. Install the OLED library (U8g2)To control the OLED display, you need to use the “U8g2” library.Arduino U8g2 library installation
  2. Install ToF Laser Ranging Sensor LibraryTo control the ToF laser ranging sensor module, the “stm32duino_vl53l0x” Arduino library is required.
    STM32duino VL53L0X ToF Sensor Arduino library
    Note: After all libraries are installed, you need to restart the Arduino IDE for the installed libraries to take effect.
  3. Import codeThen import the code into the libraries required for the OLED display and the ToF laser ranging sensor module, and define two objects named “u8g2” and “sensor_vl53l0”:
  4. GetDistance() functionThe GetDistance() function will gather the data from the ToF sensor, and display the distance on the OLED, or if there is no data, display “Nothing at all”:
  5. setup() functionIn the setup() function, both the ToF laser ranging sensor and the OLED display are initialized. We also print a message on the serial monitor in case the VL53L0X sensor’s initialization failed:
  6. loop() functionThe main loop calls the GetDistance() function every 300ms.
  7. Code uploadWe can now load our Arduino sketch to the RAK4631 development board. Selected the board in the Arduino IDE, as well as the correct port, and start the code uploading and flashing. You may also want to open the serial monitor of the Arduino IDE, selecting a 111500 bps baud rate to monitor the ranging data from the ToF laser ranging sensor module.
    RAK12014 Arduino
  8. Video demo

Final words

The ToF laser ranging sensor module can be used in a wide range of applications and scenarios All the data gathered from the sensor could also be uploaded directly to the cloud for real-time analysis. This article mainly shows you how to use the ToF laser ranging sensor module to measure the distance of an object from the sensor.

For reference, please find the complete Arduino sketch for this ToF ranging sensor project:

This is a translation, with some edits, of the tutorial posted in Chinese on CNX Software China.

Share this:

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

ROCK Pi 4C Plus
Notify of
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.
Khadas VIM4 SBC