VL53L1X sensor with RGB Ledstrip

Simulation of anxiety: pulsing rainbow heartbeat pattern on a LED strip that intensifies when something get closer…

This project combines two examples:

We will use a Seeed Studio XIAO which is a small microcontroller, but this can be done with any Arduino or ESP module you have at hand.

For code generation, GitHub Copilot is used.

Setting up the circuit

Connect the SCL & SDA pins of the VL53L1X sensor to those of the Seeed Studio XIAO (D4 is SDA and D5 is SCL). More help is in the tutorial of the VL53L1X sensor.

Next, verify if the sensor works:

Start the Arduino IDE and install the Seeed Studio boards according to the instructions.

Connect the Seeed Studio XIAO to your computer (USC-C cable).
Setup the board:

Install the VL53L1X library (Tools > Manage Libraries, search for “VL53L1X”).
The code and documentation of that library, including the examples of this library is available on Github.

Run the example sketch that comes with the library, eg. “Continuous” via File > Examples > VL53L1X.

Next, connect the LED strip (WS2812B strip with 8 LEDs) according to this tutorial. But connect the datapin of the strip to pin 6 of the Seeed Studio XIAO, as pin 4 & 5 are already taken by the SCL & SDA pins (for the sensor).

Install the fastled library (Tools > Manage Libraries).

Open this fastled_2812.ino example sketch in the Arduino IDE. At line 21 alter:

#define DATA_PIN 5

make that:

#define DATA_PIN 6

Now run the fastled_2812.ino sketch. Check if the strip works properly.

Generate code for the heartbeat pattern using GitHub Copilot

We will use generative AI to turn this into an example of a pulsing hearbeat, simulating anxiety as something approaches.

The opening prompt below was used to ask Copilot to combine the two examples into one:

I have an Seeed Studio XIAO with two components connected:
1. a VL53L1X sensor connected to D4 (SDA) and D5 (SCL) of the Seeed Studio XIAO.
2. a WS2812B LED strip with 8 LEDs, datapin connected to pin 6 of the Seeed Studio XIAO.
For each, I have a seperate, working example:
https://github.com/vanslooten/Arduino_examples/blob/master/distance_tof_VL53L1X_Continuous.ino
https://github.com/vanslooten/Arduino_examples/blob/master/fastled_2812.ino

I would like you to generate a new sketch that combines the two examples:

It shows a heartbeat pattern on the LED strip. The heartbeat will beat faster when distances are closer.
The normal heartbeat will be around 300 mm distance. Closer means faster. More than 400 mm, the LEDS will turn off.
The distance limits must be defined at the beginning of the sketch.

After a few iterations, this was the code that came out. It’s a nice example how generative AI can speed up the development code. See the full conversation with Copilot here.

The generated code is here.

The result

The video below demonstrates the result.

Result of the circuit

Similar projects