Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
sraykov08
Published

Data logger shield sd card and real time clock

Use sd and time

IntermediateFull instructions provided3,663
Data logger shield sd card and real time clock

Things used in this project

Hardware components

Flash Memory Card, SDHC Card
Flash Memory Card, SDHC Card
×1
data logger shield
×1
Arduino UNO
Arduino UNO
×1
cr1220 batery
×1
USB-A to B Cable
USB-A to B Cable
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

clock

C/C++
#include <Wire.h>
#include <ds3231.h>
#include <SPI.h> 
#include <SD.h>  

const char* filename = "time.txt";

File file;

struct ts t;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  DS3231_init(DS3231_INTCN);
  if (!SD.begin(10)) {
    Serial.println("Error : Push the reset button");
    for (;;); 
  }
  
  file = SD.open(filename, FILE_WRITE);
  /*----------------------------------------------------------------------------
    In order to synchronise your clock module, insert timetable values below !
    ----------------------------------------------------------------------------*/
  t.hour = 12;//hours
  t.min = 54;//minutes
  t.sec = 20;//seconds
  t.mday = 2;//date
  t.mon = 12;// month
  t.year = 2120;//year

  DS3231_set(t);
}

void loop() {
  DS3231_get(&t);
  Serial.print("Date : ");
  file.print("Date : ");
  file.flush();
  Serial.print(t.mday);
  file.print(t.mday);
  file.flush();
  Serial.print("/");
  file.print("/");
  file.flush();
  Serial.print(t.mon);
  file.print(t.mon);
  file.flush();
  Serial.print("/");
  file.print("/");
  file.flush();
  Serial.print(t.year);
  file.print(t.year);
  file.println();
  file.flush();
  Serial.print("\t Hour : ");
  file.print("\t Hour : ");
  file.flush();
  Serial.print(t.hour);
  file.print(t.hour);
  file.flush();
  Serial.print(":");
  file.print(":");
  file.flush();
  Serial.print(t.min);
  file.print(t.min);
  file.flush();
  Serial.print(".");
  file.print(".");
  file.flush();
  Serial.println(t.sec);
  file.println();
  file.flush();

  delay(1000);
}

Credits

sraykov08
7 projects • 1 follower
Contact

Comments

Please log in or sign up to comment.