Automatic RGB Light using RTC Widget

I have an aquarium with led strip light and every morning I need to turn the lights slowly and was getting sick of trying to remember to do so. So I came up with this idea. It consists of an esp8266 and three NPN transistors. Here is the dashboard (only the rtc widget is used ) The rtc widget is hooked up to V5.
I would like to thank @Gaff for helping me a lot in the code.


#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
#define red_pin 13
#define blue_pin 14
#define green_pin 12
#define SUNRISE 7*60 + 0
#define DAWN 8*60 + 0
#define DUSK 21*60 + 0
#define SUNSET 22*60 + 0


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icst).
char auth[] = "dc51e3dxxxxxxxxxxxxxxxxxxx6aedbcb";

SimpleTimer timer;

WidgetRTC rtc;

BLYNK_ATTACH_WIDGET(rtc, V5);



// Digital clock display of the time
void clockDisplay()
{

  // You can call hour(), minute(), ... at any time
  // Please see Time library examples for details
  BLYNK_LOG("Current time: %02d:%02d:%02d %02d %02d %d",
            hour(), minute(), second(),
            day(), month(), year());
}



void turn_on() {
    int value = 0;
    int msm = hour() * 60 + minute(); //minutes since midnight

    if ( msm < SUNRISE ) {
         value = 0;
    } else if(msm < DAWN) {
         value = map(msm, SUNRISE, DAWN, 0, 1024);
    } else if(msm < DUSK ) {
         value = 1024;
    } else if(msm < SUNSET ) {
        value = map(msm, DUSK, SUNSET, 1024, 0);
    } else { 
        value = 0;
    }
    BLYNK_LOG("Time: %d %d - setting lights to %d", hour(), minute(), value);
    analogWrite(red_pin, value);
    analogWrite(blue_pin, value);
    analogWrite(green_pin, value);
}
void setup()
{
  Serial.begin(9600); // See the cstnectist status in Serial Mstitor
  Blynk.begin(auth, "Clayxxxxxxxxxi", "xxxxxxxx3");

  while (Blynk.connect() == false) {
    // Wait until connected
  }


  pinMode(red_pin, OUTPUT);
  pinMode(blue_pin, OUTPUT);
  pinMode(green_pin, OUTPUT);


  // Begin synchronizing time
  rtc.begin();

  // Display digital clock every 1 sec

  timer.setInterval(10000L, turn_on);
  timer.setInterval(1000L, clockDisplay);

}

void loop()
{
  Blynk.run();
  timer.run();
}
1 Like

Fish dig mood lighting? Who knew! :smiley:

Haha no but they need white light at least 14 hours a day.

the 12v LED burnt my NPS