tinyGlow Smart LEDs

Bring the ATtiny85 and NeoPixels together in affordable, addressable lights!

  • 1,780 views
  • 3 comments
  • 11 respects

Components and supplies

Attiny85
Microchip ATTiny85
×1
Adafruit NeoPixel strip
×1
5V USB power bank
Your standard portable phone charger.
×1
12002 04
Breadboard (generic)
×1
08377 02 l
Resistor 330 ohm
×1
11026 02
Jumper wires (generic)
×1
A000066 iso both
Arduino UNO & Genuino UNO
Used for programming the ATtiny – not in the final project
×1

Apps and online services

About this project

This is a fun, creative, and inexpensive project/workshop, depending on how many pixels you want to use.

NeoPixels are addressable RGB LEDs that run off 5 volts and have 3 wires: +5V, ground, and data—which is controlled via one PWM pin. These versatile lights come in rolls of LED strip, sticks, matrices, and rings of various sizes. It seems Adafruit has largely replaced them with 4-wire DotStar strips, but you can still get these on Amazon. I recommend buying one 4m roll of NeoPixels (with 60 pixels per meter) and giving each person a strip of 10. When cutting the strip, cut down the middle of the copper solder pads.

The ATtiny85 is a wonderful piece of hardware: an 8-pin chip that can be programmed as an Arduino with a couple of usable GPIO pins. These little guys are perfect friends for NeoPixels: small enough that they barely jut out beyond the LED strip, able to run off the same 5V source, and cheap enough to throw everywhere. (Low-power versions are also available.)

And the entire circuit can be powered from a single 5V phone charger or rechargeable USB power bank! (Watch your amps, though – if the charger gets hot or stops working, unplug and find something that can deliver more current.)

0. Setup

First, plug in your Arduino (an Uno or 101 will do just fine) and upload the ArduinoISP sketch (File > Examples > ArduinoISP > ArduinoISP). This allows the Arduino to act as a programmer for the ATtiny.

1. Hardware

Now, set up your Arduino/ATtiny programming circuit, following this tutorial: Arjun's ATtiny + Arduino tutorial. Set up another circuit with your NeoPixels plugged in, like so:

*** I bought off-brand WS2812 LED strips on Amazon, largely because Adafruit is apparently shipping DotStars instead, and I wanted lights that only need one data pin. The unofficial ones work fine, but they have the pins in a different order; check your labels! ***

I recommend building both circuits with the wires as far to the outside of the board as possible. This makes it easier to remove and replace the ATtiny chip.

When working with the strips, make sure that the arrows on the strip point AWAY from your headers, since the lights are unidirectional and won't work if hooked up from the wrong end.

You can also solder a more permanent programmer using a protoboard with an 8-pin chip socket on it.

2. Software

Download the Adafruit Neopixel library and drop the top directory into your Arduino libraries folder. Restart the IDE if you need to.

Now, open up an example to make sure your circuit is good: File > Examples > Adafruit NeoPixel > strandtest

With the ATTiny85 plugged into the board with the Arduino, select these settings:

  • Board: "ATtiny"
  • Processor: "ATtiny85"
  • Clock: "8 MHz (Internal)"
  • Port: [Arduino's USB port]
  • Programmer: "Arduino as ISP"

Note the clock setting! This is necessary to make the ATtiny run fast enough to control your LEDs. Select the 8MHz internal clock, then click "Burn Bootloader" at the bottom of the Tools menu.

Once you've uploaded the code, transfer the ATtiny to your breadboard with the NeoPixel strip set up. Add power and watch it go!!

Check out some more examples, then try programming your own animations. There are a bunch of them in the Once you've got a good setup, you can program a whole rail of these things in no time.

Finishing the circuit

Follow Adafruit's Best Practices guide to make sure your NeoPixels (and their controller) stay happy and healthy. For example, once you solder everything up, you'll want to add a resistor (300 to 500 ohms) between the ATtiny's pin 5 and the data-in pin on the NeoPixels. You'll also want a 1000uF capacitor across the power and ground pins. These should keep your pixels happy and healthy.

Try designing and 3D-printing a little enclosure for the controller circuit!

Try it with a DigiSpark – an ATtiny built into a board with a USB interface! Still small, still cheap, and a little more convenient. (Especially if you want to make changes after mounting the lights to something – just use a USB extension cable.)

Are you gonna rock these indoors or outside? They often come in a silicone sleeve, which will keep out the water and dust. Seal up the ends with hot glue, which will also insulate your connections. You can use zip-ties or more hot glue to attach them to stuff. Plus, some strips have holes through the solder pads – you can even pass thread through unused pads and sew them in place.

Workshop

Host a hack night and help your friends bling up their bikes, ties, scarves, and more! Here are some tips on making it go smoothly.

Take a night beforehand to cut up the NeoPixels and solder headers on. This makes things way faster (especially since you don't have to teach people to solder), and prevents errors like soldering the headers to the wrong end. Of course, teaching people to solder is a noble pursuit, but it can make the workshops unpleasantly long for everyone. More advance prep = more time to experiment with colors!

If you want to share your own circuit design, you can find the NeoPixel strips in this Fritzing library for circuit diagrams: https://github.com/adafruit/Fritzing-Library

Rolls typically come in 4-meter lengths: 240 pixels total if you get the 60-per-meter kind. 12 pixels is a good amount to start having fun with animations, but of course, you can also cover your bike in them! Hell yeah!!

Like this project? Check out the NeoPixel animated eyeball for some spooky, matrix-controlled cleverness!

Code

NeoPixel test codeC/C++
File > Examples > Adafruit NeoPixel > strandtest -- Modify the "PIN" setting from 6 to 0.
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN 0

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

void setup() {
/*
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  #if defined (__AVR_ATtiny85__)
    if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  #endif
  // End of trinket special code
*/

  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  // Some example procedures showing how to display to the pixels:
  colorWipe(strip.Color(255, 0, 0), 50); // Red
  colorWipe(strip.Color(0, 255, 0), 50); // Green
  colorWipe(strip.Color(0, 0, 255), 50); // Blue
  // Send a theater pixel chase in...
  theaterChase(strip.Color(127, 127, 127), 50); // White
  theaterChase(strip.Color(127, 0, 0), 50); // Red
  theaterChase(strip.Color(0, 0, 127), 50); // Blue

  rainbow(20);
  rainbowCycle(20);
  theaterChaseRainbow(50);
}

// 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);
    strip.show();
    delay(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(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(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
    for (int q=0; q < 3; q++) {
      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, c);    //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}

//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
    for (int q=0; q < 3; q++) {
      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}

// 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);
}
Adafruit NeoPixel "simple" example codeC/C++
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

// Which pin on the Arduino is connected to the NeoPixels?
// On a DigiSpark, this should probably be 1.
#define PIN            1

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS      16

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int delayval = 500; // delay for half a second

void setup() {
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  // End of trinket special code

  pixels.begin(); // This initializes the NeoPixel library.
}

void loop() {

  // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.

  for(int i=0;i<NUMPIXELS;i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(0,150,0)); // Moderately bright green color.

    pixels.show(); // This sends the updated pixel color to the hardware.

    delay(delayval); // Delay for a period of time (in milliseconds).

  }
}

Comments

Similar projects you might like

Magic Lamp

by Nekhil ravi

  • 1,222 views
  • 3 comments
  • 12 respects

PuzzleBox

Project tutorial by Arduino

  • 516 views
  • 0 comments
  • 4 respects

Arduino MKR GSM 1400 and DTMF

by Arduino_Genuino

  • 4,337 views
  • 0 comments
  • 12 respects

Love You Pillow

Project tutorial by Arduino

  • 3,043 views
  • 0 comments
  • 5 respects

Arduino Yun Controller

Project showcase by TATCO Inc

  • 299 views
  • 0 comments
  • 5 respects
Add projectSign up / Login