Date and Time sync with bluetooth?

Hello everyone !

Reading one among many other older topics I found this discussion here : http://forum.arduino.cc/index.php?topic=182114.0

I using Arduino (MEGA 2560) to read data files from a SD CARD in order to control solenoids in specific Date, time and duration… all of this information will be stored in the SD Card.

My intention is to compare the real Time with scheduled time activities in the SD, however with this code I’m not having accuracy, time won’t be updated to latest. It starts from the time it was compiled for the first time and it goes on every time we reset it.

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;
void setup(){
  
  Serial.begin(9600);
  Wire.begin();
  rtc.begin();

  if(!rtc.isrunning()){
    Serial.println("O RTC não está sendo executado");
  }

rtc.adjust(DateTime(2016,11,3,10,50,0));
}

void  loop(){  
    DateTime now = rtc.now();
    
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();

    delay(1000);
  }

Since I need accuracy, i thought about syncronizing time using bluetooth… I have a tablet which sends all the info to the SD card using a bluetooth (HC-06), so instead of syncronizing time with the PC i would sync it with this tablet, is this possible? Suggestions?

rtc.adjust(DateTime(2016,11,3,10,50,0));

Why do you always diddle with the clock time?

Why not use a proper clock programme that you don't have to adjust?
If your problem is one of ensuring super accuracy, which is not evident, you might be better off with a DS3231.

PaulS:

rtc.adjust(DateTime(2016,11,3,10,50,0));

Why do you always diddle with the clock time?

Thx for your interest, indeed that's why it selects the date and time the code was compiled, I havent removed this part of the code just for you all understand how it is working at this very moment. The idea is to reformulate the code, instead of adjusting the clock to a certain and fixed dante and time, is to sync it to the real and latest time.

Nick_Pyner:
Why not use a proper clock programme that you don't have to adjust?
If your problem is one of ensuring super accuracy, which is not evident, you might be better off with a DS3231.

Unfortunetly this should be done with the DS1307, I can't switch any of the components i'm using right now. So are you suggesting to make a new code so the RTC DS1307 can update its date and time by it self?

So are you suggesting to make a new code so the RTC DS1307 can update its date and time by its own?

I don't understand what you are asking. The DS1307 should keep time on its own. Why do you need to update the time and date that it thinks it is?

Sorry sir, I've typed it wrong (rusty english). Post edited. I just need the DS1307 to have its time as my time zone instead of last compiled time. By doing this I'll be able to compare with scheduled SD card time as told above. Right ? Thanks in advance

I'm saying use proper code so that the DS1307 maintains time in the usual manner

Set it to your time in your timezone and, as the other guy says, no diddling. I only suggested the DS3231 as it is more accurate and it uses the same code. I don't think accuracy is really your problem, and the DS1307 is fine. All you need to do is learn to use it properly.

This link solved the problem, nothing better than a simple solution for simple problem, as I never used this kind of shield I was wondering a much more complicated solution. Really much thanks

Ah yes. One of the joys of Arduino is finding that something you thought was complicated turns out to be quite simple.