It’s a burning summer in Florence and I needed a solution to watering my little plants I have around the house.
Of course I had a look at some shops for a ready solution, but where is the joy of experimenting with an arduino?
First thing to do in this case is to know what you want, and where your project could drive you. It’s nice to fly high with ideas, but to make them affordable you have to take off first.
So here we are with our project/tutorial: a time programmed irrigator which will water my plants for 1 minute, once a day, on alternate days.
The whole thing costs around 25$ (we’ve bought almost everything from china).
What we’ve used
- – an Arduino (we used a Nano 328)
- – an RTC (Real Time Clock)
- – Water Control NC Solenoid Valve
- – a relay board
Wiring
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
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; int relay = 8; void setup () { //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__)); } void loop () { 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:
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 // class DateTime { public: DateTime (uint32_t t =0); DateTime (uint16_t year, uint8_t month, uint8_t day, uint8_t hour =0, uint8_t min =0, uint8_t sec =0); DateTime (const char* date, const char* time); uint16_t year() const { return 2000 + yOff; } uint8_t month() const { return m; } uint8_t day() const { return d; } uint8_t hour() const { return hh; } uint8_t minute() const { return mm; } uint8_t second() const { return ss; } 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 long secondstime() 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:
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_t i = 1; i < m; ++i) days += pgm_read_byte(daysInMonth + i - 1); if (m > 2 && yOff % 4 == 0) ++days; return days; } |
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.
Hello and sorry for my bad english 🙁 .I am a beginner in arduino and i want to make a aquarium controlled with arduino.For this i write to you.Can you help me?I want to switch on and off the aquarium lights through arduino nano,rtc ds3231 and 8 channel relay(using 2 relays one for lights and second for air pump).Can you write the code for me on my email?thanks 🙂
Sorry, I don’t do commissions on Arduino.
hello
i just want to know how the code changes if i want to water the plants on daily basis once at a particular time period ?
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
If I make a printout of the cumulating days, I get the following result:
39
67
98
128
159
189
220
251
281
312
342
86
So the accumulation is right, but somehow the return value is wrong
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.
define the dayOfYear as uint16_t rather than uint8_t
If you chech my values it is clear the MSB wascut off as 342-86=256
Hi!
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
Done! This is the link:
http://www.opiron.com/regador-de-plantas-diy-basado-en-arduino/1983
Congrats for the project!
Hi,
This is an awesome project! We will post a backlink to your project in our blog if you agree, at http://www.opiron.com/blog
Regards,
Antón
@Anton sure! Thank you for sharing.
Hi Edoardo …. nice project and smart …. but I have a problem. I would appreciate if you could help me, please.
When I upload the code, the compiler says “class datetime’ has no member named”. Can you point me to a solution?
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.
Hi Edoardo I am soo sorry for my English Language ..I’ll do it certainly
I already have librarie for RTC but I dont know how I can add the class and functions .. I was try Writing your the class and function to notepad and moved to my libarie folder but Does not work ..
sorry again I am new in this area but I want learn ….
thank you