What we’ve used

Wiring

Wiring Diagram

Sketching

I wanted to make arduino water my plants on alternate days, so we had to add a little function‘dayOfYear’ which will tell us (guess what?) the day of the year it is. Example: February 1st is the 32nd day of the year, and our function will return ’32’.

Maybe there was a better solution, or it was already implemented, but this way was faster for our purpose.

If the day number it’s even and the time correspond to what I’ve set, it will close the relay (and the valve will open).

We’ve used the RTClib (with the little edit I mentioned about ‘dayOfYear’) to control and read the RTC.

The Sketch

C

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

//

//Sketch for a little (stupid) plants irrigator

//Baldarn and Edo

//http://hack.lenotta.com

//

#include <Wire.h>

#include "RTClib.h"

RTC_DS1307 RTC;

intrelay=8;

voidsetup(){

//Initialize the serial port, wire library and RTC module

Serial.begin(9600);

Wire.begin();

RTC.begin();

pinMode(relay,OUTPUT);

digitalWrite(relay,HIGH);

//IF YOU USE RTC FOR THE FIRST TIME: If we remove the comment from the following line, we will set up the module time and date with the computer one

//RTC.adjust(DateTime(__DATE__, __TIME__));

}

voidloop(){

DateTime now=RTC.now();

//We print the day

Serial.print(now.day(),DEC);

Serial.print('/');

//We print the month

Serial.print(now.month(),DEC);

Serial.print('/');

//We print the year

Serial.print(now.year(),DEC);

Serial.print(' ');

//We print the hour

Serial.print(now.hour(),DEC);

Serial.print(':');

//We print the minutes

Serial.print(now.minute(),DEC);

Serial.print(':');

//We print the seconds

Serial.print(now.second(),DEC);

Serial.println();

//We check the time and sent through the serial port every 3s

if(now.dayOfYear()%2==0){

if(now.hour()==20){

if(now.minute()==54){

digitalWrite(relay,LOW);

}

else{

digitalWrite(relay,HIGH);

}

}

}

//Serial.println(digitalRead(relay));

//Serial.println();

delay(3000);

}

The Function We Added

We have modified the class DateTime in RTClib.h as follow:

C

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

//

//Baldarn and Edo

//http://hack.lenotta.com

//

classDateTime{

public:

DateTime(uint32_tt=0);

DateTime(uint16_t year,uint8_t month,uint8_t day,

uint8_t hour=0,uint8_t min=0,uint8_t sec=0);

DateTime(constchar*date,constchar*time);

uint16_t year()const{return2000+yOff;}

uint8_t month()const{returnm;}

uint8_t day()const{returnd;}

uint8_t hour()const{returnhh;}

uint8_t minute()const{returnmm;}

uint8_t second()const{returnss;}

uint8_t dayOfWeek()const;

//This is the function to calculate which day of the year it is:

uint8_t dayOfYear()const;

// 32-bit times as seconds since 1/1/2000

longsecondstime()const;

// 32-bit times as seconds since 1/1/1970

uint32_t unixtime(void)const;

protected:

uint8_t yOff,m,d,hh,mm,ss;

};

and added the following function to RTClib.cpp:

C

1

2

3

4

5

6

7

8

9

10

11

12

13

//

//Baldarn and Edo

//http://hack.lenotta.com

//

uint8_t DateTime::dayOfYear()const{

uint16_t days=d;

for(uint8_ti=1;i<m;++i)

days+=pgm_read_byte(daysInMonth+i-1);

if(m>2&&yOff%4==0)

++days;

returndays;

}

Possible Developments

As you’ve seen this is a really stupid implementation, but it was on our purpose to make it stupid and not including any sort of display.
In fact, the main project is a little bit bigger than just a programmable Garduino (as someone calls it).

What we have in mind is to make the Garduino just an interpreter for our garden architect “Mr Rasp Gardner”, a raspberry pi which will communicate with the arduino using the NRF24l01+ module we tested here. As you can imagine, this drive us to an intelligent gardener, a nice web interface, statistics and much (much) more.

One of the first thing to implement, apart wireless communication, could be a simple hygrometer which will tell us if the plants have actually been watered. Maybe next week.

very interesting hack
yet it seems it calculates wrong. It is now december 8 and it tells me it is day 86.
Compiles properly but the calculation somehow seems wrong 🙂 I will do some more digging myself but would appreciate some pointers

I already discovered where the mistake is: 342-86=256 Hmmm seems only the low byte is returned,
Not surprising as it is defined as uint8_t
dayOfYear should be defined as uint_16 in both the .h and the .cpp file

Hi, thank you for pointing the error out. This blog goes on thanks also to the help of people like you. Can you share the edits you’ve made to make the code behave as supposed so I can update the post? Thank you.

Super awesome project! I’m working on a similar system for an urban farm in Inglewood, CA where residents are building a new food system. Here’s a quick video of my first prototype: https://www.youtube.com/watch?v=ZSZiMvsUfyo

I came across your project while researching the NRF24L01. Are you interested in collaborating, and/or is it ok w/ you if I incorporate aspects of this project in my next prototype (which will hopefully be installed and utilized in the urban farm)? You can reach me at the e-mail address provided. Thanks!

Hi!
Glad to know our work was useful and that you are spreading the word!
I don’t have the time follow other projects at the moment, but keep us informed with future developments!
Feel free to use our work, it is released under Creative Commons CC-BY-SA

Hi Mahmood,
did you include all the libraries, the class and functions we added?

Note: I’ve edited a bit your comment, to make understandable to all the readers. Please, for further comments, use a clear, plain english and avoid abbreviations. It helps a lot understanding your question, and save my time (plus it makes me more prominent to answer). Thank you.

By continuing to use the site, or scrolling, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.