PROJECT Nº 4: Multicolored lamp

Learn to build and program a lamp that lights up in different colors using the components of the Maker Control Kit and Maker Kit 2.

The potentiometer will let you select the color that you want the RGB LED to shine.

DIFFICULTY LEVEL: Beginner.

DURATION OF THE EXERCISE: 45 min.

MATERIALS:

  • 1 RGB LED
  • 1 Potentiometer
  • 1 Clear or white plastic cup
  • 1 4in1 Build&Code board
  • 1 USB – Micro USB cable
  • Computer
  • Material to make the lamp structure
  • Adhesive

What is an RGB LED?

An RGB LED is an LED that can shine any color of light based on the combination of its three basic colors: red, green, blue.

BUILDING THE STRUCTURE:

To build the lamp structure, you will use 150 mm x 18 mm wooden sticks and a clear or white plastic cup. Download the quick assembly guide and follow the steps shown.

The structure that you will get is as follows:

 

Once the structure is assembled, connect all the electronic elements to the 4in1 Build&Code board as shown in the section on connections found below.

CONNECTIONS:

  1. Connect the potentiometer to analog port A0 on the 4in1 Build&Code board.
  2. Connect the RGB LED to digital port 6 on the 4in1 Build&Code board.

Look at the colors of the cables and the colors of the terminals on the 4in1 Build&Code board to guide you. Each cable should be connected to its color.

 

PROGRAMMING CODE:

The program consists of making the RGB LED change colors between 7 different colors with the movement of the potentiometer. When the value of the potentiometer is 0, the RGB LED will be off.

You can do this activity by using Arduino and Bitbloq software, as well as other compatible block programming software. Below you will find the programming code needed for each software.

Arduino Code

  1. Download the Arduino software and go through the installation process.
  2. Add the library for the RGB LED to the Arduino software, following the instructions in the guide “How to add a library to program your RGB LED.
  3. Open the Arduino program, and once in, copy the following program:
    /*
                    R   G   B
    White    1023  255 255 255
    Red      876   255 0   0
    Orange   730   255 128 0 
    Yellow  584   255 255 0
    Green     437   0   255 0
    Blue      291   0   0   255
    Purple   145   128 0   128
    Black     0     0   0   0
     */
    
    #include <Adafruit_NeoPixel.h>  //LIBRARY RGB LED
    #define PIXEL_PIN 6    //PIN OF THE RGB LED
    #define PIXEL_COUNT 1    // NUMBER OF RGB LEDS
    Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800); // CONFIGURATION OF THE RGB LED
    int PortPot = A0, ValuePot = 0; // Potentiometer connected to analog port A0 // ValuePot is the variable of the potentiometer reading
    void setup() {
      // Put your setup code here, to run once:
      Serial.begin(9600);
      //CONFIGURATION OF THE RGB LED
      strip.begin();
      strip.show(); 
    }
    
    void loop() {
      // Put your main code here, to run repeatedly:
      ValuePot = analogRead (PortPot); // Potentiometer reading
      switch (ValuePot){ // Check the potentiometer value, if it coincides with the number activate a color.
        case 0: // BLACK
        colorWipe(strip.Color(0,0,0),0);
        break;
        case 145: // PURPLE
        colorWipe(strip.Color(128,0,128),0);
        break;
        case 291: // BLUE
        colorWipe(strip.Color(0,0,255),0);
        break;
        case 437: // GREEN
        colorWipe(strip.Color(0,255,0),0);
        break;
        case 584: // YELLOW
        colorWipe(strip.Color(255,255,0),0);
        break;
        case 730: // ORANGE
        colorWipe(strip.Color(255,128,0),0);
        break;
        case 876: // RED
        colorWipe(strip.Color(255,0,0),0);
        break;
        case 1023: // WHITE
        colorWipe(strip.Color(255,255,255),0);
        break;
      } 
    }
    
    // FUNCTION FOR THE COLOR OF THE RGB LED
    void colorWipe(uint32_t c, uint8_t wait) {
      for(uint16_t i=0; i<strip.numPixels(); i++) {
        strip.setPixelColor(i, c);
        strip.show();
        delay(wait);
      }
    }
    
  4. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

Code for compatible block programming software

  1. Download the software and go through the installation process.
  2. Add the extension to program the RGB LED following the instructions in the guide “How to add a library to program your RGB LED.
  3. Open the program, and once in, copy the following code:
  4. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

BitBloq Code

  1. Get the BitBloq software.
  2. Open the BitBloq program, and once in, copy the following code:
    • Hardware
    • Software
  3. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

RESULT OF THE EXERCISE:

Using the potentiometer, you can select one of the seven colors of light that the RGB LED can shine. You have made your own multicolored lamp!

1 0

0