DS1302 RTC not storing time

Hi
Bare with me I am really new to all this but I am so keen to learn.

I am having trouble getting my DS1302 to memorise the time after removing the main power source. At this point my code is telling me that write protection is enabled. How do i go about disabling this??

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <DS1302RTC.h>
#include <MsTimer2.h>
#include <Time.h>
#include <LiquidCrystal.h>

#define I2C_ADDR    0x3F // <<----- Add your address here.  Find it from I2C Scanner
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7

DS1302RTC RTC(6, 7, 8);
#define DS1302_GND_PIN 2
#define DS1302_VCC_PIN 3

LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup() {
Serial.begin(9600);       // Begin serial session
lcd.print("RTC activated");

  delay(500);

  // Check clock oscillation  
  lcd.clear();

  if (RTC.haltRTC()) lcd.print("Clock stopped!");
  else lcd.print("Clock working.");

  // Check write-protection
  lcd.setCursor(0,1);

  if (RTC.writeEN())
    //lcd.print("Write allowed.");
    Serial.println("Write allowed.");
  else {
    //lcd.print("Write protected.");
    Serial.println("Write protected.");
    
  }

  delay ( 2000 );

  // Setup Time library  
  lcd.clear();
  lcd.print("RTC Sync");
  setSyncProvider(RTC.get); // the function to get the time from the RTC
  if(timeStatus() == timeSet)
    lcd.print(" Ok!");
  else
    lcd.print(" FAIL!");

  delay ( 2000 );

  lcd.clear();
  setTime(7, 29, 30, 28, 4, 2016);


  lcd.begin(16, 2);
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); // Define backlight pin
  lcd.setBacklight(HIGH);   // Enable LCD backlight
  lcd.home ();              // ???


}

void loop(){
    lcd.setCursor(4, 0);
    print2digits(hour());
    lcd.print(":");
    print2digits(minute());
    lcd.print(":");
    print2digits(second());
    


  if(timeStatus() != timeSet) {
    lcd.setCursor(0, 1);
    lcd.print(F("RTC ERROR: SYNC!"));
  }

}

There are a lot of problems with the DS1302. If you have a cheap module from Ebay, you need luck to make it work. Maybe you need a lot of luck. Some try to make it work by extra toggling some pins, or do something with the power.

The DS1307 is better, but the DS3231 is the best.

Which library do you use ?
This one ? Arduino Playground - DS1302RTC

Get rid of the DS1302. Buy a DS3231 module.
If you bought a DS1302 module from a well known and good seller, they might also provide good code for it.

Although I upgraded to the 1307 becasue the I2C interface is more frugal on pins, I had good success with the 1302 using Henning Karlsen's library.

A DS1302 from a good seller or a cheap module from Ebay ?

Koepel:
A DS1302 from a good seller or a cheap module from Ebay ?

An industrial supplier Mantech here in Johannesburg.

Then you have a good chip (or good module) and I suppose good other components as well.
bcraig24 might have bought a cheap module and it may never work.

Koepel:
The DS1307 is better, but the DS3231 is the best.

Which library do you use ?
This one ? Arduino Playground - HomePage

Get rid of the DS1302. Buy a DS3231 module.
If you bought a DS1302 module from a well known and good seller, they might also provide good code for it.

I bought a Arduino kit form my local electronics store which came with my DS1302. Not sure on its quality but the UNO has the gold marker proving its quality so I would assume the components accompanying it would be also.
I am using the library you mentioned.

Maybe I will try the DS3231.

JimboZA:
Although I upgraded to the 1307 becasue the I2C interface is more frugal on pins, I had good success with the 1302 using Henning Karlsen's library.

I tried this library and it is now giving me this error. Repeated for every day of the week and month on the year.

B:\Program Files\Arduino\libraries\DS1302\DS1302.cpp:258:10: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

output="Monday";

Found this thread by googling DS1302 trouble, which means others may be reading it too, so here's an update.

JimboZA:
I had good success with the 1302 using Henning Karlsen's library.

Can confirm this is a very easy way to get the DS1302 working. I tried two other libraries (RTCLib_by_NeiroN and another one that also needed Time.h (seriously, I don't expect something simple like this to need TWO special purpose libraries)) and I couldn't fathom either of them. Karlsen's library worked straight away, no messing. I'm using Arduino Nano and the cheapest DS1302 module I could find on eBay China.