Date and time based watering system using an Arduino and a RTC module
HTML-код
- Опубликовано: 26 авг 2024
- In this video I show you how to make an automated watering system based on a real time clock (RTC) module.
You can expand this project to control anything based on date/time, and you can add more switches, relays, etc.
For example, you can turn on and off your heater, lights, air purifier at a certain time of the day with this circuit.
Source code and wiring diagram: curiousscienti...
If the video was useful, please consider subscribing to my channel.
You can buy the parts and help me at the same time by using my affiliate links: curiousscienti...
An excellent video and useful too. Many people upload the video but they hide key things like software. But you not only showed it in your presentation; you explained it nicely. Many many thanks for a nice video. The time spent on it was fruitful.
Thanks! You would enjoy my other videos too then, because I always try to make all details clear and I always explain the software I wrote line by line. Cheers!
Thanks very much for such an in-depth explanation & guide to using an RTC to control the watering system using an Arduino. I'm currently working on a similar project and had been looking for a way to do exactly what you have done. You are a life saver!
Glad that my video helped you! Cheers!
Thank you so much for making such an in-depth guide and tutorial! I'm a student designer and unfortunately I don't really know my way around electronics, so I'm really thankful that there are kind people like you who make stuff like this. I love the concept of arduino and stuff but I guess I just don't have much of an engineering mindset to learn more than the basics lol. I'm currently working through configuring this to work for a planter I'm making as a school project.
Just saw a lot of comments only asking for help, so I just wanted to leave one as thanks :)
Thank you for your nice comment! I am really happy to see that my tutorial is helpful for someone. If you get stuck, just leave a comment or message me. Have a great day!
@@CuriousScientist thank you! I hope you have a great day too :)
Me too rn lol.
Hi @Curious Scientist,
Thank you so much for doing this video, the explanation was sensational! Congratulations.
Sincerely, Tales.
Hi Tales! Thank you very much for the kind words! I am glad that you found it helpful!
Hi, thanks for your explanation and code. I’m a beginner and this info is real educational. Only one problem with the screen. Every second on clock makes screen blink. Strange no? Can you imagine what going on?
Hi and you're welcome! As you can see it on the video, I don't have this issue. I recommend you to disable all serial communication. You can try removing the section that I highlighted at 14:35.
Man this is stupidly useful.
Glad to hear!
Looks a very good implementation. Better to add the circuit diagram for much more clear understanding
Thanks! How about visiting my website before complaining? I have the circuit schematics there.
@@CuriousScientist thanks. I will surely view your site. I am sorry if you felt that I am complaining. I just thought of putting it as a suggestion.
No worries, you don't need to say sorry. I just have noticed that a lot of people aren't watching my videos carefully enough and they aren't reading the description. And because of this they ask questions or make comments, however all the information they are asking for is already provided.
Hi! Thank you, but I do have a question, on the 12v power supply.. how many amps? Thank you
Hi! It depends on the pump. Generally, they are 500 mA. So it's a good idea to use a 12 V, 1 A power supply.
Very clear instructions ,, if i want to run the pump for every 10 min from 6 to 6 , every day , what will be change in the code of interval pl let me know thanks ....
Thanks! You need to trigger the pump with the desired period. Just modify the code I published. I hope you don't expect me to write the code for you.
@@CuriousScientist i will do my trial , if needed i will take help from you... thanks for reply...
So the date and time of RTC set automatically from computer date and time?
Yes, when you upload the code to the Arduino, the time of the computer will be transferred to it and the RTC module will use that time.
@@CuriousScientist thank you very much for your fast and kind reply
I will try it update you with my test.
Your way of explaining is very great and I will subscribe to your great channel
Thank you very much! Your subscription is very appreciated! I am glad that my way of explanation helped you to better understand this topic.
Great video, had a lot of useful information. Thank you.
I'm having an issue with the LCD display, for some reason I don't see any information on the screen only the backlight is ON. What could have caused it? Any guess or suggestions to look into the code.
I understand if you are done answering such stupid questions. Once again thank you for the video.
Hi and thanks! It's very typical that the contrast is not adjusted properly. Try adjusting it using the potentiometer on the LCD.
Can you post the wiring diagram, please! Thank you!
Hi! I cannot post a drawing right now, but since you are not the first, I will start including them in my future videos. I thought it is easy to reverse engineer it from the video and the discussion about the code, but seems like it is not always the case.
So, I write it down:
Both the LCD and the RTC are I2C devices, so, their pins are shared: VCC and GND is obvious, I think; SDA: A4, SCL: A5.
The relay's GND and VCC is obvious, the IN is also obvious, it is in the code and it is called 'relaypin' (which is D2). The relay is open by default and it will close the circuit when it is triggered by the Arduino.
Switch: Also in the code: D3 pin. The D3 pin is directly connected to the GND by a 1k (pull-down) resistor to avoid floating. The other side of the switch goes to +5V.
@@CuriousScientist Thanks a lot!!!
@@Nicu.zaharia963 You are welcome, I am glad that I could help!
Hi, well explained video. Only one doubt, is it possible to put multiple cycle for one day?. And if it could be controlled using a selection switch to alter timing as desired, it would have be very helpful.
Hi! Thanks! Sure, it is possible.
@@CuriousScientist Can you please convey how, I am total fresher in Arduino. A suitable link/ video explaining this would be helpful.
Hi! Just search for similar projects. I am pretty sure that someone already made it and published it somewhere. I don't have any resources as a reference. Also, you can just use my video. You can add more conditions that should trigger an action. But maybe for a total beginner, this is actually a too difficult project. You should start with something simpler.
what modifications will I need if I'm using a Uno?
Everything is the same. They are practically the same microcontroller, but with different form factor.
Hi, I am creating a code for a irrigation system based on you code, thank u. I see you declared the switch variable "shitchstate" as an int, yet when you use the digital read function it returns high, how come it did'nt crash?
Hi! Because high is also interpreted as 1, and low as 0. You can use the digitalWrite in the same fashion: either you use 1 or high, both will work.
@@CuriousScientist Thanks! Very useful tool. It will irrigate a large area of mushroom production.
@@diegofroesesouza2273 You are welcome! I wish you a nice yield!
what if I remove the switch and want it start watering in 9 AM for 6 second also each hour will start again for 7 times what is the code please
You just have to modify the code that I supplied according to your own requirements. It is relatively simple. I am sorry, but I will not write a code for you for free.
Excellent project
But can watering system will work
If we want , watering system to run
after two , three months
Thanks. Yes, it is possible. My watering system was running for half a year without any issues. I used it to water my chili plant in my office at work.
@@CuriousScientist means can I get watering after two month of gap with the help of rtc module
Sure, you just trigger the pump using the number of months as a condition. Or you keep track of the elapsed days and trigger after every 40 days. The possibilities are endless.
@@CuriousScientist Thank you Sir
Can you please give code of it to me
Sure, you can hire me for writing the code. But of course not for free.
can i just use the relay and the RTC ?, cos i really dont wanna mess with the LCD, cos it'll be outside exposed to the elements
Yes, absolutely! Just comment out the lcd related code.
@@CuriousScientist nice will try ur code soon, but i wonder, if i just do a loop for 23 hour, can it work as well as an RTC tho
@@yudhobaskoro8033 you can eliminate the RTC entirely and just use the millis() for counting. Keep in mind that the millis() will overflow after a certain value. I don't remember exactly but it's several weeks.
Very useful video! Thank you. I'm working on a program that will work on our product for our research defense, we didn't hire a programmer since its very expensive for us students to pay them. And currently, I'm having troubles with my program, is it possible that instead of turning the watering system off and on, but I will apply it to an LED that will fade at a specific time? In simple words, scheduling the LED to fade in and out at a specific time using RTC Module. I'm not very much of an expert when it comes to coding, can you recommend me examples that I can study with? I hope you can help me with this. And thank you for this video!
Hi! Sure it is possible, you just have to switch the LED instead of the relay. However, if you want it to fade in and out that's a different story. You then need to drive the LED with PWM. When you want to fade in, you ramp up the PWM, and when you want to fade out, you ramp down the PWM. For resources, the whole internet is there, just use Google.
can i change the pump with solenoid valve? would it change power needs?
Hi! You can do that, they draw roughly the same current (~300-500 mA). But ultimately, it all depends on the relay you choose and the power you switch with the relay. If you change the input voltage, you might need to reconsider the whole circuit. In this demo I was relying on the power regulator on the Arduino, so I could use the 12 V input to power both the controlling electronics and the motor. I just used a 12 V, 2 A adapter if I remember correctly. However, if you would go above 12 V, this would not work because the maximum allowed input voltage on the VIN pin on the Arduino is 12 V. I noticed that many people try to power the electronics from their Arduino board so I want to emphasize, that the motor is NOT powered via the Arduino. The Arduino only switches a relay which then allows the pump to use the power from the 12 V rail and pump the water.
on arduino code u use rtc_ds1307 but u recomend to buy ds3231 on youtube description
the question is would it work with the same code that u give in website?
if i use ds3231
From coding perspective, they are the same. You can use whichever is available for you! :)
thanks for helping bro
hi great tutorial! canthis also be edited easily for day of the week?
Hi and thanks! Yes, it is easy.
Hi @Curious Scientist,
Do you have any idea if it is possible to add a temperature sensor and if the temperature is below 50 fahrenheit, for example, it blocks the water outlet?
Sincerely, Tales.
Hi! Yes, search for a so called "solenoid valve". You can switch them in the same fashion as you are switching the pump in this project: you put a relay between the microcontroller and the valve and switch the valve using the relay. You can add a simple thermometer such as the DS18B20 (I have videos discussing this particular thermometer, search it on my channel) and just write a single function which reads the thermometer and decides whether it should close the valve or not. It is just a few extra lines of code.
@@CuriousScientist
OK, solenoid valve, I'm going to research this. On the temperature sensor, I have a DHT11, which measures temperature and humidity. I don't have much knowledge in c ++, how would the code look? I thought something like this, but i don't know if this works:
if (temperature)
@@TalesTelles Hi! The code is almost ok. It is good on the algorithm level, but the if condition has to be inside the parenthesis: if(temperature < 50). I guess, temperature is a variable that you use to store the temperature read by the DHT11. Make sure that you will use the proper units (Celsius, Fahrenheit...etc). Also, put an else after the if(). Why? Because if the temperature temporarily falls below 50, you will be locked in the "watering = false" state forever. So, the code would continue as else{watering = true;}. This will make sure that as long as the temperature is above 50, the watering stays enabled.
BTW, your English is pretty good, don't worry! Greetings from Sweden!
@@CuriousScientist OMG! Thank you so much! I will try this later and keep you updated.
@@CuriousScientist I just added the changes to the code, here is a print: prnt.sc/1050tt1
Unfortunately, I am without the arduino at the moment, so I will not be able to test = /
- 20 is the temperature in degrees celsius
ill try your code but, when the pump is after that the lcd goes blank? what should i do?
It should not turn off. Maybe you made a mistake somewhere. Do you power the pump with an individual power supply?
By the way, I am not a free support service, I cannot answer every single questions for free.
good
Thanks
Hi Curious Scientist. I have a question. How long can this stay continuously powered without a computer powering it, and how would I go about that? Thank you.
Hi! I used this exact circuit some years ago in my office to water my chillibplant and it was running from a wall adapter for roughly half a year.
Thank you!
What's the code without the lcd screen?
It is the same but without the lcd-relevant parts.
what RTClib did you use ? can i get the link
The default one that you can download in the Arduino IDE. Just search for the name of the module in the library manager.
how to add 2 times watering in a day? like int wateringhour = 9 am and 5 pm??
Hi! You just write two conditions which trigger the pump.
@@CuriousScientist like int watering = 9; int watering = 10 like this??
@@CuriousScientist you use ds3231 in actual but in code you use ds1370 rtc?
RTC should not matter too much as long as you get the same information out from it. Regarding the other questions, those are wrong. You declared the same variable twice just with different values.
Thank you
Which rtc module you used DS1307 or DS3231? I have DS3231 will the code work with ds3231 rtc module?
Watch the video more carefully...
@@CuriousScientist thank you so much its working🙏🏻 I am totally new in this field. This electronic field is very much interesting i am trying to learn new thing and c++ language is one of them. Thank😃🙏🏻
Thanks. I guess sometimes it worth, to actually watch the video. In this case, it was just 59 seconds into the video for the answer. ;)
Arduino is excellent tool for this approach to learn electronics and C/C++ languages to a certain extent by actually having fun. I hope you'll enjoy your journey.
What if i do not use a switch? I just only set thr time when to irrigate. Can u help me about the code?
Nothing should happen if you omit the switch. The switch is only used if you want to have a "forced" irrigation.
Bro, what library did u used to this code?
First of all, I am not your "bro". Second, I shared all the resources in my video and on my website. Take your time, watch the video and read my published material.
hii @curious scientist
i installed new battery to my rtc module refreshed the current time when i i power off my project the time reset to when it was complied
then i even changed my rtc module then too the problem continues
pls help me
Hi Kumar! In order to refresh the time in the RTC after you changed the battery, compile a fresh version of your code and upload it to the Arduino. The RTC always keeps the time compared to the time of the most recent upload of the Arduino code. So, just reupload your code and it should work. Check my code, there is a line like "if(!RTC.isrunning())"... Read the comments there how to do everything properly.
@@CuriousScientist yes I did this and the time refreshed but when I power off and again on my project the time doesn’t save and it starts from the default time
If you don't power off the RTC, it shouldn't happen. Are you sure that the battery is good?
@@CuriousScientist the I bought yesterday from an electronic shop and I checked the Voltage in multi meter it was 3.11 volt
And it’s my 3rd rtc module I bought for this project but the problem didn’t solve
hi can i use 220v pump instead of 12V
Hi! Yes, but make sure you choose a suitable relay. But I wouldn't risk using 220 V if it's not necessary.
@@CuriousScientist what relay module can i use
Whichever that fulfills the pump's and the microcontroller's parameters.
Hello again Curious Scientist. I have another question. If I want this to water my plant once a week, on Friday, how would I do that? I have minimal C++ coding experience, sorry.
Hi! The code or the real-time clock is not really aware of the calendar days, but only the date. So, somehow you have to tell the code the day when you upload it to the microcontroller. Then you know the day of uploading and the difference until a Friday. Then you just define a weekly period from the first occurring Friday and trigger the watering every week.
@@CuriousScientist Okay… so how would I go about that? I’m sorry, I know very little C++.
Sorry, but I won't write the code for you for free. I don't have the time and resources just to provide a ready made code.
@@CuriousScientist Sorry, but that’s not what I’m asking for. Just a place where I could find information on how to do that.
Oh. Google is your friend then. :)
Sir can u plz . make this type by using nodemcu esp8266 plz .. 🙏🙏🙏🙏🙏
Hi! You can use Arduino IDE for the above mentioned MCU, so this code should be more or less compatible with it.
@@CuriousScientist yes sir but company told us to use mcu only 😅 can u plz...help me in coding 🙏🙏
@@CuriousScientist how can I contact u
@@CuriousScientist actually we have to create smart lighting system which will turn on and off according to time and my 80% project is ready only that timing fiction is remaining plz..help sir 🙏🙏🙏
Sorry, but this is not a free technical support service.
Hello!! i have so many questions!, please how can i talk to you about in this project. i dont want my project to go on waste. please help me...
Hi! You can ask it here so others can also learn from the questions and the answers. You can also reach me privately through my website, but keep in mind that I am not a free support service.
Hello!! I just want to ask
What if i used arduino uno ? Same wirings ?
Can you help me ? This project is the same as mine, but the other feautres is that there is LED LIGHT connected to RTC module
Sample
When the time is at 8 am the punp will start and close after a seconds then when the time is at 7 pm the led light will turn on and the pump will turn on
Purplse of the led light: like you can see at fountains ? To see that tge watering system is activate
The wiring depends on you. Just check which are the i2C pins on the Uno. The switch and the relay pin actually depends on you, you can assign any pins.
Why would put the LED on the RTC? It does not make sense to me. Switch the LED from one of the Arduino's pin.
@@CuriousScientist no the LED im talking about, it is placed beside or within the sprinklers so that the light from big LED you can see the sprinklers are turn on if its night time
Ah, sorry I misunderstood it. So something like a floodlight. I recommend to use a separate relay for it, especially if you supply different voltage to it than to the pump. You still switch the relay with the Arduino, but a different one.
sir what if I set the code to just trigger the watering system once a week . how do I do it? thank you sir
Hi! You run a counter which is increased by 1 every 24 hrs. When its value is 6, you run the watering and reset the counter to 0. Simple!