Turning Light using RTC Widget

I am trying to make a project using BLYNK but ran into a problem with the RTC widget. My question is how can I use the RTC widget to turn some light on at a specific time?

You ca use widget Timer for that - http://docs.blynk.cc/#widgets-controllers-timer

No need to code.

Yes I know but If I want the light intensity to change over time I can`t use the Timer Widget.

Did you see RTC sketch? It is pretty simple.

if (hour() == 10) {
// do something.
}

Am I doing some thing wrong?

> #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 4
> #define blue_pin 8
> #define green_pin 7

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

> 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 setup()
> {
>   Serial.begin(9600); // See the connection status in Serial Monitor
>   Blynk.begin(auth, "Clayton xxxxxxxxxci", "clxxxxxcn13");

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


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

>   delay(5000);
>   digitalWrite(red_pin, HIGH);
>   delay(1000);
>   digitalWrite(red_pin, LOW);


>   // Begin synchronizing time
>   rtc.begin();

>   // Display digital clock every 10 seconds
>   timer.setInterval(10000L, clockDisplay);

> }


> void turnon()
> {
>   if (hour() == 23, minute() == 00) {
>     digitalWrite(red_pin, HIGH);
>     Serial.println("High");
>     // digitalWrite(blue_pin, HIGH);
>     // digitalWrite(green_pin, HIGH);
>   }
> }


> void loop()
> {
>   Blynk.run();
>   timer.run();
>   turnon();
> }

Yeah the code has errors but I’m on my phone so can’t help too much except saying I think you need to call the ‘turnon’ function somewhere outside the loop… And what are the delays doing in the set up?

@claytoncamilleri100

Code snippets should be formatted. Edit your post.

Wrap the code by adding 3 Backtick: ``` symbols:

Example:

 ``` cpp <--put 3 backticks BEFORE your code starts  (cpp means C++ language) 
⏎
   //Put your code here
   //..................
   //..................
⏎
 ``` <--insert 3 backticks AFTER your code

**This makes your code readable and with highlighted syntax, like this:**
//comment goes here 
void helloWorld() { 
   String message =  "hello" + "world"; 
}

Ok I will try and post my success here and the delays are for blinking an led on start up.

I fixed the problem by adding another line.
timer.setInterval(10L, turnon);
But now the esp reboots to infinity after connecting to the wifi and displays ready in the serial monitor.
Is this a bug in Blynk or with my code? and maybe because I have a rough 3.3v from the power supply.

#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 4
#define blue_pin 8
#define green_pin 7
int st1 = 31;
int st2 = 62;
int st3 = 93;
int st4 = 124;
int st5 = 155;
int st6 = 186;
int st7 = 217;
int st8 = 255;



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

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 turnon()
{

  if (hour() == 7, minute() >= 00)
  {
    analogWrite(red_pin, st1);
    analogWrite(blue_pin, st1);
    analogWrite(green_pin, st1);
  }

  else

    if (hour() == 7, minute() >= 15)
    {
      analogWrite(red_pin, st2);
      analogWrite(blue_pin, st2);
      analogWrite(green_pin, st2);
    }

    else

      if (hour() == 7, minute() >= 30)
      {
        analogWrite(red_pin, st3);
        analogWrite(blue_pin, st3);
        analogWrite(green_pin, st3);
      }
      else

        if (hour() == 7, minute() >= 45)
        {
          analogWrite(red_pin, st4);
          analogWrite(blue_pin, st4);
          analogWrite(green_pin, st4);
        }
        else

          if (hour() == 8, minute() >= 00)
          {
            analogWrite(red_pin, st5);
            analogWrite(blue_pin, st5);
            analogWrite(green_pin, st5);
          }
          else

            if (hour() == 8, minute() >= 15)
            {
              analogWrite(red_pin, st6);
              analogWrite(blue_pin, st6);
              analogWrite(green_pin, st6);
            }

            else

              if (hour() == 8, minute() >= 30)
              {
                analogWrite(red_pin, st7);
                analogWrite(blue_pin, st7);
                analogWrite(green_pin, st7);
              }
              else

                if (hour() == 8, minute() >= 45)
                {
                  analogWrite(red_pin, st8);
                  analogWrite(blue_pin, st8);
                  analogWrite(green_pin, st8);
                }

}




void turnoff()
{

  if (hour() == 20, minute() >= 15)
  {
    analogWrite(red_pin, st8);
    analogWrite(blue_pin, st8);
    analogWrite(green_pin, st8);
  }

  else

    if (hour() == 20, minute() >= 30)
    {
      analogWrite(red_pin, st7);
      analogWrite(blue_pin, st7);
      analogWrite(green_pin, st7);
    }

    else

      if (hour() == 20, minute() >= 35)
      {
        analogWrite(red_pin, st6);
        analogWrite(blue_pin, st6);
        analogWrite(green_pin, st6);
      }
      else

        if (hour() == 21, minute() >= 00)
        {
          analogWrite(red_pin, st5);
          analogWrite(blue_pin, st5);
          analogWrite(green_pin, st5);
        }
        else

          if (hour() == 21, minute() >= 15)
          {
            analogWrite(red_pin, st4);
            analogWrite(blue_pin, st4);
            analogWrite(green_pin, st4);
          }
          else

            if (hour() == 21, minute() >= 20)
            {
              analogWrite(red_pin, st3);
              analogWrite(blue_pin, st3);
              analogWrite(green_pin, st3);
            }

            else

              if (hour() == 21, minute() >= 44)
              {
                analogWrite(red_pin, st2);
                analogWrite(blue_pin, st2);
                analogWrite(green_pin, st2);
              }
              else

                if (hour() == 22, minute() >= 00)
                {
                  analogWrite(red_pin, st1);
                  analogWrite(blue_pin, st1);
                  analogWrite(green_pin, st1);
                }

}




void setup()
{
  Serial.begin(9600); // See the cstnectist status in Serial Mstitor
  Blynk.begin(auth, "xxxxxxxxxxxxxFi", "clxxxxxxxx3");

  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(1000L, clockDisplay);
  timer.setInterval(10L, turnon);
  timer.setInterval(10L, turnoff);

}








void loop()
{
  Blynk.run();
  timer.run();
  turnon();
  turnoff();
}

@claytoncamilleri100 is your system that mission critical to 10 milliseconds?

You wouldn’t normally have the functions with a timer AND in the main loop. Suggest you lose the main loop function calls and increase the 10L to 10000L (10 seconds).

You mean this part? I changed the time to 10 sec but still rebooting


  timer.setInterval(10000L, clockDisplay);
  timer.setInterval(10000L, turnon);
  timer.setInterval(10000L, turnoff);

And loop as:

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

The clock display which just shows a log entry in Serial Monitor would be ok as you had it (1000L).

Thats odd I commented these lines and it stopped rebooting and started telling me the time.

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

How can I configure the Notification widgetq to send me a low temp alert and high and including the actual temp in the notification?

void lm35()

{
val = analogRead(temp);
float mv = ( val/1024.0)*5000; 
float cel = mv/10;

if (cel <= 27)
  Blynk.notify("Temp LOW" + cel);
  else
   
   if ( cel >= 29)
     Blynk.notify("Temperature High" + cel);

I wrote the code but the leds keep turning on and I dont know why? Could it be because I have the timers before void setup and the pinmodes? Could any one suggest an edit? @pavel

#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 button V1

#define red_pin 13
#define blue_pin 14
#define green_pin 12
//int temp = A0;
//int val;
int st1 = 127;
int st2 = 255;
int st3 = 382;
int st4 = 509;
int st5 = 636;
int st6 = 763;
int st7 = 890;
int st8 = 1024;



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

SimpleTimer timer;

WidgetRTC rtc;

BLYNK_ATTACH_WIDGET(rtc, V5);


/*
void lm35()

{
  val = analogRead(temp);
  float mv = ( val / 1024.0) * 5000;
  float cel = mv / 10;

  if (cel <= 27)
    Blynk.notify("Temp LOW" );

  else

    if ( cel >= 29)
      Blynk.notify("Temperature High" );
}


if (Button, HIGH)
 Blynk
 */
// 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 turnon()
{

  if (hour() == 7, minute() >= 00)
  {
    
    analogWrite(red_pin, st2);
    analogWrite(blue_pin, st2);
    analogWrite(green_pin, st2);
  }

  else

    if (hour() == 7, minute() >= 30)
    {
      analogWrite(red_pin, st3);
      analogWrite(blue_pin, st3);
      analogWrite(green_pin, st3);
    }
    else

      if (hour() == 7, minute() >= 45)
      {
        analogWrite(red_pin, st4);
        analogWrite(blue_pin, st4);
        analogWrite(green_pin, st4);
      }
      else

        if (hour() == 8, minute() >= 00)
        {
          analogWrite(red_pin, st5);
          analogWrite(blue_pin, st5);
          analogWrite(green_pin, st5);
        }
        else

          if (hour() == 8, minute() >= 15)
          {
            analogWrite(red_pin, st6);
            analogWrite(blue_pin, st6);
            analogWrite(green_pin, st6);
          }

          else

            if (hour() == 8, minute() >= 30)
            {
              analogWrite(red_pin, st7);
              analogWrite(blue_pin, st7);
              analogWrite(green_pin, st7);
            }
            else

              if (hour() == 8, minute() >= 45)
              {
                analogWrite(red_pin, st8);
                analogWrite(blue_pin, st8);
                analogWrite(green_pin, st8);
              }

}




void turnoff()
{

  if (hour() == 20, minute() >= 15)
  {
    analogWrite(red_pin, st8);
    analogWrite(blue_pin, st8);
    analogWrite(green_pin, st8);
  }

  else

    if (hour() == 20, minute() >= 30)
    {
      analogWrite(red_pin, st7);
      analogWrite(blue_pin, st7);
      analogWrite(green_pin, st7);
    }

    else

      if (hour() == 20, minute() >= 35)
      {
        analogWrite(red_pin, st6);
        analogWrite(blue_pin, st6);
        analogWrite(green_pin, st6);
      }
      else

        if (hour() == 21, minute() >= 00)
        {
          analogWrite(red_pin, st5);
          analogWrite(blue_pin, st5);
          analogWrite(green_pin, st5);
        }
        else

          if (hour() == 21, minute() >= 15)
          {
            analogWrite(red_pin, st4);
            analogWrite(blue_pin, st4);
            analogWrite(green_pin, st4);
          }
          else

            if (hour() == 21, minute() >= 20)
            {
              analogWrite(red_pin, st3);
              analogWrite(blue_pin, st3);
              analogWrite(green_pin, st3);
            }

            else

              if (hour() == 21, minute() >= 44)
              {
                analogWrite(red_pin, st2);
                analogWrite(blue_pin, st2);
                analogWrite(green_pin, st2);
              }
              else

                if (hour() == 22, minute() >= 00)
                {
                  analogWrite(red_pin, st1);
                  analogWrite(blue_pin, st1);
                  analogWrite(green_pin, st1);
                }

}




void setup()
{
  Serial.begin(9600); // See the cstnectist status in Serial Mstitor
  Blynk.begin(auth, "Cxxxxxxxxxri Wi-Fi", "cxxxxxxxxxxxxx3");

  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(1000L, clockDisplay);
  timer.setInterval(10000L, turnon);
  timer.setInterval(10000L, turnoff);
  timer.setInterval(1000L, clockDisplay);

}








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

Have you tried changing

if (hour() == 20, minute() >= 15)

to

if (hour() == 20 && minute() >= 15)

I use a physical RTC with Blynk, but the syntax is the same.