My project needs to measure distance every 15 minutes and write the result, together with a timestamp, to an SD card. To save power, it has to go to sleep in between the measurements and to wake up by an external interrupt provided by an RTC.
Problem: After about an hour working correctly (and thus writing about 4 measurements correctly to the SD card), the UNO seems to stay in sleep mode and doesn't do anything anymore.
Setup:
UNO
9V battery
mini SD breakout
RTC DS3231
DHT11
UltraSonic US-015
You should not use Serial.print inside a ISR. An ISR should be fast, and do very little. In order to see if this is the cause of your issue, remove the serial.println.
I do not know much about RTC and setting alarms. But what happens if you add minute and time_interval. Perhaps you should print the result of that. If minute(t) is 59 and you add 10 what is the result. And what does that value translate to in the setting of the alarm.
When you just add the minutes with the time-interval, it will happen that you come to a sum of more than 59, while there are only 60 minutes in an hour. The moment that the time is e.g. 00:68:00 will never happen.
Thats why I added an if-statement that subtracts 60 from the sum of minute(t) and time_interval when that sum is more than 59. Result: 00:68:00 becomes 00:08:00 and the interrupt will be fired at the correct time.
Jedidja:
I noticed that this doesn't happen when I use a time-interval of 2 minutes instead of 15.
Jedidja:
When you just add the minutes with the time-interval, it will happen that you come to a sum of more than 59, while there are only 60 minutes in an hour. The moment that the time is e.g. 00:68:00 will never happen.
Thats why I added an if-statement that subtracts 60 from the sum of minute(t) and time_interval when that sum is more than 59. Result: 00:68:00 becomes 00:08:00 and the interrupt will be fired at the correct time.
Hello, sorry for waking up the old thread, but I am having exactly the same problem - Arduino not waking up when "time_interval" is set to more than 10 minutes. Does one or two measurements and then it stops.
How should I modify the code:
const int time_interval =30;// Sets the wakeup intervall in minutes
void setup() {
RTC.setAlarm(ALM1_MATCH_MINUTES , 0, minute(t)+time_interval, 0, 0);
// clear the alarm flag
RTC.alarm(ALARM_1);
}
.......
void SleepNow(){
//Set New Alarm
RTC.setAlarm(ALM1_MATCH_MINUTES , 0, minute(t)+time_interval, 0, 0);
// clear the alarm flag
RTC.alarm(ALARM_1);
}