How to get ds3231 to keep time when not plugged into arduino uno

hello,

I have the following code:

/*  
  
  */  
 #include <Wire.h>  
 #include "RTClib.h"  
 RTC_DS1307 RTC;  
   
 void setup()  
 {  
  Serial.begin(9600);  
    
  Wire.begin();  
  RTC.begin();  
  RTC.adjust(DateTime("JAN 19 2014","16:45:45")); 
 }  
 void loop()  
 {  
  DateTime now = RTC.now();// Getting the current Time and storing it into a DateTime object  
   
  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);  
 }

I would like to be able to set the start time (like I have done in my code) but then want the ds3231 to keep the time when it is removed and then plugged back in. So whenever I plug it back in it will display the correct time and not carry on from what the time was last or start again from the start time. is this possible? and please post code that i can copy and paste into my code rather than tell me what to write because I’m not very good with code and probably won’t understand!

any help would be much appreciated!!!

(deleted)

yes it has a cell battery

Well as far as I can see from the datasheet, it should switch to the battery of its own accord, no coding necessary.

I would like to be able to set the start time (like I have done in my code) but then want the ds3231 to keep the time when it is removed and then plugged back in. So whenever I plug it back in it will display the correct time and not carry on from what the time was last or start again from the start time.is this possible?

Of course it is. Do you have some code that does not set the time, but does read it? Why not?

You can use that code, as a matter of fact. Simply comment out the call to set the time. See what happens.

Hello, Thanks Paul, I have trailed what you suggested but the time resets to the 1/1/2000 0:0:00. Also I do have code that can read the time but I have the same problem.

Thanks John, I simply mean removing all wires from the ds3231 (yes it's a fully assembled rtc), and then putting them all back in.

I have trailed what you suggested but the time resets to the 1/1/2000 0:0:00.

Then, either the mysterious code has a problem, or the battery on the clock is dead.

Also I do have code that can read the time but I have the same problem.

If the clock isn't started, you would. We haven't seen any proof that you've set the time and started the clock.

Ok thanks paul, i will try a new battery. Also how do you set the time and start it?

Also how do you set the time and start it?

Eh? Isn't that what you are already doing?

RTC.adjust(DateTime("JAN 19 2014","16:45:45"));

Rob

I think it is because you included:

RTC.adjust(DateTime("JAN 19 2014","16:45:45"));

when will read the current time ...

  1. Upload the program to include code (RTC adjust).
  2. unplug RTC module.
  3. Upload program without code (RTC adjust) or you can command that code.
  4. plug rtc module.
  5. reset arduino

sorry for my bad english . =( =(

Ok great thanks i will try

Hi, I have tried that but it gives me the complete wrong date and time!

I have done some tests and found that the ds3231 doesn't keep time when the ground is unplugged, but if you unplug and then re-plug in all the other pins the ds3231 keeps the time and displays the correct time. any help?

(deleted)

hello, i can get a picture but might be a while but here is what i have done.

arduino uno 5v -------------------------- vcc ds3231 GND -------------------------- GND SDA -------------------------- SDA SCL -------------------------- SCL

(deleted)

http://www.ebay.co.uk/itm/DS3231-AT24C32-IIC-Module-Precision-RTC-Module-Memory-Module-/370988717355?hash=item5660a6952b

This is exactly like mine. I am using the right angle headers and havnt soldered any headers onto the opposite side of the right angle headers.

when the ground is unplugged

Unplugged from what? Is it still connected between the battery and the RTC?


Rob

When I take the wire out connecting the GND pin on Arduino to the GND pin on the ds3231. Second line on my diagram thing :).

And the battery remains connected with two wires? You aren't also disconnecting that as well are you?


Rob