using arduino at the end of each month

Hello everyone, in my project i need to use a sensor connected to my arduino to get readings at the end of each month, in other words after 30 day for exemple, but i have no idea how to do this ( making arduino wait untill 30 days are gone ) :confused:
can anyone help me with the code i need to use ? is it the timer ? or there is already a library and a code ... I don't know from where to start. any kind of help will be appreciated, thank you everyone !!

Get a real time clock (RTC). When the month changes it's the end of the month?

Oh really @Ardunaut? That handles the first month, and you have to boot your Arduino at midnight on the 1st to begin with! What do you do for subsequent months (especially as months have different numbers of days in them)? :slight_smile:

dannable:
Get a real time clock (RTC). When the month changes it's the end of the month?

Yes.

thank you guys !! the millis() works great ! :slight_smile:
what is exactly a real time clock ? how can i use it ?

Chad21:
what is exactly a real time clock ? how can i use it ?

Is google not working today?

Chad21:
thank you guys !! the millis() works great ! :slight_smile:

How do you know that? You first posted today. 2 days haven't even gone by... :slight_smile: But seriously, don't forget to make previousMillis an unsigned long. If not, you will have rollover trouble in about 22 days.

Chad21:
what is exactly a real time clock ? how can i use it ?

I think the more interesting question here is: What is a clock, that is not real-time?

Is it a clock whose batteries have run down? In which case, could it even be called a clock?

Still, Googling for "Arduino clock" seems to return over a million hits, including advertisements for things you might find interesting.

aarg:
Oh really @Ardunaut? That handles the first month, and you have to boot your Arduino at midnight on the 1st to begin with!

Simple solution. Set the RTC for one day in advance so when it says 1 June it is really 31 May

I don't think millis() would be accurate enough to keep in step with the calendar over such long times

...R

Chad21:
i need to use a sensor connected to my arduino to get readings at the end of each month, in other words after 30 day for exemple,

You need to clarify, do you really mean "30 days" or do you mean "a calendar month"?

How accurate does it need to be? If you mean "roughly every 30 days" then using the internal timer is probably adequate.

Even better idea than in Reply #10

Set the RTC to the correct time.
Read the date and add 1 day to it. If that gives the 1st of the month you know you are now at the last day of the month.

...R

Rather than setting the clock to a false date (which could lead to trouble later), you could get at the last day of the month using a function, like so:

int days_in_month (int y, int m) {
  // Fourth, eleventh, ninth, and sixth,
  // thirty days to each we fix.  
  if ((m==4)||(m==11)||(m==9)||(m==6)) return 30;  
  // Every other, thirty-one,
  // except the second month alone,
  if (m!=2) return 31;
  // which hath twenty-eight, in fine,
  // till leap-year give it twenty-nine.
  if ((y%400)==0) return 29; // leap year
  if ((y%100)==0) return 28; // not a leap year
  if ((y%4)==0)   return 29; // leap year
  return 28; // not a leap year  
}

odometer:
Rather than setting the clock to a false date (which could lead to trouble later), you could get at the last day of the month using a function, like so:

Been there, tried that sort of thing. See Reply #12 for a much simpler solution.

...R

thank you guys for the help, i really apreciate it !!!!!

in my project Im using a shield GSM/GPRS can't i for exemple get the the real time using it somehow ?

i had to be more clear im sorry, i want to get the readings at a specific dates, like 30/5/2015, 30/6/2015, 30/7/2015 ...

so if i can get the arduino to know the real time instead of making it count 30 days ( using millis ) it would be much better for two reasons :
If for exemple my project start running today, then after 2 days he will get the readings.
And if for exemple i set it to start counting the 1/06/2015 but at 15/06/2015 the power went down for 1 day and start working again, then he will not have to start counting from the begining

I hope i made myslef clear and im sorry for my english :confused:

Which chip is the GSM shield based upon? Most that I know of have a built in clock but it's not fantastically accurate over a year.

Chad21:
i had to be more clear im sorry, i want to get the readings at a specific dates, like 30/5/2015, 30/6/2015, 30/7/2015 ...

...
I hope i made myslef clear and im sorry for my english :confused:

That is not at all clear. You know that February has only 28 days, right? So what do you really want? Last day on every month? What time on that day? Do you want it at midnight at the first second of that day? Noon? The last second before midnight?

aarg:
That is not at all clear. You know that February has only 28 days, right? So what do you really want? Last day on every month? What time on that day? Do you want it at midnight at the first second of that day? Noon? The last second before midnight?

yeah right ! i forgot about that !! Well, so let it be day 28 of each month then if its going to be easier, else, the last day of every month is a good idea too ! for the time exactly, at 00h10min00s (but it's not really important when exactly, it could be anytime on that day )

Well, so let it be day 28 of each month then if its going to be easier, else, the last day of every month is a good idea too !

Why not make it the first? Then, it doesn't matter how many days in the month.

PaulS:
Why not make it the first? Then, it doesn't matter how many days in the month.

good idea too, no problem on that one !
but all i need know is how to make arduino know what date/time it is without using an external device like RTC :confused:

Without using an external device it will be nearly impossible...

There are some cheap RTC on ebay for less than 2$, the DS3231 for example is in my opinion the best you can get for this price. It's very accurate and you could even put your arduino to sleep and make the DS3231 wake up your arduino every first day of months at 00h10 if you wish. Libraries for this RTC are available and easy to use.