Make green LED continously ON and stop only after button pressed.

Im basically try to make the green LED to be continously ON even though the valA5 no longger 80. Geen LED will off when button press. I try using do-while loop. But after that cannot read valA5. Is there any other way?

int greenLed = 12;
int smokeA5 = A5;
// Threshold value
int sensorThres = 80;

void setup() {
  pinMode(greenLed, OUTPUT);
  pinMode(smokeA5, INPUT);
  Serial.begin(9600);
}

void loop() {
  int valA5 = analogRead(smokeA5);
  if (valA5 < sensorThres)
  {
    digitalWrite(greenLed, HIGH);
  }
  else
  {
    digitalWrite(greenLed, LOW);
  }
  Serial.print("Smoke level: ");
  Serial.println(valA5);
  delay(200);
}

Where is your Button? Connect a PSUH Button (K1) between DPin-2 and GND with internal pull-up resistor enabled. Now, keep polling the status of K1 for 'close condition' while keeping the greenLed at ON state depending on value of A5.

void loop()
{
    while(digitalRead(2), != LOW)
    {
             //put your codes here to ON/OFF greenLed depending on value of A5
    }
    digitalWrite(greenLed, LOW);
}

When the sensor goes over the threshold, set a flag (called say ledMustBeOn) as true. DO NOT have an else which sets the flag false if the sensor is under the threshold.

Then use that flag, not the sensor value, to on/off the led in an if, with the flag being true meaning on, else false means off. (That way, if the sensor goes below the threshold, the flag is still true, led still on.)

When you press the button, set the flag to false. Then the else of the same if as mentioned above will then turn the led off.

If you accidentally press the button while the sensor is still over the threshold, that will set the flag false, but it will get set back to true immediately when it re-reads the sensor, so no harm done.