⭐ Beginner ⏱️ 10 minutes

Rainbow Ring

With the LED ring, you make a spinning rainbow. Each light gets a different color, and all colors move around.

First you log in for a moment. Then your project is ready right away.

🧰 What do you need?

1× Arduino UNO
1× RGB LED ring (8 LEDs)
🔌
USB cable + Jumper wires

🗺️ Wiring diagram

Follow the wires from the Arduino to each part. You can choose the wire colors yourself.

From To
Arduino UNO · D6 RGB LED ring (8 LEDs) · DI
Arduino UNO · 5V RGB LED ring (8 LEDs) · 5V
Arduino UNO · GND RGB LED ring (8 LEDs) · GND

🛠️ This is how you build it

  1. Connect the LED ring: DI to pin 6, 5V to 5V, and GND to GND.
  2. That is all! Leave DO free.

💻 The code

// Rainbow ring
// The LED ring spins all the colors of the rainbow around.

#include <Adafruit_NeoPixel.h>

const int RING_PIN = 6;     // DI of the ring is on pin 6
const int LED_COUNT = 8;  // The ring has 8 lights
const int SPEED = 20;    // Smaller means it spins faster

Adafruit_NeoPixel ring(LED_COUNT, RING_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  ring.begin();
  ring.setBrightness(40);   // Not too bright: 0 = off, 255 = super bright
  ring.show();
}

void loop() {
  // Move the rainbow a little bit each time
  for (long color = 0; color < 65536; color += 512) {
    for (int i = 0; i < LED_COUNT; i++) {
      // Each light gets a slightly different color
      long lightColor = color + (i * 65536L / LED_COUNT);
      ring.setPixelColor(i, ring.gamma32(ring.ColorHSV(lightColor)));
    }
    ring.show();
    delay(SPEED);
  }
}

🧠 What does the code do?

  • We use the Adafruit_NeoPixel library to control the ring.
  • ColorHSV() makes a color from the rainbow. Each light gets a spot a bit further in the rainbow.
  • By moving the color a little each time, the rainbow looks like it is spinning around.

🎯 Try this…

  • Make the rainbow spin twice as fast
  • Turn it into a police light that flashes red and blue in turns
  • Make one light go around in circles, like a little light running around

🚀 Build this project with Codey: open codey.online/starter-kits/uno/projects/rainbow-ring and click MAKE THIS. Then the code and the wiring diagram are ready right away.

First you log in for a moment. Then your project is ready right away.
⬇️ Download this page as a PDF 📚 Download the complete tutorial (PDF)

Codey Online is a product of OTRONIC

Build your Arduino or ESP32 project with AI

Describe what you want to build. Codey Online writes the code, draws the wiring diagram, compiles it and flashes your board straight from the browser.

Start for free