Time input blynk digital pin


#define BLYNK_PRINT SwSerial


#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX
    
#include <BlynkSimpleStream.h>

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


BLYNK_WRITE(V1) {
  long startTimeInSecs = param[0].asLong();
  SwSerial.println(startTimeInSecs);
  SwSerial.println();  
  
  

}

void setup()
{
  // Debug console
  SwSerial.begin(9600);

  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  Serial.begin(9600);
  Blynk.begin(Serial, auth);

}

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

here is my code from “blynk example”. connection is via usb. I want to use blynk time input to light led. led is on D4. i need the code for it

You didn’t format your posted code as instructed…

Blynk - FTFC

Or search this forum as recommended…

Here you are. How can i put digital pin in code to light led with time inpit widget?

Now click on that link above and read up on how the Time Input Widget works… you will also want to switch to Virtual Pins for that Widget and control the GPIO via code that responds to the Widgets received data.

A somewhat simpler Time controlled option would be the basic Timer Widget…

http://docs.blynk.cc/#widgets-controllers-timer


#define BLYNK_PRINT DebugSerial
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#include <BlynkSimpleStream.h>
#define BLYNK_PRINT Serial
#include <WidgetRTC.h>
BlynkTimer timer;
char auth[] = "xxxxxxxxxxxxxxxxxx";
char currentTime[9];
char startTime[9];
char stopTime[9];
int SThour;
int STmin;
int STsec;
int SPhour;
int SPmin;
int SPsec;

WidgetRTC rtc;  // Set RTC widget.

void setup()
{
  pinMode(4, OUTPUT);  // Built-in LED
  digitalWrite(4, HIGH); // Turn OFF built-in LED
  Serial.begin(9600);  // Debug console
  Blynk.begin(Serial, auth);
  rtc.begin();
  setSyncInterval(360);
  timer.setInterval(30000L, TimeCheck);  // Update Time Check every 30 seconds
}



BLYNK_CONNECTED() {
  Blynk.syncVirtual(V1); //  Synchronize Time Input Widget when connected
  TimeCheck(); // Initial Time Check
}


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



BLYNK_WRITE(V1) {  // Called whenever setting Time Input Widget
  TimeInputParam t(param);
  SThour = t.getStartHour();
  STmin = t.getStartMinute();
  STsec = t.getStartSecond();
  SPhour = t.getStopHour();
  SPmin = t.getStopMinute();
  SPsec = t.getStopSecond();
}



void TimeCheck() {  // call with timer every 30 seconds or so
  // Get RTC time
  sprintf(currentTime, "%02d:%02d:%02d", hour(), minute(), second());
  Serial.print("Current Time: ");
  Serial.println(currentTime);

  // Get Time Input Widget time
  sprintf(startTime, "%02d:%02d:%02d", SThour, STmin, STsec);
  Serial.print("Start Time: ");
  Serial.println(startTime);

  sprintf(startTime, "%02d:%02d:%02d", SPhour, SPmin, SPsec);
  Serial.print("Stop Time: ");
  Serial.println(startTime);

  if (hour() == SThour) {
    if (minute() == STmin) {
      Serial.println("Doing something now");
      digitalWrite(4, LOW); // Turn ON built-in LED
    } else if (minute() < STmin) {
      Serial.println("Will do something");
    } else if (minute() > STmin) {
      Serial.println("Did something");
    } else {
      Serial.println("Clueless");
    }
  }

  if (hour() == SPhour) {
    if (minute() == SPmin) {
      Serial.println("Stopping something now");
      digitalWrite(4, HIGH); // Turn OFF built-in LED
    } else if (minute() < SPmin) {
      Serial.println("Will stop something");
    } else if (minute() > SPmin) {
      Serial.println("Stopped something");
    } else {
      Serial.println("Clueless");
    }
  }
  Serial.println("----------");
}

still not working. is there any mistake?







void TimeCheck() {  // call with timer every 30 seconds or so

Blynk.syncVirtual(V1); // <------  Synchronize Time Input Widget every 30 seconds
 
 // Get RTC time
sprintf(currentTime, "%02d:%02d:%02d", hour(), minute(), second());
  Serial.print("Current Time: ");
  Serial.println(currentTime);

erase this part?

no, add sync

void TimeCheck() {  // call with timer every 30 seconds or so
Blynk.syncVirtual(V1); // <------  Synchronize Time Input Widget every 30 seconds

code consists of it-

BLYNK_CONNECTED() {
  Blynk.syncVirtual(V1); //  Synchronize Time Input Widget when connected
  TimeCheck(); // Initial Time Check
}

only at first connect !
you have to sync each 30 sec

BLYNK_CONNECTED() {
  Blynk.syncVirtual(V1); //  Synchronize Time Input Widget when connected
  TimeCheck(); // Initial Time Check
}

still doesn’t work

let me see your code and your serial monitor

#define BLYNK_PRINT DebugSerial
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#include <BlynkSimpleStream.h>
#define BLYNK_PRINT Serial
#include <WidgetRTC.h>
BlynkTimer timer;
char auth[] = "xxxxxxxxxxxxxxxxxx";
char currentTime[9];
char startTime[9];
char stopTime[9];
int SThour;
int STmin;
int STsec;
int SPhour;
int SPmin;
int SPsec;

WidgetRTC rtc;  // Set RTC widget.

void setup()
{
  pinMode(4, OUTPUT);  // Built-in LED
  digitalWrite(4, HIGH); // Turn OFF built-in LED
  Serial.begin(9600);  // Debug console
  Blynk.begin(Serial, auth);
  rtc.begin();
  setSyncInterval(360);
  timer.setInterval(30000L, TimeCheck);  // Update Time Check every 30 seconds
}



BLYNK_CONNECTED() {
  Blynk.syncVirtual(V1); //  Synchronize Time Input Widget when connected
  TimeCheck(); // Initial Time Check
}


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



BLYNK_WRITE(V1) {  // Called whenever setting Time Input Widget
  TimeInputParam t(param);
  SThour = t.getStartHour();
  STmin = t.getStartMinute();
  STsec = t.getStartSecond();
  SPhour = t.getStopHour();
  SPmin = t.getStopMinute();
  SPsec = t.getStopSecond();
}



void TimeCheck() {  // call with timer every 30 seconds or so
  // Get RTC time
  Blynk.syncVirtual(V1);
  sprintf(currentTime, "%02d:%02d:%02d", hour(), minute(), second());
  Serial.print("Current Time: ");
  Serial.println(currentTime);

  // Get Time Input Widget time
  sprintf(startTime, "%02d:%02d:%02d", SThour, STmin, STsec);
  Serial.print("Start Time: ");
  Serial.println(startTime);

  sprintf(startTime, "%02d:%02d:%02d", SPhour, SPmin, SPsec);
  Serial.print("Stop Time: ");
  Serial.println(startTime);

  if (hour() == SThour) {
    if (minute() == STmin) {
      Serial.println("Doing something now");
      digitalWrite(4, LOW); // Turn ON built-in LED
    } else if (minute() < STmin) {
      Serial.println("Will do something");
    } else if (minute() > STmin) {
      Serial.println("Did something");
    } else {
      Serial.println("Clueless");
    }
  }

  if (hour() == SPhour) {
    if (minute() == SPmin) {
      Serial.println("Stopping something now");
      digitalWrite(4, HIGH); // Turn OFF built-in LED
    } else if (minute() < SPmin) {
      Serial.println("Will stop something");
    } else if (minute() > SPmin) {
      Serial.println("Stopped something");
    } else {
      Serial.println("Clueless");
    }
  }
  Serial.println("----------");
}

ok but what do you see on serial monitor ?

I can’t use serial monitor because com3 port is busy because of blynk(i’m using usb connction)

I’m using the same com port to upload code and to see serial monitor.
it’s quiet normal, else you can’t see nothing
but you have to open serial monitor after upload completed


without opening blynk-ser.bat

nothing runs!
is there any issue when you upload the sketch?

@Blynk_Coeur The OP is using the primary USP port for the actual Serial to networking connection to Blynk… it is in use full time.

@Giorgi_Turdziladze You can add in a software serial connection and using another TTL-USB adapter and a terminal program like termite to have a 2nd serial channel for debugging.

I got ît.
I just understood that it’s not an Ethernet connection.
:smile:

1 Like