Newbie needs a little programming help

Hi,

i am very new to arduino and am trying to understand the programming better but i need some quick help…

I have an UNO R3 controlling an air diverter valve via a relay. I repeat actuation 10 times and stop. It works great but i would like to add an indicating led that tells me when my 10 actuations are complete.

I dont know how to add this action. A little guidance would be greatly appreciated.

thank you

Below is my sketch

/*

Relay control with indicator lights

Turns on and off a LED and relay for specified times, Led is on while relay is active. The action is repeated 10 times.

*/

// Pin 11 has an LED connected and pin 12 has a relay.

// give pins names:

int led = 11;

int relay = 12;

void setup()

{

pinMode(led, OUTPUT); //set LED pin as an output

pinMode(relay, OUTPUT); //set relay pin as an output

//do the next thing 10 times

for(int i = 0; i < 10; i += 1)

{

//Turn relay and LED on for X seconds, followed by off for X seconds

digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)

digitalWrite(relay, HIGH); // turn the Relay on (HIGH is the voltage level)

delay(3000); // wait for X seconds

digitalWrite(led, LOW); // turn the LED off by making the voltage LOW

digitalWrite(relay, LOW); // turn the Relay off by making the voltage LOW

delay(3000); // wait for X seconds

}

}

void loop(){}

Why wouldn’t you define another pin as an output, connect an LED to it akin to the other LED (perhaps a different color) and then after your 10 iterations are done, write a HIGH to it to turn it on (just like the other LED) ?

/*
Relay control with indicator lights
Turns on and off a LED and relay for specified times, Led is on while relay is active. The action is repeated 10 times.
*/

// Pin 11 has an LED connected and pin 12 has a relay.
// give pins names:

int doneLED = 10; // new LED to indicate 10 reps are done
int led = 11;
int relay = 12;

void setup()
{
  pinMode(doneLED, OUTPUT); //set new LED pin as an output
  digitalWrite(doneLED, LOW); //make sure new LED is off
  pinMode(led, OUTPUT); //set LED pin as an output
  pinMode(relay, OUTPUT); //set relay pin as an output
  //do the next thing 10 times
  for(int i = 0; i < 10; i += 1)
  {
    //Turn relay and LED on for X seconds, followed by off for X seconds
    digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
    digitalWrite(relay, HIGH); // turn the Relay on (HIGH is the voltage level)
    delay(3000); // wait for X seconds
    digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
    digitalWrite(relay, LOW); // turn the Relay off by making the voltage LOW
    delay(3000); // wait for X seconds
  }
  // at this point all 10 of the iterations are done so turn on other LED
  digitalWrite(doneLED, HIGH);
}
void loop(){
}

ps - if you use the code buttons you can paste nicely formatted code (above) which is easier to read.

(click on to enlarge)