STEMpedia
Published © GPL3+

DIY RGB LED Goggles

This project's about making a pair of cool RGB LED goggles with controllable shades that can be turned up or down as and when you like!

IntermediateFull instructions provided4 hours942

Things used in this project

Hardware components

evive
STEMpedia evive
×1
evive Starter Kit
STEMpedia evive Starter Kit
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

Circuit Diagram

Circuit DIagram of RGB LED Goggles

Connecting LEDs

Circuit DIagram of RGB LED series connection

Code

Arduino Code for LEDs

Arduino
Here, we are using this code to make LED strip glow in 8 different patterns.
#include <Adafruit_NeoPixel.h>
#include<evive.h>

Servo myServo;

#define NeoPixel_pin 2
#define Number_of_NeoPixel 48

unsigned char statechanged =0;
unsigned char pressed2 =0;

unsigned int  A[] = {0,6,7,14,15,21,22,25,26,32,33,40,41,47};
unsigned int  B[] = {1,5,8,13,16,20,23,24,27,31,34,39,42,46};
unsigned int  C[] = {2,4,9,12,17,19,48,48,28,30,35,38,43,45};
unsigned int  D[] = {48,3,10,11,18,48,48,48,48,29,36,37,44,48};
unsigned char grip[] = {0 ,75};
boolean state = false;
unsigned char pressed1 =0;
unsigned int button = 38;

unsigned int pattern[] = {2,3,10,11,18,19,23,24,28,29,36,37,44,45};
unsigned int circle1[22]= {0,1,2,3,10,11,18,19,20,21,15,14,7,6,5,4,9,12,17,16,13,8};
unsigned int circle2[22]= {26,27,28,29,36,37,44,45,46,47,41,40,33,32,31,30,35,38,43,42,39,34};
unsigned int glass1[16]={22,21,15,14,7,6,0,1,2,3,10,11,18,19,20,23};
unsigned int glass2[16]={25,26,32,33,40,41,47,46,45,44,37,36,29,28,27,24};



Adafruit_NeoPixel strip = Adafruit_NeoPixel(Number_of_NeoPixel,NeoPixel_pin , NEO_GRB + NEO_KHZ800);
uint32_t red_color = strip.Color(150,0,0);
uint32_t green_color = strip.Color(0,150,0);
uint32_t blue_color = strip.Color(0,0,150);
uint32_t pink_color = strip.Color(150,0,150);
uint32_t Blue1_color = strip.Color(0,150,150);


void setup() {
  // put your setup code here, to run once:
   Serial.begin(250000);
 
   pinMode(button,INPUT);

   myServo.attach(44);
   strip.begin();
   strip.setBrightness(128);
   strip.show();
   myServo.write(0);


}

void loop() {
  // put your main code here, to run repeatedly:
    rainbowCycle(10);
    rainbow(10);
    color_change();
    chase();
    random_pattern();
    Scanning();
    Clear();
    circle();
    delay_ms(250);
    glass();
    delay_ms(2000);
    Clear();
    flag();
    delay_ms(3000);
  }
 
 

 
   
 
  
void Scanning()
{
  for(int i=0;i<5;i++)
{
  Servo_motion();
  uint32_t x =random(0,5);
  if(x==0) x =red_color;
  else if(x==1) x = green_color;
  else if(x==2) x =blue_color;
  else if(x==3) x = pink_color;
  else if(x==4) x= Blue1_color;
  Move_forward(x);
  Move_backward(x);
}
}
void pixel(uint8_t Position , uint32_t c)
{
  strip.setPixelColor(Position, c);
}
void Clear()
{
  for( unsigned int i =0;i<Number_of_NeoPixel;i++)
  {
    strip.setPixelColor(i,strip.Color(0,0,0));
  }
  strip.show();
}
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay_ms(wait);
  }
}
void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay_ms(wait);
  }
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay_ms(wait);
  }
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j=0; j<10; j++) {  //do 10 cycles of chasing
    Servo_motion();
    for (int q=0; q < 3; q++) {
      Servo_motion();
      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, c);    //turn every third pixel on
         Servo_motion();
      }
      strip.show();

     delay(wait);

      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
        Servo_motion();
      }
    }
  }
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}


void color_change()
{
  colorWipe(strip.Color(255, 0, 0), 50); // Red
  colorWipe(strip.Color(0, 255, 0), 50); // Green
  colorWipe(strip.Color(0, 0, 255), 50); // Blue
  colorWipe(strip.Color(255,0,255),50);  // Red+BLUE
  colorWipe(strip.Color(0,255,255),50); // Green+BLUE
  
}

void chase()
{
   theaterChase(strip.Color(127, 0, 0), 50); // Red
   theaterChase(strip.Color(0, 127, 0), 50); // green
  theaterChase(strip.Color(0, 0, 127), 50); // Blue
  theaterChase(strip.Color(127, 0, 127), 50); // Red+blue
  theaterChase(strip.Color(0, 127, 127), 50); // Blue+green
}
void Move_forward(uint32_t color)
{

 for(int i=0;i<14;i++)
 {
  pixel(A[i],color);
   pixel(B[i],color);
    pixel(C[i],color);
     pixel(D[i],color);
     if(i>3)
     {
      pixel(A[i-4],strip.Color(0,0,0));
      pixel(B[i-4],strip.Color(0,0,0));
       pixel(C[i-4],strip.Color(0,0,0));
        pixel(D[i-4],strip.Color(0,0,0)); 
     }
    
    
     strip.show();
    
     delay_ms(30);
  
 }
 for(int i =10;i<14;i++)
 {
   pixel(A[i],strip.Color(0,0,0));
      pixel(B[i],strip.Color(0,0,0));
       pixel(C[i],strip.Color(0,0,0));
        pixel(D[i],strip.Color(0,0,0)); 
        strip.show();
        delay_ms(30);

 }
 
 
 //Clear();
}
 void Move_backward(uint32_t color)
 {

 for(int i=13;i>=0;i--)
 {
  pixel(A[i],color);
   pixel(B[i],color);
    pixel(C[i],color);
     pixel(D[i],color);
     if(i<10)
     {
       pixel(A[i+4],strip.Color(0,0,0));
       pixel(B[i+4],strip.Color(0,0,0));
        pixel(C[i+4],strip.Color(0,0,0));
         pixel(D[i+4],strip.Color(0,0,0));
     }
     
     
   
     strip.show();
     
     delay_ms(30);
 }
 for(int i=3;i>=0;i--)
 {
  pixel(A[i],strip.Color(0,0,0));
       pixel(B[i],strip.Color(0,0,0));
        pixel(C[i],strip.Color(0,0,0));
         pixel(D[i],strip.Color(0,0,0));
         strip.show();
         delay_ms(30);
  
 }
 
 
}

void random_pattern()
{
  for(unsigned int i=0;i<100;i++)
  {
    Servo_motion();
   
  for(unsigned int i=0;i<14;i++)
         {
    Servo_motion();
                unsigned int base = pattern[i];

                if( i==0 || (i%2) ==0)
                      {
                           if(i==0 || i==8)
                                   {
                                        unsigned int x = random(0,3);
                                        unsigned char red = random(0,127);
                                        unsigned char green = random(0,127);
                                        unsigned char blue = random(0,127);
                                        if( x == 0)
                                                 {
                                                     strip.setPixelColor(base,strip.Color(red,green,blue));
                                                 }
                                        else if(x ==1)
                                                  {
                                                    strip.setPixelColor(base,strip.Color(red,green,blue));
                                                    strip.setPixelColor(base-1,strip.Color(red,green,blue));
                                                  }
                                                 else  if(x==2)
                                                  {
                                                     strip.setPixelColor(base,strip.Color(red,green,blue));
                                                    strip.setPixelColor(base-1,strip.Color(red,green,blue));
                                                     strip.setPixelColor(base-2,strip.Color(red,green,blue));
                                                  }
                                     }
                                     else if(i==6)
                                     {
                                      unsigned int x = random(0,2);
                                              unsigned char red = random(0,127);
                                              unsigned char green = random(0,127);
                                              unsigned char blue = random(0,127);

                                               if( x == 0)
                                                 {
                                                     strip.setPixelColor(base,strip.Color(red,green,blue));
                                                 }
                                        else if(x ==1)
                                                  {
                                                    strip.setPixelColor(base,strip.Color(red,green,blue));
                                                    strip.setPixelColor(base-1,strip.Color(red,green,blue));
                                                  }

                                              
                                     }
                           else
                                     {
                                              unsigned int x = random(0,4);
                                              unsigned char red = random(0,127);
                                              unsigned char green = random(0,127);
                                              unsigned char blue = random(0,127);
                                              if( x == 0)
                                                      {
                                                        strip.setPixelColor(base,strip.Color(red,green,blue));
                                                      }
                                              else if(x ==1)
                                                {
                                                  strip.setPixelColor(base,strip.Color(red,green,blue));
                                                  strip.setPixelColor(base-1,strip.Color(red,green,blue));
                                                }
                                              else if(x==2)
                                              {
                                                 strip.setPixelColor(base,strip.Color(red,green,blue));
                                                strip.setPixelColor(base-1,strip.Color(red,green,blue));
                                                 strip.setPixelColor(base-2,strip.Color(red,green,blue));
                                              }
                                              else  if(x==3)
                                              {
                                                 strip.setPixelColor(base,strip.Color(red,green,blue));
                                                strip.setPixelColor(base-1,strip.Color(red,green,blue));
                                                 strip.setPixelColor(base-2,strip.Color(red,green,blue));
                                                 strip.setPixelColor(base-3,strip.Color(red,green,blue));
                                                 
                                              }
                                              
                                      }
      
      
      
      
                                 }
   
               else
               {
                if(  i==5|| i==13)
                {
                                              unsigned int x = random(0,3);
                                              unsigned char red = random(0,127);
                                              unsigned char green = random(0,127);
                                              unsigned char blue = random(0,127);

                                              if( x == 0)
                                                 {
                                                     strip.setPixelColor(base,strip.Color(red,green,blue));
                                                 }
                                        else if(x ==1)
                                                  {
                                                    strip.setPixelColor(base,strip.Color(red,green,blue));
                                                    strip.setPixelColor(base+1,strip.Color(red,green,blue));
                                                  }
                                                 else  if(x==2)
                                                  {
                                                     strip.setPixelColor(base,strip.Color(red,green,blue));
                                                    strip.setPixelColor(base+1,strip.Color(red,green,blue));
                                                     strip.setPixelColor(base+2,strip.Color(red,green,blue));
                                                  }
      
                }
                else if(i==7)
                {
                                              unsigned int x = random(0,2);
                                              unsigned char red = random(0,127);
                                              unsigned char green = random(0,127);
                                              unsigned char blue = random(0,127);
                                              if( x == 0)
                                                 {
                                                     strip.setPixelColor(base,strip.Color(red,green,blue));
                                                 }
                                        else if(x ==1)
                                                  {
                                                    strip.setPixelColor(base,strip.Color(red,green,blue));
                                                    strip.setPixelColor(base+1,strip.Color(red,green,blue));
                                                  }

                  
                }
                else
                {
                                              unsigned int x = random(0,4);
                                              unsigned char red = random(0,127);
                                              unsigned char green = random(0,127);
                                              unsigned char blue = random(0,127);

                                               if( x == 0)
                                                      {
                                                        strip.setPixelColor(base,strip.Color(red,green,blue));
                                                      }
                                              else if(x ==1)
                                                {
                                                  strip.setPixelColor(base,strip.Color(red,green,blue));
                                                  strip.setPixelColor(base+1,strip.Color(red,green,blue));
                                                }
                                              else if(x==2)
                                              {
                                                 strip.setPixelColor(base,strip.Color(red,green,blue));
                                                strip.setPixelColor(base+1,strip.Color(red,green,blue));
                                                 strip.setPixelColor(base+2,strip.Color(red,green,blue));
                                              }
                                              else  if(x==3)
                                              {
                                                 strip.setPixelColor(base,strip.Color(red,green,blue));
                                                strip.setPixelColor(base+1,strip.Color(red,green,blue));
                                                 strip.setPixelColor(base+2,strip.Color(red,green,blue));
                                                 strip.setPixelColor(base+3,strip.Color(red,green,blue));
                                                 
                                              }
                }
                                              
                }
    
    
  }
  strip.show();
  delay(30);
  }
}
void circle()
{
  for(int i=0;i<22;i++)
  {
    Servo_motion();
    strip.setPixelColor(circle1[i],strip.Color(150,0,0));
    strip.setPixelColor(circle2[i],strip.Color(0,0,150));
    strip.show();
    delay(30);
  }
  delay_ms(50);
  for(int i=21;i>=0;i--)
  {
    Servo_motion();
     strip.setPixelColor(circle1[i],strip.Color(0,0,0));
    strip.setPixelColor(circle2[i],strip.Color(0,0,0));
    strip.show();
    delay_ms(30);
  }
}

void glass()
{

  for(unsigned int i=0;i<16;i++)
  {
    Servo_motion();
    strip.setPixelColor(glass1[i],strip.Color(150,0,0));
    strip.setPixelColor(glass2[i],strip.Color(150,0,0));
    strip.show();
    delay_ms(30);
  }
  strip.setPixelColor(8,strip.Color(0,0,150));
  strip.setPixelColor(9,strip.Color(0,0,150));
  strip.setPixelColor(12,strip.Color(0,0,150));
  strip.setPixelColor(13,strip.Color(0,0,150));
  strip.setPixelColor(34,strip.Color(0,0,150));
  strip.setPixelColor(35,strip.Color(0,0,150));
  strip.setPixelColor(38,strip.Color(0,0,150));
  strip.setPixelColor(39,strip.Color(0,0,150));
  strip.show();

  
  
}

void flag()
{
  unsigned int orange[14]={0,6,7,14,15,21,22,25,26,32,33,40,41,47};
  unsigned int white[14]={1,5,8,13,16,20,23,24,27,31,34,39,42,46};
  unsigned int Green[20] ={2,3,4,9,10,11,12,17,18,19,28,29,30,35,36,37,38,43,44,45};

  for(int i=0;i<14;i++)
  {
    Servo_motion();
    strip.setPixelColor(orange[i],strip.Color(150,50,0));
    strip.setPixelColor(white[i],strip.Color(100,100,100));
  }
  for(int i=0;i<20;i++)

  {
    Servo_motion();
   strip.setPixelColor(Green[i],strip.Color(0,150,0)); 
  }
 strip.setPixelColor(24,strip.Color(0,0,150)); 
 strip.setPixelColor(23,strip.Color(0,0,150));  
  strip.show();
}
void heart()
{
 unsigned int heart1[12]={32,34,41,47,27,39,26,30,43,36,37,46};
  unsigned int heart2[]={ };

  for(int i=0;i<12;i++)
  {
    
  strip.setPixelColor(heart1[i],strip.Color(150,0,0)); 
  strip.show();
  delay_ms(30);
  }
}

void delay_ms(uint32_t time_ms)
{
  for(unsigned int i=0;i<time_ms;i++)
  {
    Servo_motion();
    delay(1);
  }
}
void Servo_motion()
{
  
  
   if( digitalRead(button)==1)
   {
    if(pressed1==0)
    {
      state =!state;
      myServo.write(grip[state]);
      delay(15);
      pressed1 =1;
      
    }
   }
   else{
    pressed1=0;
       }
   }

  
   

Library for LED

C/C++
We have used these libraries to make the RGB LEDs glow.
No preview (download only).

Credits

STEMpedia
42 projects • 170 followers
STEMpedia blends theory with experiential learning by offering state-of-the-art technology, projects, tutorials, courses, and much more.
Contact

Comments

Please log in or sign up to comment.