Problem with heater control

I have a Uno card. I am trying to build a heater control to replace and older discontinued unit.
I need to test flame sensor, if sensor reads flame do nothing.
If it read no flame count 8 seconds, turn on spark and fuel for 5 seconds. If flame is detected I turn on second fuel nozzle.
If at any time no flame is detected shut of ardino without restart.
I cannot get the program to look at sensor and shut off.
I understand not using go to but it appears I need a program away from the main source code.

/* added, else or to turn off if flame sense detects no flame*/
//modified start up for green light in set up
// will not run green light comes on at start
// both forms are valid -moved from return value-

// These constants won’t change:
const int analogPinss = A0; // pin that the switch is attached to
const int analogPinflm = A1; // pin that the flame sensor is attached to
const int ledPinnf = 13; // pin that the no flame sense LED is attached to
const int ledPinprg = 12; // pin that the purge LED is attached to
const int ledPinss = 11; // pin that the system start LED is attached to
const int ledPinstg2 = 10; // pin that the stage 2 LED is attached to
const int ledPinstg1 =9; // pin that the stage 1 LED is attached to
const int ledPinfp = 8; // pin that the fuel pump LED is attached to
const int ledPinsprk = 7 ; // pin that the spark output LED is attached to
const int threshold = 800; // an arbitrary threshold level that’s in the range of the analog inputs
int analogValue1 = 1; // variable to store the value coming from the on/off switch

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

void setup() {
// initialize all the LED pin as an output:
pinMode(ledPinss, OUTPUT);
pinMode(ledPinnf, OUTPUT);
pinMode(ledPinprg, OUTPUT);
pinMode(ledPinstg1, OUTPUT);
pinMode(ledPinstg2, OUTPUT);
pinMode(ledPinfp, OUTPUT);
pinMode(ledPinsprk, OUTPUT);
pinMode(analogPinss, INPUT);
pinMode(analogPinflm, INPUT);
digitalWrite(analogPinss, LOW); // turn on pull down resistor
digitalWrite(analogPinflm, LOW); //turn on pull down resistor

//initialize serial communications:
Serial.begin(9600);;

}

void loop() {
void exit (int exitcode);

// read the value of the Flame sensor:
int analogValue1 = analogRead(analogPinss); //on oss switch, taken out
int analogValue2 = analogRead(analogPinflm); // if the analog value 2 is low, LED off:

{ if (analogValue2 > threshold)
{digitalWrite(ledPinnf, LOW); //turn off no flame LED: note this is backwards

digitalWrite(ledPinprg, LOW);

} else if (analogValue2 < threshold)
{digitalWrite(ledPinnf, HIGH); //turn no flame LED on Note this is backwards

digitalWrite(ledPinprg, HIGH);
delay (8000); //purge on time 8 seconds
digitalWrite(ledPinprg, LOW); //turn purge timer off

//need to break program so that code below runs and skips upper code
}
}
//start new program, searching for flame
{ if (analogValue2 < threshold)
{digitalWrite(ledPinfp, HIGH);
digitalWrite(ledPinsprk, HIGH);
digitalWrite(ledPinstg1, HIGH);
delay (5000);
if (analogValue2 > threshold)
abort();} //forces abnormal termination
else if (analogValue2 < threshold)
digitalWrite(ledPinstg2, HIGH);}

// print the analog value:
Serial.println(analogValue2);

}

  void exit (int exitcode);

A function prototype in a function is pretty much useless. Get rid of it.

If at any time no flame is detected shut of ardino without restart.

Is this before, or after, the "if no flame for 8 seconds" part that tries to relight it? Conflicting requirements make for difficult programming.

  digitalWrite(analogPinss, LOW); // turn on pull down resistor
  digitalWrite(analogPinflm, LOW); //turn on pull down resistor

Wrong. These statements do NOT do that.

I gave up reading your code. Use Tools + Auto Format before posting any code. Post code ONLY after clicking the # icon above the smiley faces.

Nothing follows the { on any line. Nothing follows any } ever.

:slight_smile:
THis is my problem., I have a conflicting requirement.
I must do the following:
1 CHeck that no flame sensor is good—IE sensor must read no flame
2 then I can start my program and wait for flame sensor to detect flame (IE no flame) and allow to run if I have flame detection
3. If no flame detection shiut off
4 If and after program starts I look at the flame sensor and if detects no flame I shut off permenantly
This is conflicitng stuff. I did not know if the go to function would help here? I am new to C++

/* added, else or to turn off if flame sense detects no flame*/
//modified start up for green light in set up
// will not run green light comes on at start
// both forms are valid -moved from return value-

// These constants won’t change:
const int analogPinss = A0; // pin that the switch is attached to
const int analogPinflm = A1; // pin that the flame sensor is attached to
const int ledPinnf = 13; // pin that the no flame sense LED is attached to
const int ledPinprg = 12; // pin that the purge LED is attached to
const int ledPinss = 11; // pin that the system start LED is attached to
const int ledPinstg2 = 10; // pin that the stage 2 LED is attached to
const int ledPinstg1 =9; // pin that the stage 1 LED is attached to
const int ledPinfp = 8; // pin that the fuel pump LED is attached to
const int ledPinsprk = 7 ; // pin that the spark output LED is attached to
const int threshold = 800; // an arbitrary threshold level that’s in the range of the analog inputs
int analogValue1 = 1; // variable to store the value coming from the on/off switch

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

void setup() {
// initialize all the LED pin as an output:
pinMode(ledPinss, OUTPUT);
pinMode(ledPinnf, OUTPUT);
pinMode(ledPinprg, OUTPUT);
pinMode(ledPinstg1, OUTPUT);
pinMode(ledPinstg2, OUTPUT);
pinMode(ledPinfp, OUTPUT);
pinMode(ledPinsprk, OUTPUT);
pinMode(analogPinss, INPUT);
pinMode(analogPinflm, INPUT);
digitalWrite(analogPinss, LOW); // turn off pull down resistor
digitalWrite(analogPinflm, LOW); //turn off pull down resistor

//initialize serial communications:
Serial.begin(9600);
;

}

void loop() {

// read the value of the Flame sensor:
int analogValue1 = analogRead(analogPinss); //on oss switch, system start
int analogValue2 = analogRead(analogPinflm); // if the analog value 2 is low, LED off:

{
if (analogValue2 < threshold)
{
digitalWrite(ledPinnf, HIGH); //turn on no flame LED: note this is backwards

}
else {
digitalWrite(ledPinnf, LOW); //turn no flame LED on Note this is backwards

digitalWrite(ledPinprg, HIGH);
delay (8000); //purge on time 8 seconds
digitalWrite(ledPinprg, LOW); //turn purge timer off

//need to break program so that code below runs and skips upper code Big problem area
}
}
//start new program, searching for flame
{
while(analogValue2 < threshold)

digitalWrite(ledPinfp, HIGH);
digitalWrite(ledPinsprk, HIGH);
digitalWrite(ledPinstg1, HIGH);
delay (5000);
if (analogValue2 > threshold)
while(1) {
}

if (analogValue2 < threshold)
digitalWrite(ledPinstg2, HIGH);
}

// print the analog value:
Serial.println(analogValue2);

}
http://:)\

kpar: :) THis is my problem., I have a conflicting requirement. I must do the following: 1 CHeck that no flame sensor is good---IE sensor must read no flame 2 then I can start my program and wait for flame sensor to detect flame (IE no flame) and allow to run if I have flame detection 3. If no flame detection shiut off 4 If and after program starts I look at the flame sensor and if detects no flame I shut off permenantly This is conflicitng stuff. I did not know if the go to function would help here? I am new to C++

1 Look up 'state machine'. 2 Post code using the hash button above the input box.

Thanks Henry, I a rewriting the code using the states to break up the conflicts. I am old school and used to the old basic box system with go to's.

kpar: Thanks Henry, I a rewriting the code using the states to break up the conflicts. I am old school and used to the old basic box system with go to's.

I too started with BASIC but soon got into Assembly language. Until the idea of the State Machine was pointed out to me, I too would have tried (and failed) your original method. Good luck with the rewrite. Let us know how you got on.