#include <OneWire.h>
#include <DallasTemperature.h>
int led = 8;
#define buzzer 9
int zaman = 50;
float a=0;
float b=0;
// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 4
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
void setup(void)
{
// Start serial communication for debugging purposes
pinMode(led,OUTPUT);
pinMode(buzzer,OUTPUT);
Serial.begin(9600);
// Start up the library
sensors.begin();
}
void loop(void){
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
float a = sensors.getTempCByIndex(0);
float b = sensors.getTempFByIndex(0);
temperature();
Serial.print("Celsius temperature: ");
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.print(a);
Serial.print(" - Fahrenheit temperature: ");
Serial.println(b);
delay(500);
}
void temperature()
{
if(a >= 30){
digitalWrite(led,HIGH);
digitalWrite(buzzer,HIGH);
delay(zaman);
}
else{
digitalWrite(led,LOW);
digitalWrite(buzzer,LOW);
}
}