Ever wish your clothes could change color to match each other? Make a chameleon scarf to match every outfit using the Flora color sensor and 12 color-changing LED pixels diffused by a ruffly knit scarf.

Prerequisite guides:
Portraits by Johngineer!
Bill of materials:

Sharp scissors are a must!
Clear nail polish or fray check to seal knots
To mark out your circuit use a water-soluble embroidery marker or tailor's chalk.
You'll use a needle and to stitch up the circuit.
A sewing machine helps make this project fun and easy.
On one end of your ribbon you'll connect pads marked 3V, SCL, SDA, and GND on FLORA to corresponding pads on the color sensor.

Then you'll chain on 12 NeoPixels at even intervals along the ribbon, connecting pads marked + to VBATT on FLORA, likewise the ground bus from FLORA's GND to every pixel pad marked -. Small segments of conductive thread connect each pixel's data pad to the next.
First, stitch power and ground rails along your ribbon by using a zigzag stitch. One strand of 3-ply thread works fine for this scarf's power delivery, which is about 4.5 feet long.

If your ribbon is longer or you're using more than 12 pixels, consider zigzagging around two strands of conductive thread together for less total resistance.

On one end, stop short of the ribbon's end and leave tails about 10 inches long for sewing to FLORA.
Thread one tail onto a needle and hand stitch it to VBATT by way of D12 on FLORA. The ribbon is not quite wide enough to reach to VBATT without forcing the other two connections to be impractically close together, so it's ok to short D12 to VBATT to help space things out better, since D12 is not used in this circuit.

Pick up the other tail and stitch around GND on FLORA.

Tie knots and seal with clear nail polish or fray check. As it dries, pull knots tight, then cut tails short when the adhesive is dry. For more tips, check out our Conductive Thread guide.
On the other side of the FLORA board, stitch connections between the SCL and SDA to the color sensor.

These thread connections are pretty close together. To help prevent the knots from knocking into each other, alternate which side of the ribbon you tie off. For example, tie knots for GND and SDA on the front side and SCL and 3.3V on the back side.

Seal all knots.
Another option is to solder the color sensor to the FLORA, as shown, using a piece of foam tape to affix the two together in a delicious circuit sandwich.
Stitch the first pixel close to the FLORA board, connecting pad D6 to the inward-facing arrow on the pixel. Tie off and seal the knot.

With another piece of conductive thread, stitch around the pad marked - on the pixel to secure it to the ribbon, then weave the needle under your zigzag stitch to put it in more contact with the conductive thread ground line. The more thread in contact with this line, the better the power delivery will be to the pixels.

Use a marking pen to measure where each other pixel will go-- ours are 4.5 inches apart.
Using the same zigzag technique as earlier, affix data lines to the ribbon. At each mark, cut a long tail, then pick up again on the other side of the mark. This way you can pick up and hand stitch the tails without having to stitch long distances between pixels.
Ribbon ready for pixels along side ruffle scarf, which you'll make in the next step.
Closeup of pixel sewn with lots of contact on + and - sides.
In version 2, we used narrow conductive ribbon for the data bus, and sewed the pixels on the opposite side of the ribbon from the power/ground rails.
First run the NeoPixel test sketch to make sure all your pixels are connected and receiving good signal. Reinforce connections with more conductive thread as needed.

Follow instructions on the color sensor guide for installing the code library. Run the test code with your serial monitor to be sure your color sensor is hooked up properly and working.

For this project, copy and paste this code into the Adafruit Arduino IDE:
#include <Wire.h>
#include "Adafruit_TCS34725.h"
#include <Adafruit_NeoPixel.h>

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_RGB     Pixels are wired for RGB bitstream
//   NEO_GRB     Pixels are wired for GRB bitstream
//   NEO_KHZ400  400 KHz bitstream (e.g. FLORA pixels)
//   NEO_KHZ800  800 KHz bitstream (e.g. High Density LED strip)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, 6, NEO_GRB + NEO_KHZ800);

// our RGB -> eye-recognized gamma color
byte gammatable[256];

Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);

void setup() {
  Serial.println("Color View Test!");
  strip.show(); // Initialize all pixels to 'off'
  if (tcs.begin()) {
    Serial.println("Found sensor");
  } else {
    Serial.println("No TCS34725 found ... check your connections");
    while (1); // halt!
  // thanks PhilB for this gamma table!
  // it helps convert RGB colors to what humans see
  for (int i=0; i<256; i++) {
    float x = i;
    x /= 255;
    x = pow(x, 2.5);
    x *= 255;
    gammatable[i] = x;      
  for (int i=0; i<3; i++){ //this sequence flashes the first pixel three times as a countdown to the color reading.
    strip.setPixelColor (0, strip.Color(188, 188, 188)); //white, but dimmer-- 255 for all three values makes it blinding!
    strip.setPixelColor (0, strip.Color(0, 0, 0));
  uint16_t clear, red, green, blue;

  tcs.setInterrupt(false);      // turn on LED

  delay(60);  // takes 50ms to read 
  tcs.getRawData(&red, &green, &blue, &clear);

  tcs.setInterrupt(true);  // turn off LED
  Serial.print("C:\t"); Serial.print(clear);
  Serial.print("\tR:\t"); Serial.print(red);
  Serial.print("\tG:\t"); Serial.print(green);
  Serial.print("\tB:\t"); Serial.print(blue);

  // Figure out some basic hex code for visualization
  uint32_t sum = red;
  sum += green;
  sum += blue;
  //sum += clear; // clear contains RGB already so no need to re-add it
  float r, g, b;
  r = red; r /= sum;
  g = green; g /= sum;
  b = blue; b /= sum;
  r *= 256; g *= 256; b *= 256;
  Serial.print((int)r, HEX); Serial.print((int)g, HEX); Serial.print((int)b, HEX);

  Serial.print((int)r ); Serial.print(" "); Serial.print((int)g);Serial.print(" ");  Serial.println((int)b );
  colorWipe(strip.Color(gammatable[(int)r], gammatable[(int)g], gammatable[(int)b]), 0);

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);

void loop() {
  //loop is empty because it only takes the color reading once on power up! Turn the scarf off and on again to change the color.
The first pixel in the chain will flash three times as a countdown to the color sensor reading. Place an object over the sensor during this time, then the LEDs will all light up in the color that was sensed.

To update the color, press the reset button on FLORA (while connected via USB or battery) or turn the board off and back on (only available while on battery power).
Create a super long (~12 feet) strip of lightweight knit fabric. The easiest way is to recycle an old sweater by cutting it into strips with a rotary cutter, as seen in the second picture from Brookelynn Morris' CRAFT ruffle scarf tutorial. Her guide was an inspiration for our scarf, go check it out! You can also head to the fabric store and look for a very sheer knit.

If you have one handy, a knitting machine makes fast work of this long strip. We used up a bunch of yarn we had that's too thin for pretty much anything but gauzy ruffled scarves.

Fold the long strip in half, right sides together, and pin. Use an iron if your fabric is very curly.

It was helpful to us while ironing to roll the pinned part of the (very long) strip around a cardboard tube.
Pull both the needle and bobbin threads from your sewing machine to exceed the length of your knit strip-- mine needed to be about 15 feet long.

Use a zigzag stitch to capture these threads as you sew the seam on the scarf-- these threads are now a drawstring on which you can bunch up the fabric to create ruffles.
Evenly distribute the ruffles on your drawstring threads and match the overall length to the ribbon circuit-- this one is about 4.5 feet long, bunched up from about 12 feet of knit fabric.
Tack your ribbon circuit to the ruffled seam on the scarf every so often using plain thread and a needle. You may wish to hem the ends of your scarf at this time: fold over the rough edges of both the knitting and the ribbon and stitch them in place.
Version 2 uses 3D printed flexible diffusers to even out the light inside the scarf. Download the 3D file from Thingiverse and print in NinjaFlex flexible filament, then sew the diffusers over your NeoPixels.
Test out your circuit once more!
We used a tiny lithium polymer battery for this project-- CAUTION these batteries have additional safety concerns that you should read about and observe on the product page. If in doubt, use a battery pack that takes AAAs!

Turn the entire scarf right side out by sticking your arm through the knit tube, gathering up the tube on your arm, then grasping the end while pulling the tube back off of your arm.
Version 2 is a circle scarf, giving us the opportunity to connect the power and ground rails at each end, which will more evenly distribute power to the pixels.
Your finished chameleon scarf!
Hey! Don't dunk your scarf in water while it's on! If you need to wash it, remove the battery and hand wash in the sink. Allow to air dry thoroughly before reconnecting the battery!
In version two, overlapping ends of the circle scarf hide the FLORA when you're wearing the scarf, and allow for easy access to the color sensor and battery.
Match your scarf to your outfit! We had a lot of fun playing with the scarf to match shoes, clothes, handbags, fruit, etc.!
Hey! Don't dunk your scarf in water while it's on! If you need to wash it, remove the battery and hand wash in the sink. Allow to air dry thoroughly before reconnecting the battery!
Portraits by Johngineer!

This guide was first published on May 22, 2013. It was last updated on May 22, 2013.