Interactive Light Ball

Introduction: Interactive Light Ball

It's simple project based on ws2812 led strip controlled by arduino and gyroscope. The idea is to put led light into transparent matt plastic ball and control colorof led by rotating and position of ball.

Step 1: Wirig

Used components:

Ardiono nano

8-led ws2812 strip

Gyroscope GY-521

on/off swich

any battery box (e.g. 18650)

WS2812 connected to arduino gnd-gnd, vin-5v, din-D4

GY-521 connected to arduino standard manner vcc-3v3, gnd-gnd, sda-A4, scl-A5, int - d2

battery connected to vin and gnd through on/off switch

all components was put into half of ball box and fixed by hot melt glue.

Step 2: Programming

To programm scheme will be required libraries




I used OUTPUT_READABLE_EULER gyroscope mode to read Euler angles (alfa, beta & gamma) in radians. So rotaning ball around gyroscope we can get Euler angles into arduino.

Then we can mathematically transform angles (alfa, beta & gamma) into colors (RGB) of each ws2812 leds.

The way of transformin angles into RGB is the most interesting part of programming.

I use next way:

byte cycl = (millis()/100) % 8; // cycl is counter of each 100 millesec from 0 to 7 (0,1,2,3,4,5,6,7,0,1 etc.). You can change 100 to control speed of transfusions.

byte R = abs(euler[0]) * 255/M_PI; // euler[0] - is alfa angle, R is red color from 0 to 255

byte G = abs(euler[1]) * 511/M_PI; //euler[1]is beta angle, G is green color from 0 to 255

byte B = 255 - (abs(euler[2]) * 255/M_PI) ; //euler[2] is beta angle, B is blue color from 0 to 255

for (byte i=0;i

pixels.setPixelColor( (i+cycl)%8, pixels.Color(R+ 4*i ,(B + 5*i), (G - 6*i))); };

Then we switch on counter 0 to 7 that set the appropriate RGB colors set to appropriate led and then lit it.

(i+cycl)%8 - is number of led, it's need to set transfusions effect on led strip.

RGB set controls by pixels.Color(R+ 4*i ,(B + 5*i), (G - 6*i)) to slow change color of each led. You can change coefficients +4, +5, -6, or swap R, G and B to find new interesting effects.

So you can rotate or rock light ball to find necessary color, use it as baby toy or mood lamp. Enjoy!

ps If you find mistakes or succeeded to develop project please comment.

Be the First to Share


    • Make it Glow Contest

      Make it Glow Contest
    • First Time Author Contest

      First Time Author Contest
    • PCB Challenge

      PCB Challenge