Arduino Infinity Loop I'm new to this Arduino programming. So I want to ask about my current project. My lecturer told me to make a temperature sensor using an LM35, where a green LED will light up when below some certain temperature that I set. The same goes for yellow and red LEDs for medium, and high temperatures. The tricky part here is that I need to make sure my buzzer (piezo) is on forever if it reaches the high temperature, until I press a button to reset it.

This is my coding so far:

const int greenLed = 3;
const int redLed = 4;
const int yellowLed = 5;
float tempC;
int reading;
int tempPin = 0;
int speakerOut = 11;
const int buttonPin = 2;     
int buttonState = 0;     
long duration = 10000;
int tempo = 0;

void setup() {
// initialize digital pin 13 as an output.
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(2, INPUT);
pinMode(11, OUTPUT);
analogReference(INTERNAL);
Serial.begin(9600);
}

// the loop function runs over and over again forever
void loop() {
buttonState = digitalRead(buttonPin);
reading = analogRead(tempPin);
tempC = reading / 9.31;
Serial.println(tempC);
delay(500);

if (tempC &lt; 30.00) {
//Serial.println("Temp LOW");
digitalWrite(3, HIGH);
delay(10);
}else {
digitalWrite(3,LOW);
delay(10);

}

if (31.00 &lt; tempC &lt; 33){
//Serial.println("Temp MED");
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
delay(50);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
delay(50);

}else {
digitalWrite(4,LOW);
digitalWrite(5,LOW);

}

if(tempC &gt;= 34){
**WHAT SHOULD I FILL UP HERE TO MAKE SURE MY PIEZO BUZZER ON FOREVER**
}
if(buttonState = 1);{
digitalWrite(11, LOW);
}


}

Any help would be great. Or if you have a better idea on how to do this, I'm gonna love it.
You can use the toneAC library, which allows even better handling of piezo speakers then the standard "tone"-functions.


  Features: Nearly twice the volume (because it uses two out of phase pins in push/pull fashion)
      Higher quality (less clicking)
      Capability of producing higher frequencies (even if running at a lower clock speed)
      Nearly 1.5k smaller compiled code
      Bug fixes (standard tone library can generate some odd and unpredictable results)
      Can set not only the frequency but also the sound volume
      Less stress on the speaker so it will last longer and sound better 


With the library you can do something like:

int freq = 1000
int vol = 10
int length = 0
boolean background = true

toneAC(freq, vol, length, background);


The tone now will play forever in the background, until you stop it with:

toneAC(0);