I have a sketch to put to sleep and wake up an Arduino Pro Mini 5V, but the problem is that sometimes when it is moved fast it wakes up itself, thing that I do not want. I have it configure to be waken up in the pin 2 by a rising signal using an interruption:
#define wakePin 2 // pin used for waking up
void wakeUpNow() // here the interrupt is handled after wakeup
{
// execute code here after wake-up before returning to the loop() function
// timers and code using timers (serial.print and more...) will not work here.
// we don't really need to execute any special functions here, since we
// just want the thing to wake up
}
void setup()
{
Serial.begin(115200);
pinMode(RLEDPIN, OUTPUT);
pinMode(GLEDPIN, OUTPUT);
pinMode(BLEDPIN, OUTPUT);
pinMode(wakePin, INPUT);
attachInterrupt(0, wakeUpNow, RISING );
}
void sleepNow() // here we put the arduino to sleep
{
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
sleep_enable(); // enables the sleep bit in the mcucr register // so sleep is possible. just a safety pin
attachInterrupt(0,wakeUpNow, RISING); // use interrupt 0 (pin 2) and run function // wakeUpNow when pin 2 gets LOW
sleep_mode(); // here the device is actually put to sleep!! // THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
sleep_disable(); // first thing after waking from sleep: // disable sleep...
detachInterrupt(0); // disables interrupt 0 on pin 2 so the // wakeUpNow code will not be executed // during normal running time.
}
void loop()
{
digitalWrite(GLEDPIN, HIGH); //set green led high
digitalWrite(BLEDPIN, HIGH); //set blue led high
digitalWrite(RLEDPIN, HIGH); //set red led high
times = millis();
if((times-times_f)>=12000)
{
times_f=times;
Serial.println(times-times_f);
digitalWrite(GLEDPIN, LOW); //Reset the LED's
digitalWrite(BLEDPIN, LOW);
digitalWrite(RLEDPIN, LOW);
sleepNow();
}
}
I think the problem is that it has a bit of rising signal while moving, so a solution could be to have a threshold in the reception of the signal, can it be done?