View Single Post
Unread 01/20/2012, 09:26 PM   #911
saltydogaqua
Registered Member.
 
Join Date: Oct 2011
Posts: 28
Quote:
Originally Posted by Spuzzum View Post
I'm wanting to add a fan PWM function to the script, so instead of just on/off according to the temperature, it speeds up/slows down as needed instead.

Was hoping someone can point me to an example script.


Thanks...

Code:
#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();

}



saltydogaqua is offline   Reply With Quote