GolamMostafa:
Let us follow every step of this tutorial. When a step is done, then put a tick mark on it. After the expected result has been achieved, we may slowly study the functions of the codes lines of the sketch.
1. Connect DS3231 Module as per diagram of Fig-1. -DONE

Figure-1:
2. Upload the following sketch. -DONE
#include <Wire.h>
#include "RTClib.h" // Jeelab's fantastic RTC library.
RTC_DS3231 rtc;
byte prMin = 0;
byte x;
void setup ()
{
Serial.begin(9600);
Wire.begin();
rtc.begin();
rtc.adjust(DateTime(F(DATE), F(TIME)));
//rtc.adjust(DateTime(2021, 12, 31, 11, 59, 57));//set date-time manualy:yr,mo,dy,hr,mn,sec
}
void loop ()
{
showDate(); //show date on Serial Monitor
showTime(); //Current time: 24 Hrs
showTemp(); //show temperature
timeDelay(); //2 minute time delay as counted by RTC
}
//===================================================
void showDate()
{
DateTime nowDT = rtc.now();
Serial.print(nowDT.day(), DEC); Serial.print('/');
Serial.print(nowDT.month(), DEC); Serial.print('/');
Serial.print(nowDT.year(), DEC); Serial.print(" ==> ");
}
void showTime()
{
DateTime nowDT = rtc.now();
Serial.print(nowDT.hour(), DEC); Serial.print(':');
//-------------------------------------------------
byte myMin = nowDT.minute();
if (myMin < 10)
{
Serial.print('0');
}
Serial.print(nowDT.minute(), DEC); Serial.print(':');
//--------------------------------------------------
byte mySec = nowDT.second();
if (mySec < 10)
{
Serial.print('0');
}
Serial.print(nowDT.second(), DEC);
}
//---------------------------------------------
void timeDelay()
{
prMin = bcdMinute(); //current second of RTC
while (bcdMinute() - prMin != 1)
{
;
}
prMin = bcdMinute(); //delay(1000);
}
byte bcdMinute()
{
DateTime nowTime = rtc.now();
if (nowTime.minute() == 0 )
{
prMin = 0;
return prMin;
}
else
{
DateTime nowTime = rtc.now();
return nowTime.minute();
}
}
void showTemp()
{
float myTemp = rtc.getTemperature();
Serial.print(" Temperature: ");
Serial.print(myTemp, 2);
Serial.println(" degC");
}
//==========================================
**2.** Observe that the Serial Monitor shows the current date, time in 24-Hrs format, and temperature at 1-min interval (Fig-2). The current date and time are taken from PC; however, the user can (if he wishes) set it manually in the setup() function of the sketch by manipulating the following codes: -DONE
rtc.adjust(DateTime(F(DATE), F(TIME))); //takes data time from PC
//rtc.adjust(DateTime(2021, 12, 31, 11, 59, 57));//set date-time manualy:yr,mo,dy,hr,mn,sec

Figure-2:
**3.** Functional Check of SD Card. -DONE
**(1)** Connect SD card with UNO as per Fig-1.
**(2)** Upload the following sketch into UNO to verify that this string "Forum" could be written and read to/from SD card correctly.
//SIMPLE WRITE AND READ
#include<SPI.h> //sd cARD USES spi bUS
#include<SD.h> //contains library functions
#define CSPIN 4 //if using DPin-4, it does not require to set direction
File myFile; //file pointer variavle declaration
void setup()
{
Serial.begin(9600);
pinMode(CSPIN, OUTPUT);
delay(1000);
if (!SD.begin(CSPIN))
{
Serial.println("Card failed, or not present");
return;
}
Serial.println("card initialized.");
// SD.begin(CSPIN); //SD Card is initialized
SD.remove("Test.txt"); //remove any existing file with this name
myFile = SD.open("Test.txt", FILE_WRITE); //file created and opened for writing
if (myFile) //file has really been opened
{
myFile.println("Forum"
);
}
myFile.close();
myFile = SD.open("Test.txt", FILE_READ); //file opened for reading
if (myFile) //file has really been opened
{
while (myFile.available())
{
Serial.print((char)myFile.read());
}
myFile.close();
}
}
void loop()
{
}
**4.** Upload the following sketch to begin temperature logging onto SD card and Serial Monitor when swicth K1 is pressed.
.......... (left for OP)
Thank you for your support, both of these items perform as described.
I have attached a layout of the hardware I am using and how it is currently wired in system. A few items that were left out of the original description can be found below. I want to define this hear so it is clear what we are working with.
Hardware:
1: UNO/NANO
2: 0.96" OLED screen 3.3V (adafruit GFX library)
3: DS3231RTC module 3.3V
4: 74HC595 Shift Register
5: 8x LED
6: Button 1 - sets RTC segment adjust
7: Button 2 - RTC increment
8: Button 3 - RESET
At the moment, there is no hardware provision for a "store" button, but I like the concept and it could likely be packaged.