// Include the required Arduino libraries:
#include "OneWire.h"
#include "DallasTemperature.h"
// Define to which pin of the Arduino the 1-Wire bus is connected:
#define ONE_WIRE_BUS 2
// Create a new instance of the oneWire class to communicate with any OneWire device:
OneWire oneWire(ONE_WIRE_BUS);
// Pass the oneWire reference to DallasTemperature library:
DallasTemperature sensors(&oneWire);
int pin6=6;
int pin7=7;
int pin8=8;
//int tempread=8;
int pwmvalue;
int setTemp;
void setup() {
sensors.begin();
Serial.begin(9600);
pinMode(pin6, OUTPUT);
pinMode(pin7, INPUT_PULLUP);
pinMode(pin8, INPUT_PULLUP);
}
void loop() {
// Send the command for all devices on the bus to perform a temperature conversion:
sensors.requestTemperatures();
// Fetch the temperature in degrees Celsius for device index:
float tempC = sensors.getTempCByIndex(0); // the index 0 refers to the first device
if(digitalRead(pin7)==LOW)
{
setTemp=++setTemp;
delay(250);
}
if(digitalRead(pin8)==LOW)
{
setTemp=--setTemp;
delay(250);
}
if(tempC==setTemp)
{
digitalWrite(pin6, HIGH);
Serial.print("Set temp: ");
Serial.print(setTemp);
Serial.print(" ");
Serial.print("Temperature: ");
Serial.print(tempC);
Serial.print(" \xC2\xB0"); // shows degree symbol
Serial.print("C");
Serial.print(" ");
Serial.println("Set temp has been reached");
}
// Print the temperature in Celsius in the Serial Monitor:
if(tempC<setTemp)
{
digitalWrite(pin6, LOW);
Serial.print("Set temp: ");
Serial.print(setTemp);
Serial.print(" ");
Serial.print("Temperature: ");
Serial.print(tempC);
Serial.print(" \xC2\xB0"); // shows degree symbol
Serial.print("C");
Serial.print(" ");
Serial.println("Temp is below set temp");
}
if(tempC>setTemp)
{
digitalWrite(pin6, HIGH);
Serial.print("Set temp: ");
Serial.print(setTemp);
Serial.print(" ");
Serial.print("Temperature: ");
Serial.print(tempC);
Serial.print(" \xC2\xB0"); // shows degree symbol
Serial.print("C");
Serial.print(" ");
Serial.println("Temp is over set temp");
}
delay(500);
}