Repeat Certain Number of Times, Delay Interval, Repeat Infinitely

Hello,

I have a simple problem that I have searched for and can't find the exact situation. Looks like I need a "For" in my code.

I just want to repeat 28 times, delay 15 minutes, and then repeat forever.

Here's my code:

int sensorPin = A0; // select the input pin for the potentiometer
int RelayCoil = 13; // select the pin for the Relay Coil
int sensorValue = 0; // variable to store the value coming from the sensor

void setup() {
// declare the RelayCoil as an OUTPUT:
pinMode(RelayCoil, OUTPUT);
}

void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin)/2;
// turn the RelayCoil on
digitalWrite(RelayCoil, HIGH);
// stop the program for milliseconds:
delay(sensorValue);
// turn the RelayCoil off:
digitalWrite(RelayCoil, LOW);
// stop the program for for milliseconds:
delay(sensorValue);
}

SOLVED! Thanks Forum Search!

int sensorPin = A0; // select the input pin for the potentiometer
int RelayCoil = 13; // select the pin for the Relay Coil
int sensorValue = 0; // variable to store the value coming from the sensor

void setup() {
// declare the RelayCoil as an OUTPUT:
pinMode(RelayCoil, OUTPUT);
}

void loop() {
// read the value from the sensor:
for(int i = 0; i < 27; i++)
{
sensorValue = analogRead(sensorPin)/2;
// turn the RelayCoil on
digitalWrite(RelayCoil, HIGH);
// stop the program for milliseconds:
delay(sensorValue);
// turn the RelayCoil off:
digitalWrite(RelayCoil, LOW);
// stop the program for for milliseconds:
delay(sensorValue);
}
delay(5000);
}

A delay of 15 minutes is delay(15601000UL);

Yes, thanks, I had that in there to test it so I didn't have to wait - forgot to change it

rob, I used 900000, but I'm thinking it would be better to write it out like you did. Is UL microsecond, I think it should be millisecond?

UL stands for unsigned long. It forces the numeric constants to be of that type. Normally the C/C++ compiler takes as default an int which happens to be 16 bit on AVR and would cause an overflow ...