Introduction: USB Chameleon Lamp ( Color Replicating )

Another awesome way to use Your Own Color Sensor is a "Color Sensing and Replicating Lamp" or simply a Chameleon lamp. The chameleon lamp is a super-easy-to-build project which can be used as a night light or just as a decorative piece.

This lamp features :

1. A Custom Color Sensor <-- click here to make your own

2. Personalized diffusers ( this one uses a cube shaped diffuser )

3. Different operating modes ( color sensing - color cycling ( mood lamp ) - random combinations )

4. Responds to knock

4. USB compatible.

5. Fully programmable and customizable.

6. Auto-calibration and RGB individual intensity adjustment.

Step 1: < Supplies >

To make this you'll need :

1. An arduino Uno ( or any other variant )

2. A color sensor - (Make Your Own !)

3. A copper clad - single sided board

4. Supplies for PCB fabrication - ( laser printer , glossy paper, FeCl3, HackSaw ,etc.)

5. Cardboard to make the case or a 3D printed case

Components :

1. 6 x 10K potentiometers

2. 3 x BD139 NPN power transistors ( or equivalent )

3. a strip of Female headers, male headers and male right-angled headers

4. Some ribbon cables and relimate connectors ( 4pin , 3pin )

5. A high intensity RGB LED

6. A piezo disc

7. 4 x 1M resistors

8. CD4051 8 bit multiplexer

Hardware :

1. A piece of cardboard

2. A bottle of superglue

3. Paper sheet ( white / ivory )

4. Black insulating / electrical tape

5. Heat shrink tubing ( 12mm , 4mm , 8mm )

6. Black paint

7. Soldering iron and solder

Step 2: Make the "Heart"

The "Heart" of the Lamp is the Shield - ( TriSense Shield ) which is mounted on an Arduino Uno.

The shield is compatible with all the versions of Arduino boards. Start making the shield by printing the layout ( given below ). Print it on a glossy paper and make your board using the toner transfer method.

You'll find detailed instruction guide @ Here. This previous instructable covers all the hazards and safety warnings associated with PCB manufacturing.

After you've etched the board and drilled it, start soldering the headers and then the IC base.

Now you can start soldering the other components. Solder the BD139s at the end.

Description :

The Shield basically consists of :
1. A 7 pin connector to connect the 6 pin / 7 pin Color sensor.

2. An 8 - bit multiplexer , this helps us to reduce the number of PWM pins required by the Sensor. It does so by multiplexing only one PWM pin to drive the three RGB leds on three different values.

3. An on-board LED driver + Hue calibration circuit. It also supports external power input if the project requires a bunch of extra high power LED .

4. Extra headers to attach some extra inputs/ outputs if needed.

5. A ShiftLCD jack for upcoming enhanced versions of this Lamp.

These features enables us to modify and program it in endless ways.

Your shield is ready !

Step 3: Knock Input Sensor

The Lamp uses a "Piezoelectric" disc as a button. The lamp reacts when it is knocked. This uses the default "Knock sensor" code.

It works on the principle of piezoelectricity, when the piezo element is pressed or knocked, the compression of different layers of the piezo disc generates considerable amount of voltage. This voltage is sensed by the analog 2 pin on the arduino. Whenever we knock the sensor, if the voltage is above the set threshold , it tells the Lamp to react accordingly.The input is then pulled down by using 4M ohm resistor network.

Solder the negative terminal of the piezo element to the ground pin on the Shield. Then solder the other pin to analog A2. Now finally solder the 4M resistor network as shown.

The graph in processing shows the voltage spikes when the sensor is pressed or knocked.

You've successfully made the knock input.

Step 4: Make the Diffuser and the Case

Diffuser :

Cut a white sheet of white paper in according to the given layout.

Fold the flaps and glue them to create a cube. Cut one of the edge to make space for the RGB LED.

Add black electric tape on the edges ( it looks good ).

Case :

Take a piece of cardboard and cut it according to the given template (If you're not using a 3D printed case). The dimensions depends on the features that you want in it. This version uses a 10.5 cm X 10 cm X 5.5 cm cardboard casing.

Fold the shaded flaps and glue the box using superglue. Paint it black and add black electrical tape to smooth out any imperfections or shabby edges.

Step 5: RGB LED and Hue Fine-Adjustment Board

Board :

The RGB Hue fine adjustment board is the most important element of the Lamp. Though the lamp has been programmed to auto-calibrate the sensor, the R G B individual LEDs in a single LED draw different amount of current and at the same output voltage, each LED differs in the intensity.

To make this , follow the schematic and start by soldering 3 x 10K potentiometers on a perf-board.

Solder a 4 wire relimate connector to the board ( keep the polarity in mind ).


Solder a RGB LED on a perf-board and solder 4 pin header to it.

Cut a strip of paper and fold it to form a triangular prism so that it fits in the hole of the diffuser.

Paste the structure on the LED so that it fits snugly in the diffuser.

Step 6: The Sensor

You'll find a guide to make your own sensor Here!

After you've made the sensor, Place a 4-6 mm heat shrink tube piece over the LDR.

Now add a 12 mm heat shrink tube over the whole sensor as shown.

Secure the connections either by hot glue or by superglue and slide a piece of Heat shrink tube over the cable.

The heat shrink tube needs to be black. Any other color of heat shrink tube would give false readings.

Your sensor is ready !

Step 7: Fix the Components

After you've created the case, fix the Arduino to the base using screws.

Place the shield over it and attach :

1. Color Sensor

2. RGB control Board

Now cut a small piece in the base to accommodate the shaded sensor.

Superglue the RGB control board to the edge of the case.

Finally cut a hole in the lid to fix the LED.

Step 8: Final Touches

To complete the body , glue the diffuser on the LED. Place the Knock sensor on the exterior of the case and secure it with black electrical tape.

Add tags and decorate as you like.

Look for any imperfections and shabby edges and fix them using some electrical tape.

Step 9: The TriSense Library

The TriSense RGB library is a custom made library created by me to make it easy to program the Lamp.

Instructions to install the library

1. Download the TriSense.rar archive

2. Extract the TriSense folder in C:\Program Files (x86)\Arduino\libraries\TriSense

3. Restart the IDE and check whether the library works ( using the CycleRGB example )

Functions :

The library mainly consists of these operations :

1. TS_RGB < class name > ( int red pin, int green pin, int blue pin);

2. CalibSeq ( mode ) : this function calibrates the sensor, it sets the white balance and needs to be invoked only once.

in the "mode" space , if you want serial monitor for debugging ,

write : CalibSeq("Debug");

else : CalibSeq("XDebug"); it won't initialize the Serial monitor.

3. GetColor( int delay ) : this function reads the color of any object which is placed under the sensor.

the optimum value of delay is 50 ms. Reducing the delay would give false readings and increasing the delay would slow the response.

4. CycleRGB( int delay , float brightness , float saturation ) :

this function cycles RGB colors sequentially ( mood lamp effect )

increasing the delay would slow down the animation.

the value of brightness and saturation varies from 0 to 1.

5. SetHue ( int red , int green , int blue )

this function is used to directly control the RGB led by providing it with values for each color ranging from 0 to 255.

Step 10: Programming

The full program is quite large and it took me several days to create the library and get it to work.

/* This Code is written by <a href="" rel="nofollow">
   The project can be found on the same page


TS_RGB ts(11,10,9);

int S_Tap, dTap_stat, sTap_stat , val, first, second, last_doubletap, last_tap;

int restate = 0, tap, doubletap;

long idle, returnst, time;

int dly=100, prevkno=0, knocks, last_knock, knock_stat, state,mode, MaxModes=4, calib_st;

void setup()
  Serial.begin(9600);  //  ONLY FOR DEBUGGING


  for(int i = 0 ; i <5 ; i ++)
void loop()
 //////////////////////////////////////  READING KNOCK SENSOR //// 
  knock_stat=knock(100);      //  VARIABLE WHICH STORES NUMBER OF KNOCKS  : knock(threshold value)
                               //  THE THRESHOLD MAY VARY DEPENDING ON YOUR SENSOR  
  if(knock_stat!=last_knock && state==0)  //   GET STATE CHANGE IN KNOCK
    idle=millis();                          //  RESET COUNTER  AND AVOID DELAY
    state =1;
    if(millis()-idle<1000 && knock_stat!=last_knock && dTap_stat==0)  //  READ DOUBLE TAPS WITHIN 1SEC.
    if(millis()-idle>1000 && sTap_stat==0 && dTap_stat!=1)
  ///////////////////////  DOUBLE TAP to CHANGE MODE ////////////////////////////
  sleep();                    //  SLEEP MODE , SLOW BLUE PWM 
  if(doubletap==1)             //  RGB COLOR CYCLING
    dly=dly-10;                  // TAP TO SPEED UP THE ANIMATION 
   ts.WriteColor("ColorCancelling");  // The Color cancelling mode cancels the color with least %
  Serial.print("        ");

int PwM(int dly, int start, int finish)   //   PWM without using Delay
    val = start;
  if(start < finish && val < finish )
    if(millis()-idle > dly)

  if(start > finish && val > finish)
    if(millis()-idle > dly)
    return 1;
    return 0;
  int knock(int thr)                       // Knock function
    int kno = map(analogRead(2),0,thr,0,1);
    kno = constrain(kno,0,1);
    if(prevkno!=kno && millis()-time>50)
      prevkno = kno;
      time = millis();
    return knocks/2;
  void sleep()          // Sleep function
  first = PwM(1,10,150);
  if(first == 1)
  if(second == 1)

The fact that I haven't used delay() function in this program makes it so lengthy. If we use delay() function, the program stops for that particular time period this means that all the inputs , outputs and other calculations would stop working. This would create a big problem while using knock input.

I got the CycleRGB without delay program from :

Step 11: Understanding the Program

The program first initializes White Balance calibration sequence for the color sensor. After the sensor is calibrated, it puts the lamp in sleep mode ( marked by slow Blue PWM fading ).

The lamp continues to take readings from the knock sensor.

As the user taps the sensor twice within a second , the program counts it as a double tap. It changes the mode to ColorCycling mode. If the user taps it again ( once ) , the animation speeds up.

If the program senses another double tap , it changes the mode to color sensing mode.

Step 12: Operation and Troubleshooting

Download and print the given color wheel to test and calibrate the Lamp.

Operation :

1. Before powering-up the lamp, place a perfect white - non glossy surface under the sensor.

2. Now turn it on , The lamp should now start the calibration sequence.

3. As the lamp calibrates the sensor, the Lamp would glow bright red.

4. Once it has been successfully calibrated, it will flash green and then get into sleep mode.

5. Knock it twice to activate the RGB cycling code.

6. Go on tapping it till the animation speeds up.

7. Or just double tap it to run the color sensing code.

8. In the Color Sensing mode, the sensor will continuously take readings from the object and replicate the color.

9. Now just place it on any object and watch it adapt to the color.

10. Tap it once more to lock the color that you like !

Troubleshooting :

1. Check the connections thoroughly.

2. Damaged transistors or shorts may affect the brightness of the RGB led.

3. While calibrating , glossy surfaces may give false readings.

4. Piezo sensor should have a rigid support to increase it's sensitivity.

5. The sensor should be capped to avoid false readings due to ambient light.

Debugging :

1. To check the values of the sensors , you can change the mode to debugging mode.

2. This will allow you to monitor all the readings using serial monitor.

Step 13: Conclusion

The lamp is now ready to add Hue to the ambiance, it also demonstrates how simple and basic components could be connected to create something unique and fascinating.

Being open-source and programmable , the lamp offers infinite possible ways of customizations.

I'm planning to make a v2.0 Hue Lamp with an LCD and many other functions.

Thanks for reading ! Feel free to comment and ask if anything appears to be unclear.

And if you find this project interesting, please leave a vote :)


bevandito made it!(author)2017-06-15

dude i did every part of it but im stuck at uploading the program, can you help me?

pvelazquez+gomez made it!(author)2015-03-09

Thank you dude, I'll upload a pic when I finish it

pvelazquez+gomez made it!(author)2015-03-06

dude I want to make your proyect, but I can't print the brd, could you send me it (on PDF) by email, or tell how I can print it, which program do you use?

electro18 made it!(author)2015-03-06

To print the .brd files you'll require Eagle PCB designing software or any other freeware that supports .brd files.

Open the board layout and remove all the layers except the bottom layer. Print the layout in 1:1 scale on a glossy paper directly from the software.

The problem with .pdf files if that, sometimes they tend to be out of scale and you'd ruin all the spacing and the hole widths.

pvelazquez+gomez made it!(author)2015-03-08

thanks, an other question :(, how did you conect the hue fine-adjustment board?

electro18 made it!(author)2015-03-09

The fine adjustment board is nothing but a board consisting of three 10K potentiometers connected in series with the R G B leds individually. The board has four pins, three for R G and B and the fourth one for ground.
One side of the board connects to the RGB led and other side is connected to the amplified output of the transistors. Hope this helps or else I can make a fritzing circuit for better picture of the actual thing :)

Mr+AbAk made it!(author)2014-12-30

Nice Instructable!!

electro18 made it!(author)2014-12-31

Thanks ! :)

please support by leaving a vote !

Mr+AbAk made it!(author)2014-12-30

Nice Instructable!!

StevenC2 made it!(author)2014-11-23

I love this lamp and I'm thinking of making it for a friend as a Christmas gift, problem is I have no experience with this kind of stuff. You think that even a novice could make this or should I start with something smaller and simpler?

electro18 made it!(author)2014-11-23

Yes ! Anyone with basic circuit / soldering skills can make it ! If you encounter any problem while making it or get stuck with something , feel free to ask me anytime and as many times as you want to. I'll be sure to reply it quickly. Good luck ! :)

Also , please support by leaving a vote :)

Ayush+Sharma made it!(author)2014-11-17

Amazing Lamp!

electro18 made it!(author)2014-11-18

Thanks ! :)

wjsaunders made it!(author)2014-11-05

Is there a particular reason why you wired the 4 M ohm resistors and three wires to the piezo the way you did? Does it provide better results than just two wires and a 1 M ohm resistor?

electro18 made it!(author)2014-11-05

The 4 M ohm resistors are used to pull-down the analog Input. The more value of resistors you use, the more sensitive your sensor gets. The Third pin is just a part of the second plate ( which is used when you're using the piezo in " self-drive " mode). Before placing the sensor , I tested it with all possible combinations and I got best results with this configuration.
The results and values of resistors may depend on the type of piezo that you're using.

wjsaunders made it!(author)2014-11-08

Interesting. Thank you for a reply

monster_mash made it!(author)2014-11-06

Good job how did you make it?

electro18 made it!(author)2014-11-07

All the detailed instructions are mentioned in the instructable. If any step seems unclear , feel free to ask ! :)

monster_mash made it!(author)2014-11-06

Good job how did you make it?

nerd7473 made it!(author)2014-11-05


electro18 made it!(author)2014-11-05

Thanks ! :)

seamster made it!(author)2014-10-30

Nicely done. Thanks for sharing this!

electro18 made it!(author)2014-10-30

Thanks ! :)

About This Instructable




Bio: Hey there ! I'm Tanay , a hobbyist interested in making robots and sharing stuff. I hope that my instructables help you in solving your problems ... More »
More by electro18:USB Chameleon Lamp ( Color replicating )Your Own Color Sensor using LEDsMeasure RPM - Optical Tachometer
Add instructable to: