ATtiny85 - Sometimes works, sometimes doesn't

I have the following LED strip nightlight. When I tested it on my breadboard it appeared to work. Now having soldered it all together it sometimes works and sometimes does not. By not working I mean that the lights seem to either get stuck in a certain pattern or randomly come one. I can power down and up again and it stays the same.... then all of a sudden when I switch on it starts working properly.

Right now, while posting this question, only four of the five LEDs lights up with number four staying bright green and number three blue. The other first two appear to be going through the programmed sequence.

I have disconnected from the power and left it for 1min but the Lights to not change as programmed. I did manage to get it working on three different occasions by simply switching off, waiting and switching on again.

Besides a faulty board I am wondering if I have made some mistakes in the electronics resulting in some of the pins being unstable on boot-up.

One button is for powering on and the other for pausing the sequence change by disconnecting the data line to the LED strip.

NightLight.ino (3.6 KB)

Ok so I left it for over an hour and it is now working. But when I switch it off and on again the problems start again, necessitating and long power down.

Try tying the reset pin (physical pin 1, PB5) high with a 10K resistor?

How are you powering your project?

Can I suggest on your next PCB you run power tracks directly to the LED socket and not via the ATtiny pads.

Tom... :slight_smile:

You forgot to add one or more 100 nF decoupling caps as required. They are essential for reliable operation.

Solder one directly across the ATtiny power and ground, on the foil side of the board. While you are at it, check for poor solder connections. Let us know if that fixes the problem.

The 100nF capacitor appeared to make things better. I no longer need to wait ages between power ups but I need to wait about 15 seconds i.e. if I wait 15 seconds, when switching on random lights are one but then the sequence starts running. Should I change the cap size? Also should I add the 10K resistor as mentioned above to PB5 (I am guessing I would connect from PB5 to GND). Alas I am working with a SMD (ATTiny) so don't want to attempt to do this if it might not add anything.

The code, posted properly, using code tags. The 3 second delay at program start doesn’t do anything useful.

#include <FastLED.h>


// FastLED "100-lines-of-code" demo reel, showing just a few 
// of the kinds of animation patterns you can quickly and easily 
// compose using FastLED.  
// This example also shows one easy way to define multiple 
// animations patterns and have them automatically rotate.
// -Mark Kriegsman, December 2014

#if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
#warning "Requires FastLED 3.1 or later; check github for latest code."

#define DATA_PIN    1
//#define CLK_PIN   4
#define LED_TYPE    WS2811
#define NUM_LEDS    5

#define BRIGHTNESS          96
#define FRAMES_PER_SECOND  120

void setup() {
  delay(3000); // 3 second delay for recovery
  // tell FastLED about the LED strip configuration
  FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  //FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);

  // set master brightness control

// List of patterns to cycle through.  Each is defined as a separate function below.
typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm };

uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
void loop()
  // Call the current pattern function once, updating the 'leds' array

  // send the 'leds' array out to the actual LED strip;  
  // insert a delay to keep the framerate modest

  // do some periodic updates
  EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
  EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically

#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))

void nextPattern()
  // add one to the current pattern number, and wrap around at the end
  gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);

void rainbow() 
  // FastLED's built-in rainbow generator
  fill_rainbow( leds, NUM_LEDS, gHue, 7);

void rainbowWithGlitter() 
  // built-in FastLED rainbow, plus some random sparkly glitter

void addGlitter( fract8 chanceOfGlitter) 
  if( random8() < chanceOfGlitter) {
    leds[ random16(NUM_LEDS) ] += CRGB::White;

void confetti() 
  // random colored speckles that blink in and fade smoothly
  fadeToBlackBy( leds, NUM_LEDS, 10);
  int pos = random16(NUM_LEDS);
  leds[pos] += CHSV( gHue + random8(64), 200, 255);

void sinelon()
  // a colored dot sweeping back and forth, with fading trails
  fadeToBlackBy( leds, NUM_LEDS, 20);
  int pos = beatsin16( 13, 0, NUM_LEDS-1 );
  leds[pos] += CHSV( gHue, 255, 192);

void bpm()
  // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
  uint8_t BeatsPerMinute = 62;
  CRGBPalette16 palette = PartyColors_p;
  uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));

void juggle() {
  // eight colored dots, weaving in and out of sync with each other
  fadeToBlackBy( leds, NUM_LEDS, 20);
  byte dothue = 0;
  for( int i = 0; i < 8; i++) {
    leds[beatsin16( i+7, 0, NUM_LEDS-1 )] |= CHSV(dothue, 200, 255);
    dothue += 32;

Ok, but that still does not account for the fact that when I switch off, if I don't leave it off for about 10 seconds, the LED sequence does not start. Could it be that I need to leave time for the capacitors to discharge properly before powering up again?

Could it be that I need to leave time for the capacitors to discharge properly

Yes. You may not need the big cap at all, or more than about 10 uF.

It depends on whether switching the LEDs introduces significant noise into the power supply.

Many thanks, you helped me get it sorted. Add the extra CAP and reduced the existing one. Works like a dream :slight_smile:

Glad to see you got it performing properly.

What is your power supply?

Thanks.. Tom.. :slight_smile: