Newbie with code and thermistor problem!

Hello everybody :wink: ,

I want to do a automatic temp / fan controller for my PC. I know that the output from motorshield is only ~10.4v max with 12v due h-bridge but i’m gonna supply it with ~15v after everything is running.

i have a problem with my code, the fan don’t react with the temp and why the thermistor is sooo unaccuarte?

I’m working in this project with arduino uno R3, motorshield and LCD 16x2.

This is the code :

#include <LiquidCrystal.h>
#include <math.h>

LiquidCrystal lcd(6,5,4,2,1,0);

int tempMin = 10;
int tempMax = 20;
int fanSpeed;
int fanLCD;
int temp;
int val;
int fan = 3;

void setup() {
digitalWrite(12, HIGH);
digitalWrite(9, LOW);
lcd.begin(16,2);
}
double Thermister(int RawADC) {
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15;
return Temp;
}

void loop() {

if(temp < tempMin) {fanSpeed = 0;analogWrite(fan,0);}
if((temp >= tempMin) && (temp <= tempMax)){
fanSpeed = map(temp, tempMin, tempMax, 32, 255);
fanLCD = map(temp, tempMin, tempMax, 0, 100);
analogWrite(fan, fanSpeed);}

{double temp;
val=analogRead(2);
temp=Thermister(val);

lcd.print("Temp: ");
lcd.print(temp);
lcd.print("C ");
lcd.setCursor(0,1);
lcd.print(“FANS: “);
lcd.print(fanLCD);
lcd.print(”%”);
delay(2000);
lcd.clear();}

}

Thanks a lot!!!

Please use the CODE toolbutton ("<>") just to the left of the QUOTES button (dialog cloud symbol) to post
your code. Click the MORE button in the lower right and scroll down to the MODIFY button. Click on MODIFY, highlight your code and click the CODE button and then SAVE. Please use the CODE button in the
future.

I can’t comment on the code but I would venture to say that if you got that code from somewhere as opposed to writing it yourself then we will probably need a schematic of your circuit, handdrawn , and
photographed and posted as a photo attachement.

with 12v due h-bridge

I assume you meant to say “DUAL h-bridge” as the DUE is an arduino product. (are you French ?)

I’ll give you a little suggestions. Separate everything and test it individually. Come back and tell us that the fans work fine in standalone mode with the arduino connected to ONLY the fans.

Then do the same thing with the thermister. Use serial prints to the serial monitor

val=analogRead(2);
  temp=Thermister(val);

Run the thermister as a standalone device with nothing else connected to the arduino.
Use only the bare-bones basic standalone code for the standalone tests with no other code running.

Do the same for the Lcd. I assume that’s working fine since you didn’t mention it.

The thermister and fans are separate issues. I don’t think they are related. I don’t know yet until you
do your standalone tests. That’s your homework assignment. Come back and report the results.
And post the schematic.

first thing you should learn is to format your code so people can “read” it easier.

2nd using [code]...[/code] tags helps too.

#include <LiquidCrystal.h>
#include <math.h>

LiquidCrystal lcd(6, 5, 4, 2, 1, 0);

int tempMin = 10;
int tempMax = 20;
int fanSpeed;
int fanLCD;
int temp;
int val;
int fan = 3;

void setup()
{
  digitalWrite(12, HIGH);
  digitalWrite(9, LOW);
  lcd.begin(16, 2);
}

double Thermister(int RawADC)
{
  double Temp;
  Temp = log(((10240000 / RawADC) - 10000));
  Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp )) * Temp );
  Temp = Temp - 273.15;
  return Temp;
}

void loop()
{

  if (temp < tempMin)  // temp has no vlaue here !!!
  {
    fanSpeed = 0;
    analogWrite(fan, 0);
  }
  if ((temp >= tempMin) && (temp <= tempMax) )  // or here ...
  {
    fanSpeed = map(temp, tempMin, tempMax, 32, 255);
    fanLCD = map(temp, tempMin, tempMax, 0, 100);
    analogWrite(fan, fanSpeed);
  }
  {
    double temp;
    val = analogRead(2);
    temp = Thermister(val);

    lcd.print("Temp: ");
    lcd.print(temp);
    lcd.print("C ");
    lcd.setCursor(0, 1);
    lcd.print("FANS: ");
    lcd.print(fanLCD);
    lcd.print("%");
    delay(2000);
    lcd.clear();
  }
}

problem is that your variable temp is twice defined and only one changes value…

I'm just trying to follow along for learning purposes. Are you referring to "int temp" vs "double temp"
?

Can you single out the two definitions you are talking about ?