int countDown = 120; // Countind down 2 minutes
unsigned long lastTick;
#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP 60 /* Time ESP32 will go to sleep (in seconds) */
RTC_DATA_ATTR int bootCount = 0;
void setup(){
Serial.begin(9600);
}
void loop(){
unsigned long currentMillis = millis();
if(currentMillis - lastTick >= 1000){
countDown--;
displayCountdownToSerial();
lastTick += 1000;
}
}
void displayCountdownToSerial(){
int mins = countDown / 60;
int secs = countDown % 60;
Serial.print(" Time Remain To Sleep = ");
Serial.print(mins);
Serial.print(" : ");
Serial.println(secs);
if(countDown == 0){
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
delay(1000);
Serial.println("Sleep now Start");
esp_deep_sleep_start();
Serial.println("This will never be printed");
}
}
Above was my coding for deep sleep mode for arduino . It will sleep every 2 min by countDown timing. It that possible during the sleep mode ,Example i'm using a ultrasonic sensor during the sleep mode function when it detected some distance arduino will wake up and does something?