How to delay the LED from turning back ON for 15 sceonds.

All, I used the Button program and modified it to turn ON the LED when the switch was not pressed. Pressing the switch successfully extinguishes the LED, and it comes back on after a short time off. Problem is that I want to delay the LED turning back ON until 15 seconds have elapsed! I tried inserting a delay statement in the program, with no success. I must not have it in the right place, or the right command. Can someone please advise?

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 1;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == LOW) {
    // turn LED on:
    digitalWrite(ledPin, HIGH); 
    // turn LED off:
    digitalWrite(ledPin, LOW);

Thanks, Mike

You need to catch the time when the switch first goes from HIGH to LOW. See change of detection example in the IDE. Show us your wiring. You may need INPUT_PULLUP for your switch pinMode

Actually, this is a Uno board, and all the components (switch and LED) are integral to it. The fact that it works with the base code for button and blink should be answer enough that it is working properly, but I will check it with a scope to be sure. All I needed to know was: is my programming correct - I'm a hardware guy, not much of a coder.. Thanks for the tip on the INPUT_PULLUP; will look at that.. -M-

There is no push button integrated on an UNO board except for the reset button. If you're using that and thinking it can work like a normal push button then that may be the crux of your problem.

Change the switch pinMode to

pinMode(buttonPin, INPUT_PULLUP); //Enable the internal pull-up resistor


Thanks to all; got it! Here is what I found.. First, you are correct, the reset button won't do what I thought. Had to add a switch between pin 12 and GND, and redefine in the button program. And yes, enabling the internal pullup was helpful as well - but only AFTER redoing the switch to pin 12 and testing - as well as inverting the LED states in software. The original question I asked was in part as to whether I had the delay at the right point in the software. Turns out that part was correct - once we got all the other ducks lined up right.. Sheesh.. who knew programming was this complicated? :) Thanks to all, this was very encouraging! Regards, Mike