#include "OneWire.h"
#include "DallasTemperature.h"
#define ONE_WIRE_BUS 0 //Define the pin of the DS18B20
int fanPWMpin = 0; //Define the pin of the Fan
const int HtempMin = 97.0; //Define temp when heatsink fan starts
const int HtempMax = 100.0; //Define temp when heatsink fan is 100%
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
void checkTemp()
{
sensors.requestTemperatures(); // Send the command to get temperatures
delay(250);
float temp1=0, temp2=0;
//lcd.setCursor(2, 1);
//lcd.print("Tank Temp: ");
temp1= sensors.getTempFByIndex(0);
//lcd.print(sensors.getTempFByIndex(0));
//lcd.print((char)223);
//lcd.print("F");
//lcd.setCursor(13, 1);
//lcd.print("Led Temp:");
temp2= sensors.getTempFByIndex(1);
//lcd.print(sensors.getTempFByIndex(1));
//lcd.print((char)223);
//lcd.print("F");
if (temp1<0) temp1=0; //if sensor not connected reading is -127 deg
else if (temp1>99) temp1=99;
if (temp2<0) temp2=0;
else if (temp2>99) temp2=99;
int tempval = int(temp2*10);
int fanSpeed = map(tempval, (HtempMin*10), (HtempMax*10), 0, 255); //---------heatsink fan control
if (fanSpeed<=0)
fanSpeed = 0;
if (fanSpeed>255)
fanSpeed=255;
analogWrite(fanPWMpin, fanSpeed);
// Serial.println(fanSpeed);
}
void setup() {
sensors.begin(); // Start up the DS18B20 Temp library
pinMode(fanPWMpin, OUTPUT);
}
void loop()
{
checkTemp();
}