1. Purpose of the Case

Learn to use the ToF (Time of Flight) module and create more interesting interactive applications.

ToF (Time of Flight) works by emitting infrared laser light, measuring the time it takes for the light to reach an object and reflect back, thereby obtaining precise distance data. It has excellent adaptability to lighting conditions and is unaffected by the reflectivity of the target, allowing it to work stably in various lighting conditions and usage scenarios.

2. Materials Used

CoCube Robot × 1 ToF External Module Personal Computer or Tablet

3. Software Platform

MicroBlocks——CoCube & CoCube Module

4. Quick Experience

  1. Connect Device: Connect the MicroBlocks IDE to the CoCube robot via a wired or wireless connection, and attach the ToF module to the CoCube robot.

  2. Add Block Library: Under the "Robot" directory, add the "CoCube Module Library" — this library includes all the functions of the ToF external module: "ToF Connected" and "ToF Distance (mm)."

  • ToF Connected: Drag out the "ToF Connected" block, place it in the workspace, and click to run. This block checks whether the CoCube robot is connected to the ToF laser rangefinder module.

Note: Since the module requires some time to power up, there’s a chance that the first run might return "false." Simply click to run again.

  • ToF Distance (mm): Drag out the "ToF Distance (mm)" block and click to run. This will return the distance from the ToF laser rangefinder sensor to the obstacle in front.

If you want to output the measurement results in real-time, you can write the following program:

5. Advanced Features

Can you write a program that controls the CoCube robot to follow your hand? If the CoCube is far enough from the obstacle in front, it moves forward; if the CoCube is close to the obstacle, it reverses.

Example Program – Think and Try First!

6. Challenge Yourself

Using materials at hand, build a simple 3D maze! Then try writing code to make the CoCube robot autonomously navigate out of the maze using the ToF laser rangefinder module.

7. Reference Code Examples

All tutorial code examples above:

MicroBlocks —— ToF Laser Rangefinder Module Cases

CC-BY-SA

© by CoCube 2024-2025.

This work is licensed under a CC-BY-SA 4.0 license.