Maybe not exactly gesture recognition. Let's say that we put the basics to do it through two laser sensors of the type VL53L0X.

With only two sensors the number of movements that can be recognized are rather limited, I have chosen the movement of the hand with the rotation of the wrist in order to move accordingly a led strip and realize an optical play. The effect is visible in the video at the bottom of the post.

To use two laser sensors, the electrical connections are as shown in the diagram below. To connect the LEDs, refer to the post "Yet another way to have a led blinking". The power supply can be obtained with two AA batteries serially connected.


The project is based on the VL53L0X.c library that I built following the example of the Arduino library. Beware that this is a first draft and, especially for the few documentation available on internet, there are many unexplained points, so I do not recommend the use of this library for professional projects.

The entire project can be downloaded from github, for complete understanding it is necessary to know that before you can use the above mentioned library you need the microcontroller setup that I made using the MCC tool. These are:

  1. I have set the system clock to 64MHz (see "Yet another way to have a led blinking").
  2. I have set the Ports to manage LED (see "Yet another way to have a led blinking").
  3. I have set timer0 with a period of 1msec and I have enabled IRQ (see "Yet another way to have a led blinking").
  4. I have set I2C serial bus in fast mode (see "I2C Detect").

This is the premise, we are going to see the most significant points to understand the library.


Since two lasers are used, and since each one of these lasers has its own settings, it is necessary to create a structure in which to store the respective values. This is the VL53L0XDEV structure. Next, an array is created that can contain the structures defined above for an arbitrary number of sensors.

The first laser statement performed in the main() section is VL53L0X_InitDevices(). Below is the content of this function.

init devices

It is important to note that at the power-up the lasers have the same I2C address, consequently they would be in conflict being connected to the same bus. Using the enabling pins (LASER0 and LASER1 connected to the XSHUT pins of the sensors) both are switched off; then the desired address values are loaded into the respective structures (I have defined these values in the header file); so you can turn on one laser at a time to give it the appropriate I2C address.

To allow the library to act on the data of the respective sensors, the address of the sensor structure is passed as a parameter to the various functions called (such as the Init function).

If you want to go on and discover the Init function, you would find a rather long sequence of entries in the sensor registers. This sequence is necessary for calibrating the sensor and for selecting the type of operation. It is important to remember that whenever the sensor is disabled via the XSHUT pin it is necessary to repeat the procedure.

Once the sensors have been initialized, all that remains is to choose whether to make single measurements or to instruct the sensor to make repeated measurements at maximum speed. These settings are present in the main.c file.


As indicated in the comment for details refer to the readme file, here I limit myself to pointing out that the first four options are complementary to the one selected (CONTINUOUS), in the case of the single readings (SINGLE_SHOT) it is possible to select the type of operation you want: accurate or fast.

Another clarification regarding the differences between CONTINUOUS and SINGLE_SHOT. With the second option you can still continue to interrogate the sensor in "continuous" mode through the while loop, but you will never get the same speed you can get by setting the CONTINUOUS mode. In this mode it is the sensor that takes the effort to make readings at full speed, the program does just have to query the reading register to see if it has been updated. It is what is performed in the code that follows.


The second parameter of the ContinuousReading function is an arbitrary number of milliseconds to insert between one reading and the next. The next part of the while loop (of which I report only the first section) concerns the lighting of the LEDs. 

ifelseI reject all measurements above 60cm, then comparing the measurements of the two lasers, I switch on one led and turn off the remaining ones. To get the effect shown in the video I placed the two lasers on the same axis at a distance of about 7cm.


download project