RTC DS3231 reseting time


i need here, i've project rtc ds3231. everytime set time, shut down power rtc reset time. looks isn't saving time set code.


code: [select]

#include <servo.h>
#include <ds3231.h>
ds3231  rtc(sda, scl);
servo servo;
#include <wire.h>
#include <liquidcrystal_i2c.h>
liquidcrystal_i2c lcd(0x3f,2,1,0,4,5,6,7,3, positive);
int estadobotao = 0;
int chave=3; //pino ser ligado na chave esquerda
//int chavecentral=4;  //pino ser ligado na chave central
//int chavedireita=5;  //pino ser ligado na chave direita

void setup()
{
  // setup serial connection
  serial.begin(9600);
  // initialize rtc object
  rtc.begin();
  lcd.begin (16,2);
  //rtc.setdow(monday);     // set day-of-week sunday
  //rtc.settime(17, 58, 19);     // set time 12:00:00 (24hr format)
  //rtc.setdate(28, 12, 2016);   // set date january 1st, 2014
 
  // pino de dados servo conectado ao pino 9 arduino
  servo.attach(9);   
  //define o pino como entrada
  pinmode(chave, input);     
  //aciona o resistor pull-up interno
  digitalwrite(chave, high); 
  //pinmode(chavecentral, input);
  //digitalwrite(chavecentral, high);
  //pinmode(chavedireita, input);
  //digitalwrite(chavedireita, high);
}

void loop()
{
 //le o valor da chave esquerda (on/off)
  estadobotao=digitalread(chave); 
  //caso chave seja pressionada, movimenta o servo
  lcd.setbacklight(high);
  lcd.setcursor(0,0);
  lcd.print(rtc.gettemp());
  lcd.print(" c");
  lcd.setcursor(0,1);
  lcd.print(rtc.gettimestr());   

  //blink   
  delay(3000);     
  lcd.display();   
 
  lcd.clear();
  lcd.setcursor(0,0);
  lcd.clear();

  lcd.print("data: ");
  lcd.print(rtc.getdatestr());
 
  //blink
  delay(3000);   
  lcd.clear();
 
  // fim lcd
 
 
  //inicio servo

  if(estadobotao == low)
    {
      delay(200);
      servo.write(180); delay(4000); //espera 4 segundos
      servo.write(0); delay(500);
   }   
   
  //fim servo
 
 
  //lcd.nodisplay();   
 
  //serial.print(rtc.getdowstr()); dia da senaba
 // serial.print(" "); 
 
}

does rtc have battery installed?  is battery still good?


Arduino Forum > Using Arduino > Programming Questions > RTC DS3231 reseting time


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor