Boomerang LED (Come and Go)

dnetto, arduinoc-plus-plusledembeddedhardware
Back

This project implements the classic LED Scanner effect (frequently associated with K.I.T.T. from the TV series Knight Rider or the Cylons from Battlestar Galactica). The light beam goes from one end of the LED strip to the other and bounces back, leaving a smooth trailing light (tail) behind it.

It is a highly visual and simple effect to implement on WS2812B (NeoPixels) addressable LED strips using microcontrollers like Arduino.


🛠️ How it works?

The project uses the EasyNeoPixels.h library to abstract the communication with the strip.

The smoothness of the movement and the length of the trailing light tail are controlled by parameters at the start of the code. The brightness decay is calculated using bitwise shifts (brightness >> t) for high performance even on 8-bit microcontrollers.

📐 Settings and Parameters

#define PIN 6    // Data pin connected to the LED strip
#define LEN 10   // Total number of LEDs on the strip
#define TAIL 3   // Length of the LED trailing tail
#define DELAY 50 // Transition speed (in milliseconds)

💻 Algorithm Implementation

Below is the complete C++ code to upload to your Arduino:

#include <EasyNeoPixels.h>

#define PIN 6	
#define LEN 10
#define TAIL 3
#define DELAY 50

void setup() {
  setupEasyNeoPixels(PIN, LEN);
}

void loop() {
  // Forward Movement
  for (int i = 0; i < LEN; i++) {
    writeEasyNeoPixel(i, 255, 0, 0); // Turn current LED on full brightness (Red)
    
    // Create the tail by fading previous LEDs
    for (int t = 1; t <= TAIL; t++) {
      if (i - t >= 0) {
        writeEasyNeoPixel(i - t, 255 >> t, 0, 0); // Dim the brightness (shift right)
      }
    }
    
    // Turn off the LED that left the tail range
    if (i - TAIL - 1 >= 0) {
      writeEasyNeoPixel(i - TAIL - 1, 0, 0, 0);
    }
    delay(DELAY);
  }

  // Backward Movement
  for (int i = LEN - 1; i >= 0; i--) {
    writeEasyNeoPixel(i, 255, 0, 0);
    
    for (int t = 1; t <= TAIL; t++) {
      if (i + t < LEN) {
        writeEasyNeoPixel(i + t, 255 >> t, 0, 0);
      }
    }
    
    if (i + TAIL + 1 < LEN) {
      writeEasyNeoPixel(i + TAIL + 1, 0, 0, 0);
    }
    delay(DELAY);
  }
}

📸 Visual Demo

Boomerang LED Effect Demo

🔗 Source Code

Daniel Netto Logo2026 © Daniel Netto. Todos os direitos reservados.
Hospedado por Verceldnetto.dev