Skip to content
Project: Chameleon Lamp

Code Upload

Your chameleon is about to come alive. One upload and the lamp starts watching, adapting, and glowing — and it never stops.

Warning

You have 7 wires in play — 4 for the colour sensor and 3 for the RGB LED. More connections means more places for a loose wire. Double-check every pin, especially the LED R/G/B order (D7, D8, D3). Swapped pins won't break anything, but your lamp will show the wrong colour. Head back to the Wiring module if you need a refresher.

Upload the Code

Click the button below to open Kriya Station with the Chameleon Lamp code pre-loaded. Follow the instructions in the Station to compile and upload to your NodeMCU.

Open in Kriya Station

What to Expect

Unlike the Colour Picker, there's no button to press. The Chameleon Lamp runs in a continuous loop — the moment the upload finishes, the lamp springs to life:

  1. The LED flashes through red → green → blue quickly (that's the self-test from the setup phase).
  2. The lamp starts reading the surface beneath the sensor and adjusts the LED to match.
  3. Open the Serial Monitor to see a rolling stream of data — current RGB reading, target colour, and transition progress.

LED Not Changing?

If the LED stays white or a single colour, the most common cause is swapped R/G/B LED pins. Check that D7 = Red, D8 = Green, D3 = Blue. Swap two wires and see if the behaviour changes.

Tip

Place the sensor face-down on a brightly coloured surface for the clearest result. Dark or black surfaces reflect very little light, so the lamp may dim or stay off — that's the black level correction at work.

Try It Out

Now that your lamp is alive, put it through these experiments:

01

The Slow Slide

Place the lamp on a red surface, then slowly slide it onto a blue one. Watch the LED fade through purple — that's lerping (linear interpolation) in action, exactly like the concept you learned.

02

Pattern Test

Try a patterned surface like a striped shirt or a colourful book cover. What does the lamp do? It should average the colours it sees — the trimmed mean filtering at work.

03

Threshold Detective

Move between two very similar shades — like light blue and slightly lighter blue. The lamp might not react. That's the colour distance threshold preventing flickering. By design, not a bug!