# AttachInterrupt Problem

**URL:** <https://community.particle.io/t/attachinterrupt-problem/6924>\
**Category:** Firmware\
**Created:** [September 12, 2014, 4:38pm UTC](https://community.particle.io/t/attachinterrupt-problem/6924 "2014-09-12T16:38:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gdillen](https://avatars.discourse-cdn.com/v4/letter/g/e8c25b/32.png) [@gdillen](https://community.particle.io/u/gdillen)\
**Post date:** [September 12, 2014, 4:38pm UTC](https://community.particle.io/t/attachinterrupt-problem/6924/1 "2014-09-12T16:38:01Z")

</div>

Hi,

I’m attaching an interrupt to a port with a PIR sensor (see code below). But nothing happens when the PIR sensor is “activated” or “de-activated”. Removing pinMode(pir, INPUT\_PULLUP); doesn’t change anything. What am I missing here?

```
indent preformatted text by 4 spaces

```

Thanks.  
Guy

```cpp

    int pir = D0;
    int blueLED = D1;
    
        indent preformatted text by 4 spaces
    
    void pirOn(void);
    void pirOff(void);
    volatile int state = LOW;
    
    void setup() { 
        pinMode(pir, INPUT_PULLUP);
        pinMode(blueLED, OUTPUT);
        attachInterrupt(pir, pirOn, RISING);
        attachInterrupt(pir, pirOff, FALLING);
    }
    
    void loop() {
     	// These statements work
        /*if (digitalRead(pir) == HIGH) {
            digitalWrite(blueLED, HIGH);
        } else if (digitalRead(pir) == LOW) {
            digitalWrite(blueLED, LOW);
        }*/
        
        digitalWrite(blueLED, state);
    }
    
    void pirOn() {
        // Duplicate for testing
        digitalWrite(blueLED, HIGH);
    	
        state = HIGH;
    }
    
    void pirOff() {
    	// Duplicate for testing
        digitalWrite(blueLED, LOW);
    	
        state = LOW;
    }

```

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [September 12, 2014, 4:53pm UTC](https://community.particle.io/t/attachinterrupt-problem/6924/2 "2014-09-12T16:53:20Z")

</div>

@gdillen, you can only associate a single ISR to a pin. In your case you could use CHANGE instead of FALLING and RISING then in the (single) ISR read the pin to decide what the change was ( LOW for FALLING and HIGH for RISING). 😄

---

<div class="post-metadata">

**Author:** ![gdillen](https://avatars.discourse-cdn.com/v4/letter/g/e8c25b/32.png) [@gdillen](https://community.particle.io/u/gdillen)\
**Post date:** [September 12, 2014, 5:30pm UTC](https://community.particle.io/t/attachinterrupt-problem/6924/3 "2014-09-12T17:30:26Z")

</div>

@peekay123 Thanks. I thought **wrongly** :

- I could attach 2 interrupts to the same pin.
