Editor Version ×
Standard

1.Easy to use and quick to get started

2.The process supports design scales of 300 devices or 1000 pads

3.Supports simple circuit simulation

4.For students, teachers, creators

Profession

1.Brand new interactions and interfaces

2.Smooth support for design sizes of over 5,000 devices or 10,000 pads

3.More rigorous design constraints, more standardized processes

4.For enterprises, more professional users

Ongoing

STD DS3231 Real-time Clock Modules with Arduino

License:

Mode: Editors' pick

  • 6.9k
  • 0
  • 2
Update time: 2021-06-28 10:07:40
Creation time: 2015-12-27 14:16:59
Description
## DS3231 AT24C32 IIC Precision RTC Real Time Clock Memory Module For Arduino ## Keeping the time with your Arduino or compatible board is not only easy but also the base for all manner of clock and timing related projects. No doubt you've seen various clocks and wanted to do this yourself - and now you can with a real-time clock module. There are two main differences between the boards, which is the accuracy of the time-keeping. The DS3231 used in the first module works very well, however the external temperature can affect the frequency of the oscillator circuit which drives the DS3231's internal counter. This may sound like a problem, however will usually result with the clock being off by around five or so minutes per month. The DS3231 is much more accurate, as it has an internal oscillator which isn't affected by external factors - and thus is accurate down to a few minutes per year at the most. If you have a DS1307 module- don't feel bad, it's still a great value board and will serve you well. With both of the modules, a backup battery is installed when you receive them from Tronixlabs, however these are an inexpensive variety and shouldn't be relied on for more than twelve months. If you're going to install the module in a more permanent project, it's a good idea to buy a new CR2032 battery and fit it to the module. Along with keeping track of the time and date, these modules also have a small EEPROM, an alarm function (DS3231 only) and the ability to generate a square-wave of various frequencies - all of which will be the subject of a second tutorial. ![Connecting your module to an Arduino][1] ## Connecting your module to an Arduino ## Both modules use the I2C bus, which makes connection very easy. If you're not sure about the I2C bus and Arduino, check out the I2C tutorial on our sister site tronixstuff, or review chapter seventeen of John's book "Arduino Workshop". Moving on - first you will need to identify which pins on your Arduino or compatible boards are used for the I2C bus - these will be knows as SDA (or data) and SCL (or clock). On Arduino MEGA2560 or compatible boards, these pins are A4 and A5 for data and clock ## DS3231 module ## Connecting this module is easy as header pins are installed on the board at the factory. You can simply run jumper wires again from SCL and SDA to the Arduino and again from the module's Vcc and GND pins to your board's 5V or 3.3.V and GND. However these are duplicated on the other side for soldering your own wires. Both of these modules have the required pull-up resistors, so you don't need to add your own. Like all devices connected to the I2C bus, try and keep the length of the SDA and SCL wires to a minimum. ## Reading and writing the time from your RTC Module ## Once you have wired up your RTC module. enter and upload the following sketch. Although the notes and functions in the sketch refer only to the DS3231, the code also works with the DS1307.
#include "Wire.h"
#define DS3231_I2C_ADDRESS 0x68
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}
void setup()
{
  Wire.begin();
  Serial.begin(9600);
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
   setDS3231time(30,35,21,1,27,12,15);
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
  // sets time and date data to DS3231
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
  Wire.write(decToBcd(month)); // set month
  Wire.write(decToBcd(year)); // set year (0 to 99)
  Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}
void displayTime()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
  // convert the byte variable to a decimal number when displayed
  Serial.print(":");
  if (minute
Design Drawing
schematic diagram
1 /
PCB
1 /
The preview image was not generated, please save it again in the editor.
ID Name Designator Footprint Quantity
1 DS3231SO U1 S016W 1
2 8P4R0603 R1,R2 8P4R-0603 2
3 -9VBAT U2 BAT 1
4 CAT24C02WI-G U3 SOIC-8 1
5 SIP6 P1 HDR1X6 1
6 SIP4 P2 HDR1X4 1
7 Arduino MEGA 2560 U4 DIP 1
8 1k R3 R3 1
9 LED D1 LED3MM 1

Unfold

Project Attachments
Empty
Project Members
Target complaint
Related Projects
Change a batch
Loading...
Add to album ×

Loading...

reminder ×

Do you need to add this project to the album?

服务时间

周一至周五 9:00~18:00
  • 0755 - 2382 4495
  • 153 6159 2675

服务时间

周一至周五 9:00~18:00
  • 立创EDA微信号

    easyeda

  • QQ交流群

    664186054

  • 立创EDA公众号

    lceda-cn