user29770: The example program is from here: https://www.arduino.cc/en/Reference/attachInterrupt
When I paste in the code and run it, the LED is on all the time (It's supposed to blink):
const byte ledPin = 13;
const byte interruptPin = 2;
volatile byte state = LOW;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
}

void loop() {
  digitalWrite(ledPin, state);
}

void blink() {
  state = !state;
}

This is my setup:


user27957: if you want to blink your LED by giving interrupt by push button then you can try this..
int pushButton = 2;
int LED = 13;
volatile bool flag = false;
volatile byte state = LOW;

void setup()
{
    pinMode(pushButton, INPUT_PULLUP);
    pinMode(LED,OUTPUT);
    attachInterrupt(digitalPinToInterrupt(pushButton), &setFlag, FALLING);
}

void loop() 
{
    if (flag) 
    {
        digitalWrite(LED, state);
        delay(100);
        state = !state;
    }
}

void setFlag()
{
    flag = true;
}


user30005: to expand on my comments to Prayuktibid's code,  here is what I would propose in the loop:
void loop() 
{
    if (flag) 
    {
        //blink the led
        digitalWrite(LED, !digitalRead(LED));   //digitalWrite(LED, state);
        //delay(100);
        //reset the flag
        flag = false;                           //state = !state;
    }
}

the rest remains unchanged.
here is how it works:

it works as you would expect, without resorting to delays.
edit: btw, the approach shown above (of setting a flag in the isr, processing that flag in the main loop, and resetting the flag after the processing) is a fairly standard way of utilizing interrupts - pretty much the #1 choice unless you have some special reasons to deviate from it.
edit2: to just follow up on that state above (about trying to process the flag in the main loop).
for something this simple, you can also do it in the isr, making the code much closer to your original code:
void loop() 
{
        digitalWrite(LED, flag);                //digitalWrite(LED, state);
}

void setFlag()
{
    //flip the flag
    flag = !flag;                               //flag = true;
}

the code above produced the same waveform as the code posted earlier.
the lessons learned: there is more than one way to solve a problem, as long as you do it right, :)

user84: I think you misunderstood this example: it is not expected to automatically blink!
The LED is suposed to change state at every change of level on pin 2. This supposes that you wired something (e.g. a push button) to pin 2 and that this will make pin 2 change level when something happens (e.g. you press the button or you release it).
On your diagram, there is nothing wired on pin 2, so what you observe is just normal.
If you want to see attachInterrupt in practice, then connect pin 2 to a button with the other button lead connected to GND.
Then you can observe what happens when you play with that button.

29770: <p>The example program is from here: <a href="https://www.arduino.cc/en/Reference/attachInterrupt" rel="nofollow noreferrer">https://www.arduino.cc/en/Reference/attachInterrupt</a></p>

<p>When I paste in the code and run it, the LED is on all the time (It's supposed to blink):</p>

<pre><code>const byte ledPin = 13;
const byte interruptPin = 2;
volatile byte state = LOW;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
}

void loop() {
  digitalWrite(ledPin, state);
}

void blink() {
  state = !state;
}
</code></pre>

<p>This is my setup:</p>

<p><a href="https://i.stack.imgur.com/QYAvo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QYAvo.png" alt="enter image description here"></a></p>
 27957: <p>if you want to blink your LED by giving interrupt by push button then you can try this..</p>

<pre><code>int pushButton = 2;
int LED = 13;
volatile bool flag = false;
volatile byte state = LOW;

void setup()
{
    pinMode(pushButton, INPUT_PULLUP);
    pinMode(LED,OUTPUT);
    attachInterrupt(digitalPinToInterrupt(pushButton), &amp;setFlag, FALLING);
}

void loop() 
{
    if (flag) 
    {
        digitalWrite(LED, state);
        delay(100);
        state = !state;
    }
}

void setFlag()
{
    flag = true;
}
</code></pre>
 30005: <p>to expand on my comments to Prayuktibid's code,  here is what I would propose in the loop:</p>

<pre><code>void loop() 
{
    if (flag) 
    {
        //blink the led
        digitalWrite(LED, !digitalRead(LED));   //digitalWrite(LED, state);
        //delay(100);
        //reset the flag
        flag = false;                           //state = !state;
    }
}
</code></pre>

<p>the rest remains unchanged.</p>

<p>here is how it works:</p>

<p><a href="https://i.stack.imgur.com/kYEQz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kYEQz.png" alt="enter image description here"></a></p>

<p>it works as you would expect, without resorting to delays.</p>

<p>edit: btw, the approach shown above (of setting a flag in the isr, processing that flag in the main loop, and resetting the flag after the processing) is a fairly standard way of utilizing interrupts - pretty much the #1 choice unless you have some special reasons to deviate from it.</p>

<p>edit2: to just follow up on that state above (about trying to process the flag in the main loop).</p>

<p>for something this simple, you can also do it in the isr, making the code much closer to your original code:</p>

<pre><code>void loop() 
{
        digitalWrite(LED, flag);                //digitalWrite(LED, state);
}

void setFlag()
{
    //flip the flag
    flag = !flag;                               //flag = true;
}
</code></pre>

<p>the code above produced the same waveform as the code posted earlier.</p>

<p>the lessons learned: there is more than one way to solve a problem, as long as you do it right, :)</p>
 84: <p>I think you misunderstood this example: it is not expected to automatically blink!</p>

<p>The LED is suposed to change state at every change of level on pin 2. This supposes that you wired something (e.g. a push button) to pin 2 and that this will make pin 2 change level when something happens (e.g. you press the button or you release it).</p>

<p>On your diagram, there is nothing wired on pin 2, so what you observe is just normal.</p>

<p>If you want to see <code>attachInterrupt</code> in practice, then connect pin 2 to a button with the other button lead connected to <code>GND</code>.</p>

<p>Then you can observe what happens when you play with that button.</p>
