Hi,
For my project, I am coding a temperature sensor that alerts when a certain temperature is reached. (As seen on code attached).
Though, I am interested in triggering the buzzer at different intervals. For example, 2 buzzes when the temperature has reached 27 degrees then it stops until 30 degrees is reached in which there will be 3 buzzes etc.
Though, i have tried to use 'if statements' and have not come out successful.
Would anyone know how to go about this?
Any help would be appreciated !!!
Thankyou, Tegan 
tempsensor1.ino (702 Bytes)
You will get more and faster help if you post your code so that members do not have to download it. See the how to use this forum-please read sticky.
Hi,
For my project, I am coding a temperature sensor that alerts when a certain temperature is reached. (As seen on code below).
float temp;
int buzzerPin = 8;
void setup()
{
pinMode(buzzerPin,OUTPUT);//Initialise the buzzerPin as an output
pinMode(A0,INPUT);
Serial.begin (9600) ; // put your setup code here, to run once:
}
void loop()
{
temp = analogRead (A0) ; //read the value from the sensor
temp = temp * 0.048828125 ;
Serial.print ( "TEMPERATURE: ") ; //prints temperature in serial monitor
Serial.print (temp) ;
Serial.print ("*C") ;
Serial.println () ;
delay (1000) ; // put your main code here, to run repeatedly:
if (temp >= 26.0) { //DON'T FORGET TO CHANGE TO 42 FOR APRON
digitalWrite(buzzerPin, HIGH);
tone(buzzerPin, 1500, 1000); delay(150);
}
else
{
digitalWrite (buzzerPin, LOW);
}
}
Though, I am interested in triggering the buzzer at different intervals. For example, 2 buzzes when the temperature has reached 27 degrees then it stops until 30 degrees is reached in which there will be 3 buzzes etc.
Though, i have tried to use 'if statements' and have not come out successful.
Would anyone know how to go about this?
Any help would be appreciated !!!
Thankyou, Tegan 
@teganko, please do not cross-post. Threads merged.
Serial.print ( "TEMPERATURE: ") ; //prints temperature in serial monitor
That is NOT what that code does.
delay (1000) ; // put your main code here, to run repeatedly:
Another completely stupid comment.
if (temp >= 26.0) { //DON'T FORGET TO CHANGE TO 42 FOR APRON
And another one.
Though, i have tried to use 'if statements' and have not come out successful.
You never will be, until you can detect when the temperature BECOMES 27 degrees, or 30 degrees.
You can't detect when the temperature becomes some value when the only thing you know is the current value.
The state change detection example bears viewing.