DS3231(?) to turn Christmas lights on and off

I must be using the wrong search terms for I can't find quite what I'm looking for.
I have led strips running nicely. Rather than remembering to unplug the Nano each evening I thought it would be smart to put the nano to sleep(?) during the day, then wake it up at dark. I.e. run the sketch between say, 1600 and 2100.
Yes, I could use a mechanical timer plugged into the wall outlet. Yes, I could use a relay to turn power on/off to the nano.
I don't just want an alarm. I don't simply want to wake up the nano and run through the sketch once to get a reading.
In Arduino/DS3231 language what are the key terms I should be use in my internet search?
Happy holidays!

If you've read this far, I have another potential Christmas light project. I have three rooms, each with a nano, each nano running a different Fastled sketch. I would like to run the same sketch on each of the Nanos, but only if I can synch the three. I.e. all eight led strips are showing the same lights at the same time. The strips can't be wired to the same Nano. If I were to put a DS3231 on each, and set the time on each RTC from a computer, and set the same sleep/wake up times (see above), would that work? Or would there be time creep such that after a few hours the lights would get out of synch?

The DS3231 data sheet tells you what to expect for timing accuracy. It's roughly a few seconds per month.

Are you dead set on sleeping the Nano? It won't use much current if it's plugged into a power supply and the LEDs are all turned off. If you expect wake from sleep with the RTC, you're getting into a major programming challenge.

From experience here, (6 clocks based on the RTC modules) these RTCs run within 2 seconds of each other over 1year.

1 Like

Yeah, in my experience it will do that when the temperature is stable. It's slightly less if temperature changes force the temperature compensation circuit into play. But for tree lights, more than good enough... I guess the Xmas tree won't be up all year... :slight_smile:

Tell that to our neighbours. :grin:

It's so easy to just turn it off and wait for next year. I know. :slight_smile: The porch lights are less conspicuous...

An old friend keeps their nativity scene up all year long on their lawn; grass grows into baby Jesus’s manger.

I don't know what you mean. How do I keep it plugged in to power and turn off leds? Maybe that's what I use the RTC for? What is that function or feature called?

You did not tell us what LEDs you are using and how you control them,
but expect us to tell you, how to switch them off?

:unamused:

ESP8266 and NTP time.

WS2812B, Fastled library.

 strip.fill_solid(leds, numLeds, 0);
 strip.show();
1 Like

That's way above my pay grade, I think. And I can't spend more money on Arduino projects. We have mechanical wall timers laying about.

I'm a few steps ahead of that. I want to turn the sketch off during certain hours.

If you think so, go ahead. Good luck.

That is the default state for an Arduino that is doing something. So, you have to explain why you think leaving it plugged in would be a big problem...

Maybe you don't realize that the Arduino can be powered from a cell phone charger, instead of a computer? I don't know because I'm forced to try to read your mind.

If you mean that you already have written code, then please post it (in code tags).

#include <FastLED.h>

#define LED_PIN     2
#define NUM_LEDS    60

CRGB leds[NUM_LEDS];

void setup() {

  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);

}

void loop() {
    test1();
    //Strobe - Color (red, green, blue), number of flashes, flash speed, end pause
//      Strobe(0xff, 0xff, 0xff, random(5,20), random(10,100), 500);
//      Strobe(0xff, 0x00, 0x00, random(5,20), random(10,100), 500);
//      Strobe(0x00, 0xff, 0x00, random(5,20), random(10,100), 500);
      CylonBounce(0x00, 0xff, 0x00, random(3,10), random(5,20), random(5,200));
      CylonBounce(0xff, 0x00, 0x00, random(3,10), random(5,20), random(5,200));
     // NewKITT - Color (red, green, blue), eye size, speed delay, end pause
      NewKITT(0xff, 0x00, 0x00, random(5,10), random(5,10), 50);
      NewKITT(0x00, 0xff, 0x00, random(5,10), random(5,10), 50);        
      //Twinkle - Color (red, green, blue), count, speed delay, only one twinkle (true/false); 
        Twinkle(0xff, 0x00, 0x00, random(30,50), 100, true);
        Twinkle(0x00, 0xff, 0x00, random(30,50), 100, true);
      // TwinkleRandom - twinkle count, speed delay, only one (true/false)
           TwinkleRandom(60, 100, true);
      // Running Lights - Color (red, green, blue), wave dealy
          RunningLights(0xff,0x00,0x00, 20);  // red
          RunningLights(0xff,0xff,0xff, 30);  // white
          RunningLights(0x00,0xff,0x00, 40);  // green  
      // colorWipe - Color (red, green, blue), speed delay
           colorWipe(0xff,0x00,0x00, 20);
           colorWipe(0x00,0xff,0x00, 20);
      // meteorRain - Color (red, green, blue), meteor size, trail decay, random trail decay (true/false), speed delay 
            meteorRain(0xff,0xff,0xff,10, 64, true, 10);
            meteorRain(0x00,0xff,0x00,10, 64, true, 10);
            meteorRain(0xff,0x00,0x00,10, 64, true, 10);           
}

    
void test1(){
  for (int i = 0; i <= 59; i++) {
    leds[i] = CRGB ( 0, 255, 0);
    FastLED.show();
    delay(random(3,20));
  }
  for (int i = 59; i >= 0; i--) {
    leds[i] = CRGB ( 255, 0, 0);
    FastLED.show();
    delay(random(5,30));
  }
    for (int i = 0; i <= 59; i++) {
    leds[i] = CRGB ( 0, 0, 255);
    FastLED.show();
    delay(random(3,20));
  }
  for (int i = 59; i >= 0; i--) {
    leds[i] = CRGB ( 255, 255, 255);
    FastLED.show();
    delay(random(5,30));
  }
 }
void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause){
  for(int j = 0; j < StrobeCount; j++) {
    setAll(red,green,blue);
    FastLED.show();
    delay(FlashDelay);
    setAll(0,0,0);
    FastLED.show();
    delay(FlashDelay);
  }
 
 delay(EndPause);
}
void CylonBounce(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){

  for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue); 
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    FastLED.show();
    delay(SpeedDelay);
  }

  delay(ReturnDelay);

  for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue); 
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    FastLED.show();
    delay(SpeedDelay);
  }
  
  delay(ReturnDelay);
}

// Set all LEDs to a given color and apply it (visible)
void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue); 
  }
    FastLED.show();
}

// Set a LED color (not yet visible)
void setPixel(int Pixel, byte red, byte green, byte blue) {

   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;

}

void NewKITT(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){
  RightToLeft(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  LeftToRight(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  OutsideToCenter(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  CenterToOutside(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  LeftToRight(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  RightToLeft(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  OutsideToCenter(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  CenterToOutside(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
}

// used by NewKITT
void CenterToOutside(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i =((NUM_LEDS-EyeSize)/2); i>=0; i--) {
    setAll(0,0,0);
    
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue); 
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    
    setPixel(NUM_LEDS-i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(NUM_LEDS-i-j, red, green, blue); 
    }
    setPixel(NUM_LEDS-i-EyeSize-1, red/10, green/10, blue/10);
    
    FastLED.show();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

// used by NewKITT
void OutsideToCenter(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = 0; i<=((NUM_LEDS-EyeSize)/2); i++) {
    setAll(0,0,0);
    
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue); 
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    
    setPixel(NUM_LEDS-i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(NUM_LEDS-i-j, red, green, blue); 
    }
    setPixel(NUM_LEDS-i-EyeSize-1, red/10, green/10, blue/10);
    
    FastLED.show();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

// used by NewKITT
void LeftToRight(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue); 
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    FastLED.show();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

// used by NewKITT
void RightToLeft(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue); 
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    FastLED.show();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
} 

void Twinkle(byte red, byte green, byte blue, int Count, int SpeedDelay, boolean OnlyOne) {
  setAll(0,0,0);
  
  for (int i=0; i<Count; i++) {
     setPixel(random(NUM_LEDS),red,green,blue);
     FastLED.show();
     delay(SpeedDelay);
     if(OnlyOne) { 
       setAll(0,0,0); 
     }
   }
  
  delay(SpeedDelay);
}

void RunningLights(byte red, byte green, byte blue, int WaveDelay) {
  int Position=0;
  
  for(int i=0; i<NUM_LEDS*2; i++)
  {
      Position++; // = 0; //Position + Rate;
      for(int i=0; i<NUM_LEDS; i++) {
        // sine wave, 3 offset waves make a rainbow!
        //float level = sin(i+Position) * 127 + 128;
        //setPixel(i,level,0,0);
        //float level = sin(i+Position) * 127 + 128;
        setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
                   ((sin(i+Position) * 127 + 128)/255)*green,
                   ((sin(i+Position) * 127 + 128)/255)*blue);
      }
      
      FastLED.show();
      delay(WaveDelay);
  }
}

void colorWipe(byte red, byte green, byte blue, int SpeedDelay) {
  for(uint16_t i=0; i<NUM_LEDS; i++) {
      setPixel(i, red, green, blue);
      FastLED.show();
      delay(SpeedDelay);
  }
}

void TwinkleRandom(int Count, int SpeedDelay, boolean OnlyOne) {
  setAll(0,0,0);
  
  for (int i=0; i<Count; i++) {
     setPixel(random(NUM_LEDS),255,0,0);
     setPixel(random(NUM_LEDS),0,255,0);
     setPixel(random(NUM_LEDS),255,0,0);
     setPixel(random(NUM_LEDS),0,255,0);
     FastLED.show();
     delay(SpeedDelay);
     if(OnlyOne) { 
       setAll(0,0,0); 
     }
   }
  
  delay(SpeedDelay);
}

void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {  
  setAll(0,0,0);
  
  for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {
    
    
    // fade brightness all LEDs one step
    for(int j=0; j<NUM_LEDS; j++) {
      if( (!meteorRandomDecay) || (random(10)>5) ) {
        fadeToBlack(j, meteorTrailDecay );        
      }
    }
    
    // draw meteor
    for(int j = 0; j < meteorSize; j++) {
      if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
        setPixel(i-j, red, green, blue);
      } 
    }
   
    FastLED.show();
    delay(SpeedDelay);
  }
}

// used by meteorrain
void fadeToBlack(int ledNo, byte fadeValue) {
// #ifdef ADAFRUIT_NEOPIXEL_H 
//    // NeoPixel
//    uint32_t oldColor;
//    uint8_t r, g, b;
//    int value;
//    
//    oldColor = strip.getPixelColor(ledNo);
//    r = (oldColor & 0x00ff0000UL) >> 16;
//    g = (oldColor & 0x0000ff00UL) >> 8;
//    b = (oldColor & 0x000000ffUL);
//
//    r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
//    g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
//    b=(b<=10)? 0 : (int) b-(b*fadeValue/256);
//    
//    strip.setPixelColor(ledNo, r,g,b);
// #endif
// #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[ledNo].fadeToBlackBy( fadeValue );
// #endif  
}

I don't mind at all leaving it plugged in.

It is being powered by a 5V cell phone charger.

Is there a way to do this with a few ifs, elses, and millis?

Yes, it is. Study the example sketches and tutorials that come with millis() in the online documentation.