Go Down

Topic: Interrupt Issues, Interrupt 5 not working (Read 246 times) previous topic - next topic

ccholas

Hello. I am new to Arduino, but very excited to be using it. It has been very simple in all other aspects until I tried to use the interrupts. I have a PIR motion sensor (http://www.robotshop.com/productinfo.aspx?pc=RB-See-194&lang=en-US) attached to the arduino mega 2560 ADK R3 board (http://arduino.cc/en/uploads/Main/ArduinoADKFront.jpg). I have connected the motion sense pin of the sensor to pin 18 (interrupt 5) of the board. Have confirmed the pin out and I have confirmed that the pin does in fact go high for about 3 seconds when motion is detected. I have confirmed this with a volt meter and I have connected the pin to the analog A1 input to read the voltage. So it is fully functioning. However when I connect it to pin 18 and set up the pin for the interrupt I cannot get it to detect the rising edge of the motion sense pin and call the ISR. I have tried to move the pin to interrupt 0 and interrupt 1. I cannot use these pins in my design because I intend to use those ports for communication with other devices. The following is my code that I am trying to use.

Can anyone give me an idea of what I am doing wrong?

/**********
Motion Sensor Code
***********/

int motionPin = 18;
volatile int motionSensorState = LOW;

void setup(){
// Open serial 0 communications and wait for port to open:
//Serial port 0 will be used to send debugger messages to the PC
//that is connected via the USB port.
Serial.begin(57600);

pinMode(motionPin, INPUT);
attachInterrupt(5, pin5isr, RISING);
Serial.println("Motion Sensor Pin configured");
}

void loop() {
if(motionSensorState){
Serial.println("Motion Detected");
motionSensorState = LOW;
}
}

void pin5isr()
{
  motionSensorState = HIGH;
}

CrossRoads

And please don't post the same thing in multiple places - i.e. crosspost - we'll see it & move it if needed.
Thanks
Moderator
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

AWOL

Useful reading here and here

Please don't cross-post. Your duplicate post has been deleted.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy