HELP PLEASE! DS3231 RTC clock won´t work (and I need it to work asap for a college project)

Hi, I´m Marta, a college student that has never done anything with electronics or programming BUT I´ve always wanted to try at it. So, I´m doing a project for college that consists of a lamp that imitates a sunrise to wake you up easier, but to do so i have to program the arduino uno i just got with an RTC DS3231 that wont work properly.

The problem: the rtc DS3231 will not work no matter how many tutorials and libraries I try to use. Rn I´m using the one from here: http://www.rinkydinkelectronics.com/library.php?id=73

I´ve downloaded it, opened arduino IDE and uploaded the zip library, and when i open the example to set the serial time, edit it and upload it, the serial monitor shows the date once when uploaded and then this: ϊ⸮Friday 12.11.2021 -- 21:46:10
⸮⸮X⸮⸮⸮⸮⸮⸮X⸮⸮X⸮⸮X⸮⸮⸮"⸮['⸮⸮⸮X⸮⸮X⸮⸮⸮⸮⸮ ⸮['⸮Y'⸮⸮⸮Y⸮⸮X⸮⸮⸮&⸮0iX⸮⸮X⸮⸮⸮&⸮⸮⸮⸮⸮X⸮⸮X⸮⸮['⸮['⸮0iX⸮⸮⸮⸮Y%⸮⸮&⸮⸮"⸮5⸮⸮⸮Y-⸮Y-⸮ ⸮⸮⸮Y'⸮Y-⸮Y-⸮⸮⸮5⸮['⸮Y'⸮['⸮⸮⸮⸮⸮⸮Y'⸮ ⸮Y-⸮5⸮X⸮⸮X⸮⸮['⸮X⸮⸮⸮⸮⸮⸮X⸮⸮⸮⸮Y-⸮['⸮ ⸮ ⸮⸮Y'⸮Y-⸮⸮⸮ ⸮Y⸮⸮⸮⸮⸮⸮X⸮⸮X⸮⸮Y%⸮⸮⸮⸮⸮⸮⸮⸮⸮"⸮ ⸮0iX⸮⸮Y-⸮⸮"⸮X⸮⸮Y-⸮⸮⸮⸮⸮X⸮⸮⸮&⸮Y-⸮X⸮⸮X⸮⸮X⸮⸮Y%⸮X⸮⸮⸮⸮5⸮['⸮Y-⸮X⸮⸮Y⸮⸮Y-⸮ ⸮⸮⸮X⸮⸮X⸮⸮⸮⸮⸮"⸮⸮&⸮Y'⸮X⸮⸮⸮"⸮['⸮⸮"⸮ ⸮['⸮⸮⸮⸮⸮⸮"⸮⸮⸮ ⸮⸮"⸮⸮⸮Y%⸮⸮⸮0aX⸮⸮Y%⸮X⸮⸮X⸮⸮⸮⸮⸮Y'⸮['⸮X⸮⸮['⸮ ⸮5⸮⸮⸮⸮⸮⸮⸮X⸮⸮X⸮⸮⸮⸮0a⸮⸮

this is the example when opened:
`// DS3231_Serial_Easy
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
//
// A quick demo of how to use my DS3231-library to
// quickly send time and date information over a serial link
//
// To use the hardware I2C (TWI) interface of the Arduino you must connect
// the pins as follows:
//
// Arduino Uno/2009:
// ----------------------
// DS3231: SDA pin -> Arduino Analog 4 or the dedicated SDA pin
// SCL pin -> Arduino Analog 5 or the dedicated SCL pin
//
// Arduino Leonardo:
// ----------------------
// DS3231: SDA pin -> Arduino Digital 2 or the dedicated SDA pin
// SCL pin -> Arduino Digital 3 or the dedicated SCL pin
//
// Arduino Mega:
// ----------------------
// DS3231: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA pin
// SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL pin
//
// Arduino Due:
// ----------------------
// DS3231: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA1 (Digital 70) pin
// SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL1 (Digital 71) pin
//
// The internal pull-up resistors will be activated when using the
// hardware I2C interfaces.
//
// You can connect the DS3231 to any available pin but if you use any
// other than what is described above the library will fall back to
// a software-based, TWI-like protocol which will require exclusive access
// to the pins used, and you will also have to use appropriate, external
// pull-up resistors on the data and clock signals.
//

#include <DS3231.h>

// Init the DS3231 using the hardware interface
DS3231 rtc(SDA, SCL);

void setup()
{
// Setup Serial connection
Serial.begin(115200);
// Uncomment the next line if you are using an Arduino Leonardo
//while (!Serial) {}

// Initialize the rtc object
rtc.begin();

// The following lines can be uncommented to set the date and time
rtc.setDOW(FRIDAY); // Set Day-of-Week to SUNDAY
rtc.setTime(21, 46, 10); // Set the time to 12:00:00 (24hr format)
rtc.setDate(12, 11, 2021); // Set the date to January 1st, 2014
}

void loop()
{
// Send Day-of-Week
Serial.print(rtc.getDOWStr());
Serial.print(" ");

// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");

// Send time
Serial.println(rtc.getTimeStr());

// Wait one second before repeating :slight_smile:
delay (1000);
}`

somebody please help me, and guide me through step by step to make it work.
THANK YOU <3!!!

Show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.

1 Like

First thing you should be doing is running the "standard" I2C Scanner. It will scan all I2C addresses and report if anything was found.
Results:

  1. Reports an I2C device at the address of you DS3231 = good it is at least talking
  2. Does not report any I2C devices (or at least not a device as should be the DS3231 address) = BAD check wiring, move every wire to verify the connections are good. Continue to run the scanner until your device is found.

Then, Run the example from you library for the DS3231.

// I2C Scanner

#include <Wire.h>

void setup() {
  Wire.begin();

  Serial.begin(9600);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}

void loop() {
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for (address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.print(address, HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error == 4)
    {
      Serial.print("Unknown error at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.println(address, HEX);
    }
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan
}

And is this the same setting as in the serial monitor?

Please remember to use code tags when posting code

That rinkydinkelectronics library is not a nice library. It uses its own software I2C bus for the DS3231. I doubt if that will go together with other I2C devices.
The 'SDA' and 'SCL' are defined for your Uno by Arduino. They are the labels for the hardware I2C bus.

I suggest to use a normal library.
Do you want to use a "time" library, or do you just want to read the time now and then from the DS3231 ?


Okay so this is the wiring I´m using rn. The arduino is an ELEGOO UNO R3, ), an the RTC clock is from AZDelivery

so this is what the Serial monitor says, which I believe is a good thing right?, Scanning... I2C device found at address 0x57 ! I2C device found at address 0x68 ! done

Which one would you recommend? I´m planning to make a lamp that using the clock it can be programmed to turn on at X time and slowly get brighter and brighter (resembling a sunrise), I´m basically making a sunrise alarm clock. I´m sorry I might sound dumb but I just have no idea about this new world of electronics in getting into :sweat_smile:

OH! I noticed it was different so I changed that but still it wouldn´t work, but since Koepel recommended to change the library to a better one I´m not worrying about that one. And how can I use code tags here? (there´s a little icon like this: </> that´s what I used to paste the code before but it doesnt look quite like the other codes on here, let me know how to properly post code please :hugs: :grin: )

Let's assume you overcome the issue of the RTC not working, by finding a better library. That the I2C scanner found the clock is good news. (My Arduino sketches are all on an old laptop that struggles to fire up, so I can't check to see what library I used for a DS3231 sketch I used a few years back- I'll see if it's in a good mood and fires up....)

So, assuming the clock works, what's your strategy (in words, not code) to have your system know when it's sunrise?

To paste code in tags is easy.

  • In the IDE, press control-T which formats the sketch with nice indents to make easy to read.

  • In the IDE, press control-shift-C to snag the code for the forum

  • Then just control-V that into the forum. Simples...

After some research I´ve found two main tutorials: 1) He explains everything so well i felt like I could even understand it (but he used the library that they are saying isn´t very good (but I´ve managed to make the RTC work perfectly with this one) here´s the link to the youtube video with all the info in the description box:
The thing is he used a normal LED and I want to use an RGB one to resemble the sun better SO i found this other tutorial that uses the adafruit neopixel (I got the 12 led ring)

The goal now is to mix both codes to be able to use it with the RGB led. Do you think it´d be too difficult to include the adafruit library/code (i dont really know the difference lol) into the first simpler code?

And this is how everything would be wired:

But I dont know if I´d need to put on some resistors or if to power it´d be enough through the USB or a 12V transformer to the arduino or breadboard power supply. (I know I´m asking wayyyy too much so if you don´t really know how to help is completely understandable!)

And thanks for the tip on how to post code :smiling_face_with_three_hearts: !!

Adafruit has a long tutorial on their Neopixels. Take a look at the section on power. They suggest a cap and an external power supply because each pixel will pull as much as 60mA at maximum brightness.

The fastest way is to use the Adafruit RTClib. It is in the Library Manager in the Arduino IDE.
There is also a TimeLib, which is more basic, but also more extendable.

The Arduino Uno is a 5V board with a 5V I2C bus (The SDA and SCL are between 0...5V).
If you power the DS3231 module with 3.3V, then it has a 3.3V I2C bus.
That means your I2C bus is not good, it barely works.

You can power the DS3231 module with 5V, but not if you have a rechargeable battery in it. That module has a bad charging circuit. You can disable the charging by removing the diode and put a normal battery in it.

Your DS3231 module costs less than 4 euros: https://www.aliexpress.com/item/1005003101038004.html
You paid 8 euros for the exact same module.

All this trouble with the module, with 5V and 3.3V, with the I2C, and so on, that is what you get when you buy the cheapest things. Adafruit makes good quality modules, they test everything they sell, they don't use fake components, they have a forum, and so on. They don't cheat, they tell if a module can be used with 3.3V and 5V.
DS3231: https://www.adafruit.com/product/3013
Look there for a good tutorial, they also explain how to install the RTClib and how to use an example.

Are you feeling where this is going ? Your DS3231 might be a counterfeit, there are many bad tutorial on Youtube and Instructables, if you buy the cheapest crap then it might not work very well or maybe only for a week or maybe only in a certain situation.
Be careful, if you buy a more expensive module from a local seller, then it might be the same as the cheapest crap on Ebay/Aliexpress/Amazon.

Damn it, they really ripped off then. The best thing would be, like you said, to order the components off of adafruit but being from Spain and needing them as fast as possible to be able to hand in the project on time, it would´ve been risky if it gets stopped on customs (same goes for aliexpress and banggod and so on). So my only option was amazon and I did what I could honestly, even though it might not be the best solution.
I´ll try using that library and with some luck it´ll all work out just fine before my due date (aka in about 2 weeks for the whole lamp lol)

Appreciate all this advice too, if I make another cool arduino project on my own free time I´ll be sure to get the things from proper sellers.
Thanks man!!

Update ----

Why did you say 'Damn it, they really ripped off then. "? I may have missed something but the device responds to a I2C scan. Are you sure it isn't working? Read more below.....


The I2C address of the DS3231 is 0x68.

The other address you found is for the on module EEPROM (also I2C).

Unless you need the EEPROM you can ignore it.

If you were an Arduino hobbyist you would learn the ins and outs of purchasing electronic module. But since this is a one off college project none of that matters.

I've not used a library for my DS3231 but when I look in the Arduino library manager I find the first entry is: this library.

I'm using arduino V2 beta so I don't know if it is in the IDE V1.xxx

I would load it and run one of their examples. I believe this is the fastest way to get things going.

Regarding the charging and the diode. I would recommend you start without the battery at all. Just to get going.

If you then want to use a regular battery and if you don't have the proper soldering equipment to unsolder it....simply crush it with a small pliers. Not very elegant but effective and quick.

The thing that I said about thinking that I got ripped off, comes from how Koepel explained that I got sold a cheap component for double its price, (but I can´t do anything now to change that so it´s okay).
I believe the RTC works, because it shows the date and time (not the right one but I´ll try to change that), but now I´m trying to use the new library recommended.
What difference would it make having the battery that comes with the rtc on or off?

Thanks for making it a bit easier for me, i was getting a little overwhelmed tbh hahah

The battery is just there to keep the clock running when your project doesn't have power. It will work without it, but it won't retain the proper time if you turn it off.

No thanks necessary :slight_smile: Happy I was able to help.

The battery keeps the RTC going when you loose board power. So in theory once you set the RTC with the correct time, the battery will keep the RTC running when power is disconnected to the board.

I wouldn't worry about getting "ripped off". You have an RTC, it seems to work, but you found it might have been cheaper elsewhere. It happens to everybody.

If only paying more meant one was assured of getting a better or genuine instance of a module. :expressionless:

I accidentally purchased 25 RTCs, thought I was buying 5 (life tim supply) but turned out to be 5 packs of 5… so they are the ones I’m using, haha.

So far so good, but I have not checked the long term accuracy, one specification that the counterfeit modules can’t keep up to.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.