BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Using another time source?

Hi. I had a problem a little while ago whereby some motors on my project kept tripping up my DS1307RTC unit and halting everything. I was advised to install some flyback diodes across the motors which i thought had worked but in my final phase of testing the project just now, the fault seems to be back, albeit not as much.

My questions is… is there any other way of holding time in Arduino other than an RTC? I spent weeks before trying to resolve the above issue and cannot spend more so thought it would be easier to just remove the RTC and try a different way.

Things I need time to do…

  1. Display time in hours, minutes and seconds on a monitor device.
  2. Allow functions to trigger such as turn motors on and off (all driven via a relay bank)

Ps. I am using Blynk to control/monitor all of the functions.

Thanks, Steve.

@stevelondon have you considered Blynk’s RTC widget?

No I do not know much about it. Will it do what I mentioned above?

Yes.

Great I’ll look into it thank you. Will come back if I get stuck.

I use the DS1307 library with my RTC, and Blynk to update it every now and again. So if your clock deviates, Blynk will reprogram it many times.

#include <WidgetRTC.h>

#include <RTClib.h>                 // RealTimeClock Library for DS1307 and DS3231
#define BLYNK_PRINT Serial

RTC_DS1307 RTC;
float UTCOffset = -5.0;    // Your timezone relative to UTC (http://en.wikipedia.org/wiki/UTC_offset)

WidgetLCD lcdA(V7);  //Set LCD widget to Advanced Mode - Widget to display project clock
WidgetTerminal terminal(V8);
WidgetRTC rtcWidget;  // requires RTC widget in app
BlynkTimer timer;       // SimpleTimer instance named timer

void displayDateTime()
{
  Serial.println("displayDateTime");
  DateTime now = RTC.now();          // reads time at beginning of loop
  byte HOUR = now.hour();
  byte twelveHour = now.hour() - 12; // Variable used to display 13+ hours in 12 hour format
  byte zeroHour = 12;                // Variable use to convert "0" zero hour to display it as 12:00+
  byte displayHour;
  byte MIN = now.minute();
  byte SEC = now.second();
  char* meridian;

  if (now.hour() == 0)  // First we test if the hour reads "0"
  {
    displayHour = zeroHour;
    meridian = "AM";
  }
  else if (now.hour() >= 13)  // if no, Second we test if the hour reads "13 or more"
  {
    displayHour = twelveHour;
    meridian = "PM";
  }
  else
  {
    displayHour = now.hour();
    meridian = "AM";
  }
  if (Blynk.connected())
  {
    char stamp[16];
    lcdA.clear();
    sprintf(stamp, "%02d:%02d:%02d-%02s", displayHour, MIN, SEC, meridian);
    lcdA.print(3, 0, stamp);
    sprintf(stamp, "%02d/%02d/%04d", now.month(), now.day(), now.year());
    lcdA.print(3, 1, stamp);
  }
}
// synchronize the RTC hardware device with our server provided date/time values
void syncRTCHardware()
{
  if (!Blynk.connected())
  {
    Serial.println("Blynk not connected. Exiting syncRTCHardware.");
    return;
  }
  Serial.println("syncRTCHardware");
  DateTime now = RTC.now();          // reads time at beginning of loop

  char currentTime[16];
  char currentDate[16];
  sprintf(currentDate, "%02d/%02d/%04d", month(), day(), year());
  sprintf(currentTime, "%02d:%02d:%02d", hour(), minute(), second());
  Serial.print("Server Time: ");
  Serial.print(currentDate);
  Serial.print (" ");
  Serial.println(currentTime);

  // time library is synchronized by the Blynk WidgetRTC
  if (Blynk.connected())
  {
    bool syncClocks;
    if (now.hour() != hour() && now.minute() != minute()) syncClocks = true;
    if (syncClocks == true)
    {
      syncClocks = false;
      Serial.println("Resynching RTC Time...");
      terminal.println("Resynching RTC Time...");
      RTC.adjust(DateTime(year(), month(), day(), hour(), minute(), second()));
      terminal.flush();
    }
  }
}

BLYNK_CONNECTED()
{
  Serial.println("BLYNK_CONNECTED");
  rtcWidget.begin();      // Synchronize with widget (server) time on connection
  setSyncInterval(5 * 60); // subsequent time sync interval in seconds (5 minutes)
}

void setup() {
 timer.setInterval(15000L, syncRTCHardware);  // synchronize the RTC device with the server time every 15 seconds
  timer.setInterval(5000L, displayDateTime);   // update the LCD Widget every 5 seconds
}

void loop()
  {
    // only attempt Blynk-related functions when connected to Blynk
    if (Blynk.connected())
    {
      Blynk.run();
    }
    timer.run();
  }

I’m pretty sure that’s all of it (RTC code). I may need to edit and add more/less.

Is this working. Because it is not working for me. I am using ESP-01 for WiFi connect. Apart from that evrything looks same.

Forum member @myggle hasn’t been seen since February 2019, so I doubt you’ll get a response to your question.
The code that was posted was incomplete, and won’t compile without some changes. As you’ve not shared information about how you’ve changed the code it will be difficult for anyone to assist you with this example.

You currently have another active topic about using an external RTC module with the Bl6nk RTC widget, but in that topic you aren’t providing the necessary information to allow us to assist you.
I’d suggest you focus on your active topic, simplify the code you are using, and provide full details about how you are connecting your external devices to your Uno. It would also be helpful if you gave more in-depth responses to questions, and be clearer about the information you post.

Pete.

The reason why I am using this concept is, I don’t have stable internet in my village.It may go down any time and it will be out for hours. So I wanted to use DS3231 as my timer. I wanted to sync with Blynk Server one in day to avoid time issue with my setup.

I ON my outside house light in the even after 6PM. I ran into issue when there was no internet and light didnt on as i was not able to sync with the Blynk Server.