Hi,
I'm a newby with programming and now am fiddling for days with the following.
I want a fancontroller pwm that goes faster when it's closer to the maximum temperature.
Buy in my sketch the fan speed don't go past 50%.
Hopefully somebody can help me.
My code is:
/**
* ReadSHT1xValues
*
* Read temperature and humidity values from an SHT1x-series (SHT10,
* SHT11, SHT15) sensor.
*
* Copyright 2009 Jonathan Oxer <jon@oxer.com.au>
* www.practicalarduino.com
*/
#include <SHT1x.h>
// Specify data and clock connections and instantiate SHT1x object
#define dataPin 10
#define clockPin 11
SHT1x sht1x(dataPin, clockPin);
int tempMin = 22;
int tempMax = 24;
int alertLed = 8;
int fanSpeed;
int fanLCD;
int fan = 9;
void setup()
{
Serial.begin(9600); // Open serial connection to report values to host
Serial.println("Starting up");
}
void loop()
{
float temp_c;
float temp_f;
float humidity;
pinMode(alertLed, OUTPUT);
pinMode (fan, OUTPUT);
// Read values from the sensor
temp_c = sht1x.readTemperatureC();
if (temp_c < tempMin) {
fanSpeed = 0;
digitalWrite(fan, 0);
}
if((temp_c >= tempMin) && (temp_c <= tempMax))
{
fanSpeed = map(temp_c, tempMin, tempMax, 32, 255); // the actual speed of fan
fanLCD = map(temp_c, tempMin, tempMax, 0, 100); // speed of fan to display on LCD
analogWrite(fan, fanSpeed); // spin the fan at the fanSpeed speed
}
if(temp_c > tempMax)
{
digitalWrite(alertLed, HIGH);
}
else {
digitalWrite(alertLed, LOW);
}
Serial.print("TEMP: ");
Serial.print(temp_c); // display the temperature
Serial.print("C ");
Serial.print("FANS: ");
Serial.print(fanLCD); // display the fan speed
Serial.println("%");
Serial.print(fanSpeed);
delay(200);
delay(2000);
}
If this is working i will try so start fan at 30% even when it's lower than the minimum temperature.