I purchased the ZS-042 on Ebay (advertised as DS3231 AT24C32 IIC) as a replacement for my DS1302 RTC modules. The DS1302 seemed to work very well for my application, but it lacked accuracy. Over a period of about 4 months, the DS1302 gained about 8 minutes. The ZS-042 seems to be much more accurate!
Wiring the ZS-042
The wiring of the ZS-042 is very simple. I only made for connections to make this clock work. This module works on I2C (Inter-IC) communication. In my case, I wired VCC to 3.3v on the Uno, GND (ground) to GND, SCL (Serial Clock) to SCL, and SDA (Serial Data) to SDA on the Uno. If you have an older Uno, just use A5 for SCL, and A4 for SDA. The RTC module can be used for applications such as an alarm clock, for time stamping, or simply to display the current time on an LCD display.
Code for ZS-042
I found some code on the TronixStuff website to make this module work. Before uploading, I un-commented the “setDS3231time” line, and adjusted the clock. I set the clock about 1 minute ahead of time, and then pressed the upload button about 4 seconds ahead of the time setting because it takes a few seconds for the upload to complete. I didn’t want the clock to be reset to this time every time the power is cycled, so then I commented out the “setDS3231time” and uploaded again. This code uses the “Wire” Library.
The sketch can be found at http://tronixstuff.com/2014/12/01/tutorial-using-ds1307-and-ds3231-real-time-clock-modules-with-arduino/
After the upload is complete, you can go to your serial monitor to very the clock is correct. Be sure to set your baud rate to 9600 if using this exact code.
If you are using a standard CR2032 battery, I would strongly recommend disabling the charging circuit. This can easily be done by removing the series charging resistor. There is a youtube video on how to do this here. I’ve attempted using the standard CR2032 without disabling the charging circuit. The battery began to bulge and was worthless after just a couple days. Up to this time, I’ve never had to replace a standard CR2032 yet, and I’ve been using the ZS-042 for over six months now.
I would recommend removing power for a few minutes then powered back up to ensure the CR2032 battery is working, then verify the time again through your serial monitor.
Once you have the RTC up and running, you can experiment with other features such as the alarm feature, and square wave generator… This module can also store some data to EEPROM, but my main reason for upgrading to this module was for the accuracy of the clock itself. I like to keep things as simple as possible!
— Ricky Bryce
Well thank you! I bought this clock in a kit and the guide with it was old indicating to use A4 A5 to connect the clock and I have an UNO R3, so it was all but functioning… it was loosing up to 2 minutes a day but this insight about the new SCL SDA pin placement saved my day! Now my contraption is working!
I have been using this RTC on an application – a solar single axis tracker. Sww watt-tracker.com.
As usual, I forgot to document some code segments.
One subroutine I call PowerFromBattery
It goes like this:
I2C transmit byte 208 – this is a write command
I2C transmit byte 0x0E – I believe this is the control register
I2C transmit byte (0b00011100)
I can not remember what it does exactly, or from where I got it.
You are right…. It’s difficult to remember the purpose of each bit in each register. The data sheet might help to jog your memory. The Control register is on page 13 at https://datasheets.maximintegrated.com/en/ds/DS3231.pdf.
If you power the RTC module using 3.3V instead of 5.0V, the battery charges just fine and does not bulge. I’ve been using mine at 3.3V for 3 years now.
That’s a very good point. Because of the voltage drop of the diode, and since the batter is 3v, you have much less chance of the overcharging problem! In short, that has to be one of the cheapest, crudest charging circuits that I’ve seen. Thank you for your comment. — Ricky Bryce