How to make a schedule in arduino?

Hello everybody,

I'm working on my graduation project and I really need your help please .. My project is about controlling irrigation system automatically using Soil Moisture Sensor, what I need to do now is saving the schedule of the irrigation system (meaning each time the sensor senses that the soil needs water, the valves will be turned on until the soil is has enough water) and when this happens I need it to be saved (what time the valves was ON and for how long)

So there are two questions, how can I save the data with the specific time and how can I use this schedule later in case the sensor went out of order ?

Please please help me :-[ :-[

If you need a specifik time and date stamp, you have no other options than go add an RTC module to your Arduino. This can run "forever" as it utilises a backup battery to keep track of time and date.

I would also advice you to get a memory card reader for your Arduino, as then you can write the time stamp into a file each time you had an event. That frees up any concern on memory space for storing these data over lengthy time.

Both these add-ons are available as ready made shields for Arduino, and libraries are available for the necessary functions to make use of them within the Arduino C environment. Both these shields are available at very low cost, around £1 on Ebay.

how can I save the data with the specific time and how can I use this schedule later in case the sensor went out of order ?

As suggested, an RTC will give you accurate times. Save the times and actions taken to an SD card, or EEPROM if data volumes and frequencies are low, and read them back when needed. Keeping 24 hours data would seem to be all that is needed.

How are you going to know that the sensor is out of order ?

do you think I need a memory card ? because I want to save the schedule of two days only, why? because first, Day 1 schedule will be saved, then Day 2 has started, if at any time in day 2 the sensor went out of order then schedule of Day 1 will be used, but if the sensor was good then its schedule will be saved to be used as a backup for Day 3 when Day 3 is started, then schedule of Day 1 will be deleted and start saving schedule of Day 3, I hope you got what I mean

I was asking about the libraries used for this purpose, cuz the coding is a bit difficult for me

How are you going to know that the sensor is out of order ?

that will be by using 2 sensors and comparing their readings, if they were different with an unacceptable amount, then we know for sure that one of them has an error or damaged (out of order) and then we go to plan B which is the the saved schedule for the previous day until the sensor is fixed or replaced.

So can you guys help me with the code ?

You can save the schedule in EEPROM, and it will survive re-boot. You probably don't need an SD card.

You can save the schedule in EEPROM, and it will survive re-boot. You probably don't need an SD card.

that's in the Arduino, right? I don't need to buy anything I mean .... but how please

With your latest information, you do not need an SD card with reader.

Maybe you could use Arduinos build in counter, that counts the number of milliseconds from power on. This value is of type unsigned long integer and will run over the edge in something like 50 days, where it starts over from 0.

As long as you know the start time of your Arduino project application, you can always calculate the exact time a recorded event happened, by recording the value of milliseconds.

Then you are back to basis with no need for hardware or library updates. Have a look on the function millis() in the reference section.

If you want to keep track of time and days across a reboot, you will need an RTC.

We are not here to do your homework. http://arduino.cc/en/Reference/EEPROM

You need to show us what you have and we are glad to provide assistance.

As long as you know the start time of your Arduino project application, you can always calculate the exact time a recorded event happened, by recording the value of milliseconds.

I think counting milliseconds might be complicated, especially that It's difficult to know the start time of the project

They make an amazing thing called a “variable”:

unsigned long starttime = millis();

If you want to keep the arduino running, and not worry about reboots, there is a time library that uses the internal millis() clock, but the supplied resonator on the Uno is not very accurate.

A rtc can be had for less that 6 bucks... Way less headache...

For EEPROM, look at the EEPROM Write Anything library. With RTC, you only get seconds - if you need mS, you will to track them in between time updates from the RTC.

If you want to keep the arduino running, and not worry about reboots, there is a time library that uses the internal millis() clock, but the supplied resonator on the Uno is not very accurate.

I haven't used this library before, but I will check it .. Thank you

Qdeathstar: A rtc can be had for less that 6 bucks... Way less headache...

I also haven't used RTC before, is it easy ? because if not, I'm afraid I don't have much time for the deadline of my graduation project. Thanks

CrossRoads: For EEPROM, look at the EEPROM Write Anything library. With RTC, you only get seconds - if you need mS, you will to track them in between time updates from the RTC.

I don't need it to be in milliseconds, it's enough to know the time in seconds or even in minutes, like turn the valve ON at 11.30 AM then turn it OFF at 11.50 AM it won't be that different if it was turned OFF at 11.51 AM. Thanks

Lamya: So can you guys help me with the code ?

I can move this post to the Gigs and Collaborations part of the forum if you want.

I love having an RTC, but for a beginner project, the onboard timer is simpler. The Arduino (at least the Uno R3) onboard timer is accurate enough to manage watering plants (by a generous margin). Yes, you will lose track of time if power is lost. But it is just an educational project. You could mention the limitation and suggest an RTC as a future upgrade. If you use an RTC you will have to learn how to manage libraries for it, and also possibly the time library.

So if you just want to get it done fast, use the millis() function. You just have to do the math, using 1000 ms = 1 second, 60 seconds = 1 hour etc. etc.
The timing stuff is well documented in the example code and the programming reference.

Unless I misunderstand, your “schedule” can be saved in EEPROM as suggested. To keep the time, you will have to keep the system running. Think about battery backup. If you do keep it running, you won’t need to use EEPROM. So that would simplify things as well.

Again, all in the cause of keeping things simple.

I can move this post to the Gigs and Collaborations part of the forum if you want.

I'm sorry but I'm new to the Arduino website and I don't know what does the Gigs and Collaborations part do, but of course, if you know that they can help me, then please move the post there ... Thanks a lot

Unless I misunderstand, your "schedule" can be saved in EEPROM as suggested. To keep the time, you will have to keep the system running. Think about battery backup. If you do keep it running, you won't need to use EEPROM. So that would simplify things as well.

yes, I am searching now about the EEPROM and how to use it, because I think it's the best. but I still don't know how can I save the time exactly and most important how to use the schedule later when the sensor is out of order. and you mentioned a very important point, which is the battary. The system should be working 24/7, how can I do that? what do you recommend ? Thanks a lot

I was asking about the libraries used for this purpose, cuz the coding is a bit difficult for me

...

So can you guys help me with the code ?

If you are asking people to sit down and write your code from scratch, then offering to pay them is the acceptable way to go.

Alternatively, you try writing, and post questions if you have issues. There are lots of pages about programming on the Internet. You could start with some of the examples that come with the IDE.

oh, no I'm not asking to write the code for me, I just need suggestions and ideas about libraries that can help me best in my project ... I want to write it myself, but thanks anyway.