[Solved] Arduino wont wake up from Sleep mode

I am using motion sensor to wake up my Arduino Mega from power down sleep mode with external interrupt but it is not working. My Arduino sleep forever and wont wake up.

#include "LowPower.h"


const int wakeUpPin = 2;
int MotionS = 7; 


void wakeUp()
{
  Serial.println("woke up");

}

void setup()
{
  Serial.begin(9600);
   pinMode(MotionS, INPUT);
   pinMode(wakeUpPin, INPUT_PULLUP);
   attachInterrupt(digitalPinToInterrupt(wakeUpPin), wakeUp, LOW);
}

void loop()
{
  Serial.println(MotionS);
  if (digitalRead(MotionS) == LOW)
  {
      Serial.println("Going to Sleep");
      delay(1000);
      LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
  }

 else
  {
    wakeUp();
    digitalWrite(wakeUpPin, LOW);
    delay(10000); 
    digitalWrite(wakeUpPin, HIGH); 
  }

}

What is wakeUpPin connected to?

What do you think this does?

Hi, there is nothing connect to the wakeUpPin.
But i want the signal of pin 2 to be low then it can wake up my arduino.

digitalWrite(wakeUpPin, LOW); is to set the signal of the pin 2 to be low when the motion sensor is activated so the arduino will wake up.

How can you set pin 2 low when you are asleep?

Yup, you are correct so i am confusing how can i use a sensor to wake up my arduino, or it is impossible to do that.

You can use a sensor to wake up... but the sensor needs to be powered on. What sensor are you using?

i am using the motion sensor

Which one? Can you provide a link?

https://s.lazada.com.my/s.4pUU6

Ok so just connect the output pin to the interrupt pin. I presume it goes HIGH on movement, so you just set an interrupt to trigger on RISING.

Therefore, i connect my output pin to the pin 2 and the coding will be like this?

#include "LowPower.h"


const int wakeUpPin = 2;


void wakeUp()
{
  detachInterrupt(digitalPinToInterrupt(wakeUpPin));
  Serial.println("woke up");

}

void setup()
{
  Serial.begin(9600);
   pinMode(wakeUpPin, INPUT_PULLUP);
   attachInterrupt(digitalPinToInterrupt(wakeUpPin), wakeUp, RISING);
}

void loop()
{
  if (digitalRead(wakeUpPin) == LOW)
  {
      Serial.println("Going to Sleep");
      delay(1000);
      LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
  }

 else
  {
    wakeUp();
    delay(10000); 
    digitalWrite(wakeUpPin, LOW); 
  }

}

Do you want the motion sensor to wake up the Arduino or put it to sleep?

Your code is mode complicated than it needs to be.

Hi, i want my motion sensor to wake up the Arduino.

ok.. and what puts it to sleep? does it sleep after a certain time?

Yeah, my project is like a monitoring system, so it need to sleep when there is nothing, and wake up for a period to perform its function when the motion sensor detected something.

so yes, i need it sleep after a certain time so i put a delay for it

#include "LowPower.h"

const int wakeUpPin = 2;

void wakeUp()
{
  detachInterrupt(digitalPinToInterrupt(wakeUpPin));
}

void setup()
{
  Serial.begin(9600);
  pinMode(wakeUpPin, INPUT);  
}

void loop()
{
  Serial.println("Going to Sleep");
  delay(1000);
  attachInterrupt(digitalPinToInterrupt(wakeUpPin), wakeUp, RISING);
  LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);

  Serial.println("Woke up");
  delay(1000);

  // Do the other stuff here...
}
1 Like

HI, after using this code, the arduino still wont wake up.

Hi, i am appreciate that for your helping, my system is working correctly now, Thank you so much!

Good to hear. Mark the post as solved so others don't waste time on it.

Sorry about that, it is working on Arduino UNO but Arduino Mega is not working with this code, i think the problem is Mega cant understand the RISING.