Learn electronics, coding, and projects — step by step.

009 - MakeCode MicroBit: Brickcell TOF VL53L0X

George Bantique October 7, 2023 No Comments

Table of Contents

VL53L0X Time-of-Flight (ToF) Distance Sensor

The VL53L0X Time-of-Flight (ToF) sensor is a miniature, highly advanced distance sensor designed to measure distances accurately and quickly. It operates based on the principle of time-of-flight, where it emits a laser or infrared light pulse and measures the time it takes for the light to bounce back after hitting an object. This allows it to calculate the distance to the object in front of it with high precision.

VL53L0X ToF sensors are often used in various applications, including robotics, drones, gesture recognition systems, and even in smartphones for functions like proximity sensing and autofocus in cameras. They offer benefits such as fast and accurate distance measurement, compact size, and low power consumption.

Hardware Instruction

Let's explore how to connect the VL53L0X Time-of-Flight distance sensor to a micro:bit microcontroller and utilize MakeCode for programming.

  1. Connect the TOF distance sensor GND pin to micro:bit GND pin.
  2. Connect the TOF distance sensor VCC pin to micro:bit VCC pin.
  3. Connect the TOF distance sensor serial data pin (SDA) to micro:bit pin 20.
  4. Connect the TOF distance sensor serial clock pin (SCL) to micro:bit pin 19.

Software Instruction

Now, let's start programming the micro:bit to utilize the VL53L0X TOF distance sensor.

  1. Login to https://makecode.microbit.org/ using your Microsoft account.
  2. Create a new project by clicking the "New Project" button. You may name it anything you want; I suggest naming it descriptively such as "tof-vl53l0x-test".
  3. Click the "Extensions" block just under the "Math" block.
  4. Type https://github.com/gbantique/brickcell-tof-vl53l0x/ in the search bar.
  5. Select the "brickcell-tof-vl53l0x" from the search results. The "tof vl53l0x" block should appear under the "Brickcell" block.
  6. Copy the code provided below.
    
    Brickcell.init()
    basic.forever(() => {
        serial.writeNumber(Brickcell.distance())
        serial.writeString("\r\n")
        basic.pause(1000);
    })
    
  7. Open a Serial Monitor such as Termite terminal app https://www.compuphase.com/software_termite.htm/ . Set the baud rate to 115200 bps.

Or you can make a copy of my created project in your MakeCode workspace.

https://makecode.microbit.org/S55676-77516-83467-70824/

Expected Result

If you carefully follow the provided instructions above, you should be able to view the measured distance on the serial terminal every 1000 milliseconds.

×

Leave a Reply

Required fields are marked *






Related Articles: (by Categories)