Arduino wake up

Hello there,

My question is simple (I guess).

Here is my code. How can I wake up my arduino? I mean....what to put on PIN 2 to wake it up?

#include <avr/sleep.h>
#include <avr/power.h>

int pin2 = 2;

/***************************************************

  • Name: pin2Interrupt
  • Returns: Nothing.
  • Parameters: None.
  • Description: Service routine for pin2 interrupt

**************************************************/
void pin2Interrupt(void)
{
/
This will bring us back from sleep. */

/* We detach the interrupt to stop it from

  • continuously firing while the interrupt pin
  • is low.
    */
    detachInterrupt(0);
    }

/***************************************************

  • Name: enterSleep
  • Returns: Nothing.
  • Parameters: None.
  • Description: Enters the arduino into sleep mode.

***************************************************/
void enterSleep(void)
{

/* Setup pin2 as an interrupt and attach handler. */
attachInterrupt(0, pin2Interrupt, LOW);
delay(100);

set_sleep_mode(SLEEP_MODE_PWR_DOWN);

sleep_enable();

sleep_mode();

/* The program will continue from here. */

/* First thing to do is disable sleep. */
sleep_disable();
}

/***************************************************

  • Name: setup
  • Returns: Nothing.
  • Parameters: None.
  • Description: Setup for the Arduino.

***************************************************/
void setup()
{
Serial.begin(9600);

/* Setup the pin direction. */
pinMode(pin2, INPUT);

Serial.println("Initialisation complete.");
}

/***************************************************

  • Name: loop
  • Returns: Nothing.
  • Parameters: None.
  • Description: Main application loop.

***************************************************/
int seconds=0;
void loop()
{
delay(1000);
seconds++;

Serial.print("Awake for ");
Serial.print(seconds, DEC);
Serial.println(" second");

if(seconds == 3)
{
Serial.println("Entering sleep");
delay(200);
seconds = 0;
enterSleep();
}

}

I don't know f I understand the question, but I guess that a push button.

a push button connecting PIN2 with what? I ve tried connecting vcc to pin2 to wake it up or gnd but it doesnt works...

Connected to with a pull-up to GND:

  attachInterrupt(0, pin2Interrupt, LOW);

You can change the "LOW" to other thing too.

Wait a momment. I got an rf receiver on the project which output a HIGH when I press the button of the remote. Would this work as triger pin? and if yes should be low,failing,change or what?

if you dont specify the input pin config, it may be floating. so set it to high or low, and have the device like button changing the input value.

then if device grounds the pin detect a falling signal, or a rising signal if the press sets 5v

I got confused now...If I use LOW whats the input of the pin that would wake my arduino??

for example, set the pullup to high on the input pin.

now when your button grounds it to zero you have a clean falling transition.

so... I set this:

attachInterrupt(0, pin2Interrupt, HIGH);

and then I use a button to connect PIN with GND right?

PS

If I use

attachInterrupt(0, pin2Interrupt, LOW);

and connect PIN with VCC will this wake it?

dunno about attachinterrupt syntax, but you get the concept, yes.

Thanks a lot!!!!

Hi, try this

It works for me.

#include <avr/sleep.h>


void  setup()

{

  Serial.begin(9600);
  pinMode(7, OUTPUT);


  pinMode(2, INPUT);
  digitalWrite(2, HIGH); // set int0 = digital pin 2 HIGH
  
  
}

void loop()

{ delay(5000);  // arduino goes to bed after five seconds

  sleepSetup();
}


void sleepSetup()

{ sleep_enable();
  attachInterrupt(0, pinInterrupt, FALLING);  // wake arduino up when you press the button on pin2

  set_sleep_mode(SLEEP_MODE_PWR_DOWN);

  digitalWrite(7, LOW);
  sleep_cpu();
  Serial.println("Arduino is up!");
  digitalWrite(7, HIGH);

}

void pinInterrupt()

{ sleep_disable();

  detachInterrupt(0);

}

Do not use LOW as Delta says **********do use FALLING

digital pin 2 ------one leg of your button -------------the other leg of your button -----arduino ground

(no resistors needed)

since digital write pin 2 (int 0 = interrupt 0) to HIGH in the setup

the internal pullup resistor is used the pin 2 is HIGH

when you press the button on pin 2, the pin state goes from HIGH to LOW

you can then wake up your arduino

Hi,
Can I use arduino onto pin 0 or pin 1, A0 to A5 as wake interrupt instead of pin2? Pls. Advise. Thanks.