Error message on the sketch.

Hi, I’m new to programming.
Hardware is not difficult for me, but the software is a big problem.
I got an error message in this sketch.
Please, if you have an idea how to fix it share it.

Error is:
Garduino_Geek_Gardening.ino:2:10: error: #include expects “FILENAME” or
Garduino_Geek_Gardening.ino: In function ‘void setup()’:
Garduino_Geek_Gardening:45: error: ‘DateTime’ was not declared in this scope
Garduino_Geek_Gardening.ino: In function ‘void loop()’:
Garduino_Geek_Gardening:92: error: ‘DateTime’ was not declared in this scope

Greetings Victor.

//include the datetime library, so our garduino can keep track of how long the lights are on

//define analog inputs to which we have connected our sensors
int moistureSensor = 0;
int lightSensor = 1;
int tempSensor = 2;

//define digital outputs to which we have connecte our relays (water and light) and LED (temperature)
int waterPump = 7;
int lightSwitch = 8;
int tempLed = 2;

//define variables to store moisture, light, and temperature values
int moisture_val;
int light_val;
int temp_val;

//decide how many hours of light your plants should get daily
float hours_light_daily_desired = 14;

//calculate desired hours of light total and supplemental daily based on above values
float proportion_to_light = hours_light_daily_desired / 24;
float seconds_light = 0;
float proportion_lit;

//setup a variable to store seconds since arduino switched on
float start_time;
float seconds_elapsed;
float seconds_elapsed_total;
float seconds_for_this_cycle;

void setup() {
//open serial port
//set the water, light, and temperature pins as outputs that are turned off
pinMode (waterPump, OUTPUT);
pinMode (lightSwitch, OUTPUT);
pinMode (tempLed, OUTPUT);
digitalWrite (waterPump, LOW);
digitalWrite (lightSwitch, LOW);
digitalWrite (tempLed, LOW);

//establish start time
start_time =;
seconds_elapsed_total = 0;

void loop() {
// read the value from the moisture-sensing probes, print it to screen, and wait a second
moisture_val = analogRead(moistureSensor);
Serial.print("moisture sensor reads ");
Serial.println( moisture_val );
// read the value from the photosensor, print it to screen, and wait a second
light_val = analogRead(lightSensor);
Serial.print("light sensor reads ");
Serial.println( light_val );
// read the value from the temperature sensor, print it to screen, and wait a second
temp_val = analogRead(tempSensor);
Serial.print("temp sensor reads ");
Serial.println( temp_val );
Serial.print("seconds total = ");
Serial.println( seconds_elapsed_total );
Serial.print("seconds lit = ");
Serial.println( seconds_light);
Serial.print("proportion desired = ");
Serial.println( proportion_to_light);
Serial.print("proportion achieved = ");
Serial.println( proportion_lit);

//turn water on when soil is dry, and delay until soil is wet
if (moisture_val < 850)
digitalWrite(waterPump, HIGH);

while (moisture_val < 850)

digitalWrite(waterPump, LOW);

//update time, and increment seconds_light if the lights are on
seconds_for_this_cycle = - seconds_elapsed_total;
seconds_elapsed_total = - start_time;
if (light_val > 900)
seconds_light = seconds_light + seconds_for_this_cycle;

//cloudy days that get sunny again: turn lights back off if light_val exceeds 900. this works b/c the supplemental lights aren't as bright as the sun:)
if (light_val > 900)
digitalWrite (lightSwitch, LOW);

//turn off lights if proportion_lit>proportion_to_light, and then wait 5 minutes
if (proportion_lit > proportion_to_light)
digitalWrite (lightSwitch, LOW);
delay (300000);
//figure out what proportion of time lights have been on
proportion_lit = seconds_light/seconds_elapsed_total;

//turn lights on if light_val is less than 900 and plants have light for less than desired proportion of time, then wait 10 seconds
if (light_val < 900 and proportion_lit < proportion_to_light)
digitalWrite(lightSwitch, HIGH);

//turn on temp alarm light if temp_val is less than 850 (approximately 50 degrees Fahrenheit)
if (temp_val < 850)
digitalWrite(tempLed, HIGH);


How to use this forum

Read this before posting a programming question

Code tags please.


So where is the name of the library?

What error did you get?


What are you including?


What is the error that you are getting? Can you copy it and post it here? It would help us help you! :wink:

I see also that at the beginning of your sketch you have:


//include the datetime library, so our garduino can keep track of how long the lights are on


…but you are missing the library’s name. It should say:

#include <DateTime.h>

just one other thing, please use the CODE Tags when posting your code. It makes it much nicer and easier to read!
Good Luck!

Error is:

Garduino_Geek_Gardening.ino:2:10: error#include expects “FILENAME” or Garduino_Geek_Gardening.ino: In function setup()’ Garduino_Geek_Gardening:45: error: ‘Date was not declared in this scope Garduino_Geek_Gardening.ino: In function oop()’: Garduino_Geek_Gardening:92: error: 'Date was not declared in this scope

[codee]//include the datetime library, so our garduino can keep track of how long the lights are on

//define analog inputs to which we have connected our sensors

error#include expects “FILENAME” or <FILENAM

It really could not be much clearer.

Is there a possibility that library is not installed:

Where to look for this library

Is there a possibility that library is not installed:

Yes, there is that possibility, but until you tell the compiler that that is the header you want to include, the error message is not going to go away.

You should look for it at the same place you got your sketch from.
If it's not there, there will likely be a link to it.

I just googled the sketchname and found the source of it, it's a "makezine" project.
Being so it's also a real screwup.
There's a bunch of people telling it would work but as you just found out it can't work with what's offered there.
Your code is as far as i can see a direct copy of that what's on that site.

So i googled some more and found this (click!).
I guess that should help you.

Hello guys. So it turned out that I had installed library Date Time.
I installed the library and corrected code as you said, but there is again a mistake this time DateTime.cpp

Error message is:

C:\Program Files\Arduino\libraries\DateTime\DateTime.cpp: In member function ‘void DateTimeClass::setTime(time_t)’:
C:\Program Files\Arduino\libraries\DateTime\DateTime.cpp:28: error: ‘millis’ was not declared in this scope
C:\Program Files\Arduino\libraries\DateTime\DateTime.cpp: In member function ‘time_t DateTimeClass::now()’:
C:\Program Files\Arduino\libraries\DateTime\DateTime.cpp:43: error: ‘millis’ was not declared in this scope

DateTime.cpp is:

  DateTime.cpp - Arduino Date and Time library
  Copyright (c) Michael Margolis.  All right reserved.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of

extern "C" {
  // AVR LibC Includes
//#include <string.h> // for memset
#include "DateTime.h"
#include <wiring.h>

//extern unsigned long _time;

#define LEAP_YEAR(_year) ((_year%4)==0)
static  byte monthDays[]={31,28,31,30,31,30,31,31,30,31,30,31};

// private methods

void DateTimeClass::setTime(time_t time)
    // set the system time to the given time value (as seconds since Jan 1 1970)
    this->sysTime = time;  
        [b]this->prevMillis = millis();[/b]  28 row

//* DateTime Public Methods

   this->status = dtStatusNotSet;

time_t DateTimeClass::now()
  [b]while( millis() - prevMillis >= 1000){[/b] 43 row
    this->prevMillis += 1000;
  return sysTime;

void DateTimeClass::sync(time_t time) 
   //status.isSynced = true;   // this will be set back to false if the clock resets 
   //status.isSet = true; // if this is true and isSynced is false then clock was reset using EEPROM -- TODO
   this->status = dtStatusSync;

boolean DateTimeClass::available()
// refresh time components if clock is set (even if not synced), just return false if not set
   if(this->status != dtStatusNotSet) { 
      this->now(); // refresh sysTime   
      this->localTime(&this->sysTime,&Second,&Minute,&Hour,&Day,&DayofWeek,&Month,&Year)  ;     
          return true;
      return false;
void DateTimeClass::localTime(time_t *timep,byte *psec,byte *pmin,byte *phour,byte *pday,byte *pwday,byte *pmonth,byte *pyear) {
// convert the given time_t to time components
// this is a more compact version of the C library localtime function

  time_t long epoch=*timep;
  byte year;
  byte month, monthLength;
  unsigned long days;
  epoch/=60; // now it is minutes
  epoch/=60; // now it is hours
  epoch/=24; // now it is days
  while((unsigned)(days += (LEAP_YEAR(year) ? 366 : 365)) <= epoch) {
  *pyear=year; // *pyear is returned as years from 1900
  days -= LEAP_YEAR(year) ? 366 : 365;
  epoch -= days; // now it is days in this year, starting at 0
  //*pdayofyear=epoch;  // days since jan 1 this year
  for (month=0; month<12; month++) {
    if (month==1) { // february
      if (LEAP_YEAR(year)) {
      } else {
    } else {
      monthLength = monthDays[month];
    if (epoch>=monthLength) {
    } else {
  *pmonth=month;  // jan is month 0
  *pday=epoch+1;  // day of month

time_t DateTimeClass::makeTime(byte sec, byte min, byte hour, byte day, byte month, int year ){
// converts time components to time_t 
// note year argument is full four digit year (or digits since 2000), i.e.1975, (year 8 is 2008)
   int i;
   time_t seconds;

   if(year < 69) 
      year+= 2000;
    // seconds from 1970 till 1 jan 00:00:00 this year
    seconds= (year-1970)*(60*60*24L*365);

    // add extra days for leap years
    for (i=1970; i<year; i++) {
        if (LEAP_YEAR(i)) {
            seconds+= 60*60*24L;
    // add days for this year
    for (i=0; i<month; i++) {
      if (i==1 && LEAP_YEAR(year)) { 
        seconds+= 60*60*24L*29;
      } else {
        seconds+= 60*60*24L*monthDays[i];

    seconds+= (day-1)*3600*24L;
    seconds+= hour*3600L;
    seconds+= min*60L;
    seconds+= sec;
    return seconds; 

// make one instance for DateTime class the user 
DateTimeClass DateTime = DateTimeClass() ;
#include <wiring.h>

Wiring? This is the Arduino forum! (That’s a hint)

Thank you very much guys.
Without your help I would not have done.
Greetings Victor.

To make this a little more clear for future users (because I just had this same problem):

First, you need to downloand and install the DateTime Library. The code is missing the <DateTime.h> tag if you pull your code from here:

It should read: #include <DateTime.h>

Next, the DateTime.cpp file is wrong, you need to open that in notepad and change the <wiring.h> tag/attribute to <arduino.h>

After making those two changes your code should compile correctly.