#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is connected to pin 2 on the Arduino
#define ONE_WIRE_BUS 12
const int led = 4;
const int Sled = 7;
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass the oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
void setup() {
// Start serial communication
pinMode(led, OUTPUT);
pinMode(Sled, OUTPUT);
Serial.begin(115200);
// Initialize the sensor
sensors.begin();
}
void loop() {
// Request temperature data from all devices on the bus
sensors.requestTemperatures();
// Get the temperature in Celsius
float temperatureC = sensors.getTempCByIndex(0);
// Print the temperature to the Serial Monitor
if(temperatureC > 4){
digitalWrite(led, HIGH);
digitalWrite(Sled, LOW);
}else{
digitalWrite(led, LOW);
digitalWrite(Sled, HIGH);
}
// Serial.print("Temperature: ");
Serial.print(temperatureC);
// Serial.println(" °C");
// Add a delay before the next reading
// delay(1000);
}