Using a basic 1307 SetTime program, and ran into a problem (first time programming a module).

#include <Wire.h>
#include <Time.h>
#include <DS1307RTC.h>

const char *monthName[12] = {
  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"

tmElements_t tm;

void setup() {
  bool parse=false;
  bool config=false;

  // get the date and time the compiler was run
  if (getDate(__DATE__) && getTime(__TIME__)) {
    parse = true;
    // and configure the RTC with this info
    if (RTC.write(tm)) {
      config = true;

  while (!Serial) ; // wait for Arduino Serial Monitor
  if (parse && config) {
    Serial.print("DS1307 configured Time=");
    Serial.print(", Date=");
  } else if (parse) {
    Serial.println("DS1307 Communication Error :-{");
    Serial.println("Please check your circuitry");
  } else {
    Serial.print("Could not parse info from the compiler, Time=\"");
    Serial.print("\", Date=\"");

void loop() {

bool getTime(const char *str)
  int Hour, Min, Sec;

  if (sscanf(str, "%d:%d:%d", &Hour, &Min, &Sec) != 3) return false;
  tm.Hour = Hour;
  tm.Minute = Min;
  tm.Second = Sec;
  return true;

bool getDate(const char *str)
  char Month[12];
  int Day, Year;
  uint8_t monthIndex;

  if (sscanf(str, "%s %d %d", Month, &Day, &Year) != 3) return false;
  for (monthIndex = 0; monthIndex < 12; monthIndex++) {
    if (strcmp(Month, monthName[monthIndex]) == 0) break;
  if (monthIndex >= 12) return false;
  tm.Day = Day;
  tm.Month = monthIndex + 1;
  tm.Year = CalendarYrToTm(Year);
  return true;

And I got the following

"tmElements_t tm;" does not name a type.

1 Answer 1


According to example ReadTest/ReadTest.ino, you have to include

#include <TimeLib.h>

See also comment from Alexander below (unchecked by me) that Time.h needs to be referenced.

  • Added that to the code, and it tells me there is no such file or directory.
    – ApeBoy89
    Apr 12, 2019 at 10:19
  • 1
    Maybe you used another library (you could try this one instead?) I never used this or the other library myself btw. Apr 12, 2019 at 10:31
  • 1
    Arduino Studio also need to reference Time Library.
    – Alexander
    Apr 12, 2019 at 14:54
  • I'm pretty sure I used the right library, and it's in the Arduino library folder. Changed it to <TimeLib.h> and ran into the invalid library issue. I put on my TFT shield and tested the examples for that and it ran fine. Maybe something else that I am missing... First time wiring up a module.
    – ApeBoy89
    Apr 12, 2019 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.