loader

Activity No. 6: Measure a distance and display the value in the serial console (IoT sensors kit)

Using the Time of Flight module with the NUCLEO-L476RG board

 The Time of Flight distance sensor is a module that measures the distance between the sensor and an object up to at 200cm.

The operating principle is simple. This sensor emits a laser (940nm) invisible to the human eye and calculates the time that the emitted photons take to return to the receiver. It thus determines the distance separating the sensor from the object. The information returned by the sensor is the distance in millimeters or centimeters. 


zoom-TOF-EN

To measure the distance using the NUCLEO-L476RG card, the following connection must be made: 
- Connect the NUCLEO-Shield to the connectors on the card. 
- Connect, using the Grove cable, the Time Of Flight module to one of the available ports named I2C.
- Connect the L476RG board to the computer using the mini-USB cable.

iot-TOF-EN

Let's get to the programming now! 

We are going to use two blocks:
- "write in the console", available in the Communication of the block locker to manage the display.
- "[Time Of Flight] Distance in cm ", available in the Sensors, to retrieve the value of the module.

tof-en

Use the following interface to program the module: 


The distance will be displayed in the console, at the bottom of the interface.
iot-console-tof-FR

Once the program has been created, it must be copied onto the card. To do this, you must use the "Upload" button (see Activity 0: Getting started with the board).

We are now going to create a text, to make it easier for the user to read. 

You must use the "create the text ... ... ... " block available in the Text part of the block locker, combining it with the block ("...") which allows you to write. 

text-en

Here is an example of ready-to-use code:



This code includes:
- the display of a text composed of the word "Distance:" + the value of the sensor + the 'cm' symbol
- a 1 second pause to facilitate reading

Download the program to the card and launch the console to view the distance measured.

You succeeded ? Perfect, you now know how to program the temperature sensor using your NUCLEO-L476RG board!
Discover the other activities of the IoT Sensors kit by clicking on the icons below.

Användarlicens