Equipments :
- LM35 Temperature Sensor pin
- Buzzer
- Arduino Uno
- Breadboard
- Jumper Wires
Arduino Code :
#include <TimerOne.h>
int lm35Pin = 0;
int buzzerPin = 3;
int duration=1000;
int frequency = 262;
float tempVal;
int val;
int flag = 0;
void setup(){
pinMode(buzzerPin, OUTPUT);
Timer1.initialize(500000);
Timer1.attachInterrupt(readTemp);
Serial.begin(9600);
}
void loop(){
if(val>10){
Serial.println("Temperature is to high, fire might be occured!!");
Serial.println(val);
buzz();
}
}
void readTemp(){
flag++;
if(flag==12){
tempVal = analogRead(lm35Pin);
val = tempVal/2;
// val = (5.0*100.0)/1024.0;
flag = 0;
Serial.print("Temp :");
Serial.println(val);
}
}
void buzz(){
for(int i = 0;i<4;i++){
tone(buzzerPin, frequency, duration/2);
delay(duration);
}
}
Hiç yorum yok:
Yorum Gönder