Battery Died, Test Needed

I have all my gear here which is a servo motor, arduino board, rtc DS1307 but the battery in the DS1307 had died. I won't be getting my new battery until somewhere between May 1-May 5, could someone hook up a servo motor to Analog pin 9, and a rtc to the SCL, SDA, VCC, and GND pin then upload the following program, wait about 20 seconds for the time to go and tell me if the servo motor did what was told of it?

//Arduino 1.0+ Only
//Arduino 1.0+ Only
#include <Servo.h>
#include "Wire.h"
#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workaround for issue #527

int hour =  hour;
int minute =  minute;
int second = second;

int pos = 0;
Servo myservo;



void setup(){
  Wire.begin();
  Serial.begin(9600);
  setDateTime(); //MUST CONFIGURE IN FUNCTION
  myservo.attach(9);
}

void loop(){
  printDate();
  if (hour == 20 && minute == 15 && second == 0)
{
  for (pos = 0; pos <= 180; pos += 1);
  }
  delay(1000);
}

void setDateTime(){

  byte second =     43; //0-59
  byte minute =      14; //0-59
  byte hour =        20; //0-23
//  byte weekDay =     2; //1-7
 // byte monthDay =    1; //1-31
 // byte month =       3; //1-12
//  byte year  =       11; //0-99

  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write(zero);

  Wire.write(decToBcd(second));
  Wire.write(decToBcd(minute));
  Wire.write(decToBcd(hour));
//  Wire.write(decToBcd(weekDay));
//  Wire.write(decToBcd(monthDay));
 // Wire.write(decToBcd(month));
 // Wire.write(decToBcd(year));

  Wire.write(zero); //start 

  Wire.endTransmission();

}

byte decToBcd(byte val){
// Convert normal decimal numbers to binary coded decimal
  return ( (val/10*16) + (val%10) );
}

byte bcdToDec(byte val)  {
// Convert binary coded decimal to normal decimal numbers
  return ( (val/16*10) + (val%16) );
}

void printDate(){

  // Reset the register pointer
  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write(zero);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_ADDRESS, 7);

  int second = bcdToDec(Wire.read());
  int minute = bcdToDec(Wire.read());
  int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
 // int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
//  int monthDay = bcdToDec(Wire.read());
//  int month = bcdToDec(Wire.read());
//  int year = bcdToDec(Wire.read());

  //print the date EG   3/1/11 23:59:59
 // Serial.print(month);
//  Serial.print("/");
//  Serial.print(monthDay);
//  Serial.print("/");
//  Serial.print(year);
//  Serial.print(" ");
  Serial.print(hour);
  Serial.print(":");
  Serial.print(minute);
  Serial.print(":");
  Serial.println(second);
 
}

Thank you so much
-Roie

Also for the ones who have seen me post on about my project, if this code is a success, I got it in the bag, thank you for the help!

No experience with the DS1307 but the only purpose of the battery is keep the time going when no power is supplied; the remaining functionality of the DS1307 should still be there when the normal power issupplied,

So if you keep on modifying the time and the 'target' time that an action needs to take place, you can keep on testing.

A little inconvenient but it should give you the idea if your code will work or not.

The code has been working perfectly and then it randomly stopped and printed out "625:125:125" I thought it was the if statement that I added but even if I remove it, same issue. Sterretje, I think the code also works on a DS3231.

roie_moyal:
The code has been working perfectly and then it randomly stopped and printed out "625:125:125" I thought it was the if statement that I added but even if I remove it, same issue. Sterretje, I think the code also works on a DS3231.

exactly nothing will happen here:

for (pos = 0; pos <= 180; pos += 1);

that semicolon assures you of that.

I find these declarations confusing.

int hour =  hour;
int minute =  minute;
int second = second;

Later you declare new 'byte' versions of hour, minute, and second. Maybe you don't need the globals.

I think the globals were used for the if statement. I could remove them and play with the code more

The only issue I am having is the If statement, nothing to do with the clock, I edited out what I added but I don't know what to do for the If statement. I know it's not anything to do with the Serial commands in the code or wire commands.

roie_moyal:
The only issue I am having is the If statement...

perhaps because it doesn't do anything?

void loop(){
  printDate();
  if (hour == 20 && minute == 15 && second == 0)

Do you mean a problem with THIS 'if' statement? Perhaps since printDate() doesn't use the global variables they remain zero forever. That would prevent that 'if' from doing anything useful.