Arduino pro mini power up

Yes i have seen this but with this code arduino wake up one time and then remains in sleep mode

Ok, so I don't have the SD card to had or the temp/humidity sensor. What I do have here is an UNO clone and a DS3231 (the ZS-042 board). I took the code from the website link I gave in #20 and stripped out all the temp/humidity and SD cards stuff, changed the alarm time to 1 minute and ended up with this code:

#include <avr/sleep.h>  // this AVR library contains the methods that controls the sleep modes
#define interruptPin 2  // Pin we are going to use to wake up the Arduino
#include <DS3232RTC.h>  // RTC Library https://github.com/JChristensen/DS3232RTC

// RTC Module global variables
const int time_interval = 1; // Sets the wakeup intervall in minutes

void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(interruptPin, INPUT_PULLUP);
  digitalWrite(LED_BUILTIN, HIGH);

  // initialize the alarms to known values, clear the alarm flags, clear the alarm interrupt flags
  RTC.setAlarm(ALM1_MATCH_DATE, 0, 0, 0, 1);
  RTC.setAlarm(ALM2_MATCH_DATE, 0, 0, 0, 1);
  RTC.alarm(ALARM_1);
  RTC.alarm(ALARM_2);
  RTC.alarmInterrupt(ALARM_1, false);
  RTC.alarmInterrupt(ALARM_2, false);
  RTC.squareWave(SQWAVE_NONE);
  /*
     Uncomment the block block to set the time on your RTC. Remember to comment it again
     otherwise you will set the time at everytime you upload the sketch
  */
  /* Begin block
    tmElements_t tm;
    tm.Hour = 00;               // set the RTC to an arbitrary time
    tm.Minute = 00;
    tm.Second = 00;
    tm.Day = 4;
    tm.Month = 2;
    tm.Year = 2018 - 1970;      // tmElements_t.Year is the offset from 1970
    RTC.write(tm);              // set the RTC from the tm structure
    Block end * */
  time_t t; //create a temporary time variable so we can set the time and read the time from the RTC
  t = RTC.get();
  RTC.setAlarm(ALM1_MATCH_MINUTES , 0, minute(t) + time_interval, 0, 0); // Setting alarm 1 to go off 5 minutes from now
  // clear the alarm flag
  RTC.alarm(ALARM_1);
  // configure the INT/SQW pin for "interrupt" operation (disable square wave output)
  RTC.squareWave(SQWAVE_NONE);
  // enable interrupt output for Alarm 1
  RTC.alarmInterrupt(ALARM_1, true);

  Serial.println("initialization done.");
}

void loop() {
  delay(5000);   //wait 5 seconds before going to sleep. In real senairio keep this as small as posible
  Going_To_Sleep();
}

void Going_To_Sleep() {
  sleep_enable();//Enabling sleep mode
  attachInterrupt(0, wakeUp, LOW);//attaching a interrupt to pin d2
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);//Setting the sleep mode, in our case full sleep
  digitalWrite(LED_BUILTIN, LOW); //turning LED off
  time_t t;// creates temp time variable
  t = RTC.get(); //gets current time from rtc
  Serial.println("Sleep  Time: " + String(hour(t)) + ":" + String(minute(t)) + ":" + String(second(t))); //prints time stamp on serial monitor
  delay(1000); //wait a second to allow the led to be turned off before going to sleep
  sleep_cpu();//activating sleep mode
  Serial.println("just woke up!");//next line of code executed after the interrupt
  digitalWrite(LED_BUILTIN, HIGH); //turning LED on
  t = RTC.get();
  Serial.println("WakeUp Time: " + String(hour(t)) + ":" + String(minute(t)) + ":" + String(second(t))); //Prints time stamp
  //Set New Alarm
  RTC.setAlarm(ALM1_MATCH_MINUTES , 0, minute(t) + time_interval, 0, 0);

  // clear the alarm flag
  RTC.alarm(ALARM_1);
}

void wakeUp() {
  Serial.println("Interrrupt Fired");//Print message to serial monitor
  sleep_disable();//Disable sleep mode
  detachInterrupt(0); //Removes the interrupt from pin 2;

}

The DS3231 is connected to my UNO GND, +5V, SCL, SDA & the SQW signal to pin 2.

Running the code and looking at the serial monitor, I get:

15:54:12.598 -> Sleep  Time: 0:1:36
15:54:35.842 -> Interrrupt Fired
15:54:35.842 -> just woke up!
15:54:35.882 -> WakeUp Time: 0:2:0
15:54:40.843 -> Sleep  Time: 0:2:5
15:55:35.857 -> Interrrupt Fired
15:55:35.857 -> just woke up!
15:55:35.897 -> WakeUp Time: 0:3:0
15:55:40.858 -> Sleep  Time: 0:3:5
15:56:35.874 -> Interrrupt Fired
15:56:35.874 -> just woke up!
15:56:35.874 -> WakeUp Time: 0:4:0
15:56:40.836 -> Sleep  Time: 0:4:5
15:57:35.851 -> Interrrupt Fired

My Arduino clone "appears" to be going through the motions of the sleep-wake-sleep cycle. It certainly seems to be responding to the 1 minute periodic Alarm/Interrupt signal from the DS3231.

I suggest you try something similar with your setup and strip out the temp/humidity sensor and SD card code to see what happens. Then add in the code for the sensor and check that your sleep-wake-sleep cycle is still working. Then add in the SD card code and check again.

I’ll try it and post the results. Thanks for all

good evening again. I managed and made it work but after 59 minutes the arduino does not wake up. what i'll try to do?

Ok, what 59 minutes are you referring to? Is it 59 minutes since the sketch started, or is it when the RTC time changes from 59 minutes back to 00 minutes?

I suspect that it may be the rollover from 59 minutes back to 00 minutes. Specifically this line of code in the Going_To_Sleep() function:

RTC.setAlarm(ALM1_MATCH_MINUTES , 0, minute(t) + time_interval, 0, 0);

When the alarm for the 59th minute is triggered, then the new minutes value gets computed as 59+1 - i.e. 60, which is not a correct number of minutes. The modulo % operator should help you out here. Try changing the line of code to:

RTC.setAlarm(ALM1_MATCH_MINUTES , 0, (minute(t) + time_interval) % 60, 0, 0);

I’ll try it later and post the results.. thanks again

I tried the change you suggested but now arduino don’t wake up from sleep mode

Strange. I just checked and the code I posted in #22 does indeed fail to wakeup after the RTC minutes changes from 59 to 00.

I modified the code from #22 with the change I suggested in #25 so it is like this:

#include <avr/sleep.h>  // this AVR library contains the methods that controls the sleep modes
#define interruptPin 2  // Pin we are going to use to wake up the Arduino
#include <DS3232RTC.h>  // RTC Library https://github.com/JChristensen/DS3232RTC

// RTC Module global variables
const int time_interval = 1; // Sets the wakeup intervall in minutes

void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(interruptPin, INPUT_PULLUP);
  digitalWrite(LED_BUILTIN, HIGH);

  // initialize the alarms to known values, clear the alarm flags, clear the alarm interrupt flags
  RTC.setAlarm(ALM1_MATCH_DATE, 0, 0, 0, 1);
  RTC.setAlarm(ALM2_MATCH_DATE, 0, 0, 0, 1);
  RTC.alarm(ALARM_1);
  RTC.alarm(ALARM_2);
  RTC.alarmInterrupt(ALARM_1, false);
  RTC.alarmInterrupt(ALARM_2, false);
  RTC.squareWave(SQWAVE_NONE);
  /*
     Uncomment the block block to set the time on your RTC. Remember to comment it again
     otherwise you will set the time at everytime you upload the sketch
  */
//  /* Begin block
    tmElements_t tm;
    tm.Hour = 00;               // set the RTC to an arbitrary time
    tm.Minute = 57;
    tm.Second = 00;
    tm.Day = 4;
    tm.Month = 2;
    tm.Year = 2018 - 1970;      // tmElements_t.Year is the offset from 1970
    RTC.write(tm);              // set the RTC from the tm structure
//    Block end * */
  time_t t; //create a temporary time variable so we can set the time and read the time from the RTC
  t = RTC.get();
  RTC.setAlarm(ALM1_MATCH_MINUTES , 0, minute(t) + time_interval, 0, 0); // Setting alarm 1 to go off 5 minutes from now
  // clear the alarm flag
  RTC.alarm(ALARM_1);
  // configure the INT/SQW pin for "interrupt" operation (disable square wave output)
  RTC.squareWave(SQWAVE_NONE);
  // enable interrupt output for Alarm 1
  RTC.alarmInterrupt(ALARM_1, true);

  Serial.println("RTC Time: " + String(hour(t)) + ":" + String(minute(t)) + ":" + String(second(t))); //prints time stamp on serial monitor
  Serial.println("initialization done.");
}

void loop() {
  delay(5000);   //wait 5 seconds before going to sleep. In real senairio keep this as small as posible
  Going_To_Sleep();
}

void Going_To_Sleep() {
  sleep_enable();//Enabling sleep mode
  attachInterrupt(0, wakeUp, LOW);//attaching a interrupt to pin d2
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);//Setting the sleep mode, in our case full sleep
  digitalWrite(LED_BUILTIN, LOW); //turning LED off
  time_t t;// creates temp time variable
  t = RTC.get(); //gets current time from rtc
  Serial.println("Sleep  Time: " + String(hour(t)) + ":" + String(minute(t)) + ":" + String(second(t))); //prints time stamp on serial monitor
  delay(1000); //wait a second to allow the led to be turned off before going to sleep
  sleep_cpu();//activating sleep mode
  Serial.println("just woke up!");//next line of code executed after the interrupt
  digitalWrite(LED_BUILTIN, HIGH); //turning LED on
  t = RTC.get();
  Serial.println("WakeUp Time: " + String(hour(t)) + ":" + String(minute(t)) + ":" + String(second(t))); //Prints time stamp
  //Set New Alarm
  RTC.setAlarm(ALM1_MATCH_MINUTES , 0, (minute(t) + time_interval) % 60, 0, 0);

  // clear the alarm flag
  RTC.alarm(ALARM_1);
}

void wakeUp() {
  Serial.println("Interrrupt Fired");//Print message to serial monitor
  sleep_disable();//Disable sleep mode
  detachInterrupt(0); //Removes the interrupt from pin 2;

}

It sets the time to 00:57:00 each time but correctly wakes up when the time rolls over from minute 59 to minute 00 as you can see from the serial monitor output:

16:45:25.403 -> RTC Time: 0:57:0
16:45:25.403 -> initialization done.
16:45:30.392 -> Sleep Time: 0:57:5
16:46:25.401 -> Interrrupt Fired
16:46:25.401 -> just woke up!
16:46:25.401 -> WakeUp Time: 0:58:0
16:46:30.372 -> Sleep Time: 0:58:5
16:47:25.406 -> Interrrupt Fired
16:47:25.406 -> just woke up!
16:47:25.406 -> WakeUp Time: 0:59:0
16:47:30.402 -> Sleep Time: 0:59:5
16:48:25.411 -> Interrrupt Fired
16:48:25.411 -> just woke up!
16:48:25.411 -> WakeUp Time: 1:0:0
16:48:30.391 -> Sleep Time: 1:0:5
16:49:25.417 -> Interrrupt Fired
16:49:25.417 -> just woke up!
16:49:25.417 -> WakeUp Time: 1:1:0
16:49:30.385 -> Sleep Time: 1:1:5
16:50:25.420 -> Interrrupt Fired
16:50:25.420 -> just woke up!
16:50:25.420 -> WakeUp Time: 1:2:0
16:50:30.385 -> Sleep Time: 1:2:5
16:51:25.421 -> Interrrupt Fired
16:51:25.421 -> just woke up!
16:51:25.421 -> WakeUp Time: 1:3:0
16:51:30.396 -> Sleep Time: 1:3:5

Maybe post your code here so we can see if there is anything amiss.

Hi again. Now i face a new problem. SD card won’t initialize suddenly.. i don’t know why. Any ideas for this issue?

Any ideas??