Stop void loop

Hi,

Is there anything to stop a void loop?

Why! My program runs a system ignitor which if after 3 attemps a flame is not detected (via thermocouple+co amp) switches on a warning lamp while shut down a gas solenoid and the system.

Help please...

Thanks
Kenneth

code below

//----Igniton Module v3.0
//----by Kenneth Agius

#define Ignitor 13
#define Solenoid 12

int x;
int IgnitionStarts = 1;
int BeforeFlameOn;
int AfterFlameOn;

//-------------------------------------------------------------------------------\

void setup() // run once, when the sketch starts
{
Serial.begin(9600);
pinMode(Ignitor, OUTPUT);
pinMode(Solenoid, OUTPUT);
}

//-------------------------------------------------------------------------------\

void loop() // run over and over again
{
Ignition_();
//ThermocoupleTest_();
delay(20000);
}

//-------------------------------------------------------------------------------\

void Ignition_()
{
Serial.println();
Serial.print("Start Ignition sequence no: ");
Serial.print(IgnitionStarts);
Serial.println();

BeforeFlameOn=analogRead(0);
Serial.print("Low flame reading: ");
Serial.print(BeforeFlameOn);

//condition 1
if (analogRead(0)>150)
{
Serial.println();
Serial.print("Flame is on or thermocouple is cooling down");
Serial.println();
Serial.print("Ignition sequence stopped- 15sec cool down started");
Serial.println();
delay(15000);
return;
}
else
{
Serial.println();
Serial.print("Open gas valve");
digitalWrite(Solenoid,HIGH);
Serial.println();
delay(500);
Serial.print("Ignitor started");
Serial.println();
digitalWrite(Ignitor, HIGH);
delay(700);
Serial.print("Ignitor switched off");
Serial.println();
digitalWrite(Ignitor, LOW);
}

delay(1000);
AfterFlameOn=analogRead(0);
Serial.print("High flame reading: ");
Serial.print(AfterFlameOn);
Serial.println();

//condition 2
if (AfterFlameOn>BeforeFlameOn+50)
{
Serial.print("Flame Detected");
Serial.println();
}
else
{
digitalWrite(Solenoid,LOW); // switch off solenoid
Serial.print("Ignition sequence aborted- Flame not detected");
Serial.println();
IgnitionStarts++;
return;
}
//condition 3
if (BeforeFlameOn>150)
{
Serial.print("Flame is on or thermocouple is cooling down");
Serial.println();
Serial.print("Ignition sequence stopped");
Serial.println();
return;
}

}

//-------------------------------------------------------------------------------\

void ThermocoupleTest_()
{
for (int x=0; x<5000; x++)
{
BeforeFlameOn=analogRead(0);
Serial.println();
Serial.print("x= ");
Serial.print(x);
Serial.print("\t");
Serial.print(analogRead(0));
Serial.print("\t");
Serial.print(BeforeFlameOn);
}
}

If I understand well, you want to completely stop the program. You can just make it go in an endless loop :

while(1) { }

"Stopping" the void loop() would mean returning from main(), which in the case of AVR programming is not exactly a bright idea :slight_smile:

I'm new to C and this kindy of programing.
What exacly
"Stopping" the void loop() would mean returning from main()

means?

This was just a detail : Arduino environnement defines a main() function which endlessy calls the loop() function you write in your program.

When you do C programming for common computers, returning from (io reaching the end) of main() means ending the program and giving back control to the computer. In the context of the Arduino, there's nothing you can give "control" back to if you leave the program, so the Arduino will (I believe, as I haven't tested) go on anyway on random data.

The important thing I wanted to say was that you can't stop the program, but you can make it go endlessly doing nothing, with the little bit of code I posted. Will have exactly the same effect, seen from the outside.

Thank you very much. Appricated..