user27073: Can anyone help me to build a code which will activate a LED after 2 minutes when the power supply is cut off and blink that LED after a time interval of 30 seconds.
I want to import the code on Arduino-Uno.
I will power the Arduino with cell and assign two pins as sensor if they are connected to each other than every this is fine if they are cut the Arduino will blink the LED after 2 minutes and will keep blinking at 30 seconds interval

user10394: The Blink example will tell you how to blink an LED, you just need to change the times in the delay statements.
You want to detect the failure of a power supply.  You Arduino has a backup battery (cell) to power it when the power fails.  Correct?
There are voltage sensor kits available that can monitor mains voltage, just search for "Arduino Voltage sensor".  However there is a risk to you working with main voltages.  So using optical isolation (as ST2000 says) is probably safer for you.  There may be some optical isolator IC that can manage mains and 5V, they are usually white in colour.

user27073: I have a code edited by me
int pinButton = 8; //the pin where we connect the button
int LED = 2; //the pin we connect the LED

void setup() {
 pinMode(pinButton, INPUT); //set the button pin as INPUT
 pinMode(LED, OUTPUT); //set the LED pin as OUTPUT
}

void loop() {
 start:delay(120000);
 check:int stateButton = digitalRead(pinButton); //read the state of the button
 if(stateButton == 0) { //if not pressed

   digitalWrite(LED, HIGH);
   delay(250);
   digitalWrite(LED, LOW);
   delay(30000);
   goto check;
 } 
 else { //if  pressed
  digitalWrite(LED, LOW);
  goto start;
 }
}


user27157: DISCLAIMER: This is just a suggestion. No hate for this anwser please.
You could use a capacitor. A super capacitor (high capacity) with a proper joule theft circuit for your project could power the arduino for propably another 5min even if main power is cut off, plus you do not need any extra power source once the main source is cut off. It can be useful if you need to change the battery or move it to an other location but you do not want the module to be turned off.
const int led = 13;    //led pin
const int sensor = A0; //connect this your power supply, use a voltage divider if necessary
                       //this will act like a volt meter

void setup()
{
  pinMode(led, OUTPUT);
  pinMode(sensor, INPUT);
}

void loop()
{
  int V = analogRead(sensor);
  V = map(V,0,1023,0,5); // the 5 is replaced with the ammount of voltage that you supply the arduino

  if(V < 1) // when the power is below a point or simply disconnected, the capacitor 
            //will kick in by itself because the Arduino will draw its power
    {
    delay(120000)
    while(V < 1)
    {
      V = analogRead(sensor);
      V = map(V,0,1023,0,5);

      digitalWrite(led, HIGH);
      delay(500);
      digitalWrite(led, LOW);
      delay(29500);
    }
  }
}


user20245: Use a commonly available USB power pack re-charging from mains and powering the Arduino.  Use a light source directly powered by main and optically couple that to an Arduino.  There are plenty of examples on the web where an Arduino is used to detect light.  Once triggered, write some additional code to blink the led.  Since you are not doing anything other than timing, you can use the delay Arduino library to time events.

27073: <p>Can anyone help me to build a code which will activate a LED after 2 minutes when the power supply is cut off and blink that LED after a time interval of 30 seconds.
I want to import the code on Arduino-Uno.</p>

<p>I will power the Arduino with cell and assign two pins as sensor if they are connected to each other than every this is fine if they are cut the Arduino will blink the LED after 2 minutes and will keep blinking at 30 seconds interval</p>
 10394: <p>The Blink example will tell you how to blink an LED, you just need to change the times in the delay statements.</p>

<p>You want to detect the failure of a power supply.  You Arduino has a backup battery (cell) to power it when the power fails.  Correct?</p>

<p>There are voltage sensor kits available that can monitor mains voltage, just search for "Arduino Voltage sensor".  However there is a risk to you working with main voltages.  So using optical isolation (as ST2000 says) is probably safer for you.  There may be some optical isolator IC that can manage mains and 5V, they are usually white in colour.</p>
 27073: <p>I have a code edited by me</p>

<pre><code>int pinButton = 8; //the pin where we connect the button
int LED = 2; //the pin we connect the LED

void setup() {
 pinMode(pinButton, INPUT); //set the button pin as INPUT
 pinMode(LED, OUTPUT); //set the LED pin as OUTPUT
}

void loop() {
 start:delay(120000);
 check:int stateButton = digitalRead(pinButton); //read the state of the button
 if(stateButton == 0) { //if not pressed

   digitalWrite(LED, HIGH);
   delay(250);
   digitalWrite(LED, LOW);
   delay(30000);
   goto check;
 } 
 else { //if  pressed
  digitalWrite(LED, LOW);
  goto start;
 }
}
</code></pre>
 27157: <p>DISCLAIMER: This is just a suggestion. No hate for this anwser please.</p>

<p>You could use a capacitor. A super capacitor (high capacity) with a proper joule theft circuit for your project could power the arduino for propably another 5min even if main power is cut off, plus you do not need any extra power source once the main source is cut off. It can be useful if you need to change the battery or move it to an other location but you do not want the module to be turned off.</p>

<pre><code>const int led = 13;    //led pin
const int sensor = A0; //connect this your power supply, use a voltage divider if necessary
                       //this will act like a volt meter

void setup()
{
  pinMode(led, OUTPUT);
  pinMode(sensor, INPUT);
}

void loop()
{
  int V = analogRead(sensor);
  V = map(V,0,1023,0,5); // the 5 is replaced with the ammount of voltage that you supply the arduino

  if(V &lt; 1) // when the power is below a point or simply disconnected, the capacitor 
            //will kick in by itself because the Arduino will draw its power
    {
    delay(120000)
    while(V &lt; 1)
    {
      V = analogRead(sensor);
      V = map(V,0,1023,0,5);

      digitalWrite(led, HIGH);
      delay(500);
      digitalWrite(led, LOW);
      delay(29500);
    }
  }
}
</code></pre>
 20245: <p>Use a <a href="http://lmgtfy.com/?q=usb%20power%20pack" rel="nofollow">commonly available USB power pack</a> re-charging from mains and powering the Arduino.  Use a light source directly powered by main and optically couple that to an Arduino.  There are plenty of <a href="http://arduinobasics.blogspot.com/2011/06/arduino-uno-photocell-sensing-light.html" rel="nofollow">examples</a> on the web where an Arduino is used to detect light.  Once triggered, write some additional code to <a href="https://www.arduino.cc/en/tutorial/blink" rel="nofollow">blink the led</a>.  Since you are not doing anything other than timing, you can use the <a href="https://www.arduino.cc/en/Reference/Delay" rel="nofollow">delay Arduino library</a> to time events.</p>
