ds 1307 shuts down when arduino turns on leds

[code]hi forum members  
 I have a ds 1307 I can not get it to set the time properly. I have tried the example sketch as follows 
[code#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h>

void setup()
{
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  pinMode(9,OUTPUT);
  RTC.stop();
  RTC.set(DS1307_SEC,1);        //set the seconds
  RTC.set(DS1307_MIN,50);     //set the minutes
  RTC.set(DS1307_HR,1);       //set the hours
  RTC.set(DS1307_DOW,4);       //set the day of the week
  RTC.set(DS1307_DATE,15);       //set the date
  RTC.set(DS1307_MTH,9);        //set the month
  RTC.set(DS1307_YR,11);         //set the year
  RTC.start();
}

void loop()
{
  Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true
  Serial.print(":");
  Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)
  Serial.print(":");
  Serial.print(RTC.get(DS1307_SEC,false));//read seconds
  Serial.print("      ");                 // some space for a more happy life
  Serial.print(RTC.get(DS1307_DATE,false));//read date
  Serial.print("/");
  Serial.print(RTC.get(DS1307_MTH,false));//read month
  Serial.print("/");
  Serial.print(RTC.get(DS1307_YR,false)); //read year 
  Serial.println();

  delay(1000); 

  if (RTC.get(DS1307_HR, false) == 1 && 
      RTC.get(DS1307_MIN, false) == 50 && 
      RTC.get(DS1307_SEC, false) == 30){
     digitalWrite (13, HIGH);
     digitalWrite (9, HIGH);
  }
  if (RTC.get(DS1307_HR, false) == 1 && 
      RTC.get(DS1307_MIN, false) == 55 && 
      RTC.get(DS1307_SEC, false) == 00){
      digitalWrite (13, LOW);
      digitalWrite (9, LOW);
}

}]

it uploads fine but all I get in the serial monitor is 12:23:0 45/21/2009 over and over
it worked fine for awhile. after I hooked up my led array that im using the uno to switch on and off the rtc would time out and show all 0 in every value spot. I did some research and found out that when my leds turned on it pulled to much current so I unhooked it from the sensor shield and wired it up scl to a5 sda to a4and vs to 5v out on supply rail and ground to ground of supply rail....now it shows the wrong values for date and time but I also can not set them even with the second sketch.

I also found this code here but I get the same results
[code

#include "Wire.h"
#define DS1307_ADDRESS 0x68

void setup(){
Wire.begin();
Serial.begin(9600);
}

void loop(){
printDate();
delay(1000);
}

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);

byte zero = 0x00;
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()); //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/12);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
Serial.println(second);

}

][/code]
any thought or ideas you can give me would be awesome thx guys
and I cant figure out why the first code did not copy properly but it came from the examples used with 0022

Your code is hard to read:

[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]()
{
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]begin[/color](9600);
  [color=#CC6600]pinMode[/color](13, [color=#006699]OUTPUT[/color]);
  [color=#CC6600]pinMode[/color](9,[color=#006699]OUTPUT[/color]);
  RTC.[color=#CC6600]stop[/color]();
  RTC.set(DS1307_SEC,1);        [color=#7E7E7E]//set the seconds[/color]

Just copy the code, don't use "copy for forum". Then put it into code tags.

How to use this forum

ok thx nick ill adjust that when i get home.. but do u have any idea as to why the chip does not work with either one of the codes?

Why do you set the time every time the sketch starts? Won't it always be the same time after a reset? Sounds like it might be an electrical issue.

simply put nick its just test code and i have no batt back up for the clock. i actually got it to work properly after i removed it from the sensor shield and wired it into the board itself. power and ground on the supply rail and sd int a4 and scl into a5 and using this code.

#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h>

void setup()
{
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  pinMode(9,OUTPUT);
  RTC.stop();
  RTC.set(DS1307_SEC,1);        //set the seconds
  RTC.set(DS1307_MIN,50);     //set the minutes
  RTC.set(DS1307_HR,1);       //set the hours
  RTC.set(DS1307_DOW,1);       //set the day of the week
  RTC.set(DS1307_DATE,29);       //set the date
  RTC.set(DS1307_MTH,9);        //set the month
  RTC.set(DS1307_YR,13);         //set the year
  RTC.start();
}

void loop()
{
  Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true
  Serial.print(":");
  Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)
  Serial.print(":");
  Serial.print(RTC.get(DS1307_SEC,false));//read seconds
  Serial.print("      ");                 // some space for a more happy life
  Serial.print(RTC.get(DS1307_DATE,false));//read date
  Serial.print("/");
  Serial.print(RTC.get(DS1307_MTH,false));//read month
  Serial.print("/");
  Serial.print(RTC.get(DS1307_YR,false)); //read year 
  Serial.println();

  delay(1000); 

  if (RTC.get(DS1307_HR, false) == 1 && 
      RTC.get(DS1307_MIN, false) == 50 && 
      RTC.get(DS1307_SEC, false) == 30){
     digitalWrite (13, HIGH);
     digitalWrite (9, HIGH);
  }
  if (RTC.get(DS1307_HR, false) == 1 && 
      RTC.get(DS1307_MIN, false) == 55 && 
      RTC.get(DS1307_SEC, false) == 00){
      digitalWrite (13, LOW);
      digitalWrite (9, LOW);
}

}

now the issue is that when those pins go high the clock stops working. i go from having the time to having zeros in the time and date are. i tried to post a screenshot but could not so i attached it.

The DS1307 does not work properly without the battery backup. According to the datasheet:

Battery voltage must be held between 2.0V and 3.5V for proper operation.

nick i have gotten a new battery and installed it in the rtc. i tested the set up using a wall transformer and unfortunately i got the same result. after 30 seconds the lights came on and then when the 5 min of time went bye the lights never shut off, so i am pretty sure the clock is shutting down still, i am wondering if i should move this topic to the power section now though.what do you think.

Its not clear to me what you actually have - an RTC chip? an RTC breakout board
with chip, crystal and battery? Can you clarify what the hardware is.

it is a breakout board....in fact here is a pic of it....

I'll move it to general electronics for you.

Hi, thanks for the picture, that LED is a unit that I think needs a bit of current to run.
What are its specifications and how are you turning it ON?
I hope not directly from the arduino pin 9 or pin 13.
This could cause lockups with your software and cpu resets.
Can you post a schematic or a picture of your circuit diagram.

Tom..... :slight_smile:
PS I see more than just two wires to that LED, how many are there and if you have a MOSFET or transisitor turning them ON, where are you getting the supply for them.

i am turning it on from those pins using a tip 102 trannie...the main power for the leds is coming from the vin on the power rail wich is giving me 12 volts from the wall transformer...that is wired to the positive side of the led....then pins 9 and 13 is running to the base of the trannies to switch them on then the collector is going to the negative side of the led to switch them on and off..and of course the emitter is going to ground...the leds are on star pads to facilitate the wiring them up in parallel...yes they need lots of current about 800 ma worth and i have that going to them the data sheet on those tip 102 shows that those have a collector current of 8 amps min....they turn on fine and work great just the clock shuts down when i get a chance to post the diagram i will..and the leds are wired in parallel one circuit is white and the other are blue led her is a pic of my hand drawn schem and a pic of the actual wiring as well

now i have a quandary....yesterday i got some time to play with the lights....i found that when i had it connected to my laptop the clock chip stayed on when the lights turned on and the test program worked fine. when i unhooked it from the laptop and used the wall plug the lights came on but did not turn off when supposed to. so i plugged it into to both to watch the serial monitor it worked as supposed to then as well....and once again not with just the wall plug.

Hi, you say that you need 800mA.
I would say no matter what the spec of the "wall wart" is, it is not supplying the needed current, try swapping power sources with only ONE LED on each output transistor.
The output of the wart is not able to produce clean DC under load, this causes problems with the arduino.
Can you please post he spec or supplier of the LEDs please?

Tom.... :slight_smile:

hi tom thanks for the idea and yea that wall wart is not holding up i found yesterday that when the leds power up the voltage for the clock drops from 5 v to 2.5 v and the supply for the leds drops from 12 v to 5 v to me that's a severe voltage drop and i'm not liking it lol.....i'm going to try to try a few different wiring schemes when i get the chance this week...thanks and the leds i got came from kingbright for the blues and the white ones o got off ebay

here is a good illustration of my circuit. its wired up just the same as every other circuit like this i have seen...im suspecting that rhe wall wart is the issue but im also wondering if i could toss a voltage regulator in there like a 7805 or a 7815 and use that to supply the clock cause thats where my problem lies is getting that guy happy.

lights.docx (271 KB)