Forum Software Ferduino code Add fan to enclosure

Add fan to enclosure  [SOLVED]


Post Number:#1 Post Thu Feb 19, 2015 7:03 pm
Posts: 61
Topics: 11
Solve rating: 1
Joined: Thu Aug 28, 2014 9:27 am
Topics: 11
Age: 43
Location: England
Gender: Male
National Flag:
Great Britain
Moved from: viewtopic.php?f=8&t=151

Hi, Sorry to hijack this thread, I am trying to follow this but am struggling as I know very little about coding. I am still learning but this is beyond me ~x(

I am trying to do a very similar thing but using the ambient temp sensor as that is my controller enclosure temp and I want to control the fan that keeps the enclosure cool when it gets too hot (led drivers are also in the enclosure so it may get hot in there)

This is what I have so far but not sure if its enough

In Ferduino_with_webcontrol_beta
const byte desativarFanPin = 1;   // Pino que desativa os coolers.
const byte desativarFanPinA = 7;   // Pino que desativa os coolers.

//*****************************************************************************************
//*********************** Variáveis de controle da temperatura do dissipador **************
//*****************************************************************************************
float tempH = 0;    // Temperatura do dissipador
float tempA = 0;    // Temperatura do dissipador
byte tempHR = 60;   // Temperatura para reduzir potência dos leds
byte potR = 30;     // Porcentagem a ser reduzida.

//*****************************************************************************************
//*********** Variáveis temporárias de controle da temperatura do dissipador **************
//*****************************************************************************************
float temperatura_dissipador_temp = 0; // Temperatura temporária
float temperatura_ambiente_temp = 0; // Temperatura temporária
byte tempHR_t = 0;                     // Temperatura temporária para reduzir potência dos leds
byte potR_t = 0;                       // Porcentagem temporária a ser reduzida.
boolean temperatura_alta = false;      // Sinaliza que a temperatura dos leds está alta.
boolean temperatura_baixou = false;    // Sinaliza que a temperatura dos leds esteve alta.


In tab Inicio
myGLCD.setColor(0, 255, 0); 
  myGLCD.printNumF(tempH, 2, 316, 14);   // Temperatura dissipador
  myGLCD.printNumF(tempA, 2, 316, 14);   // Temperatura dissipador
  myGLCD.printNumF(tempC, 2, 302, 28);   // Temperatura da agua
  myGLCD.printNumF(PHA, 2, 327, 42);     // PH aqua
  myGLCD.printNumF(PHR, 2, 316, 56);    // PH reator
  myGLCD.printNumI(DEN, 293, 70);        // Densidade
  myGLCD.printNumI(ORP, 245, 84);       // ORP
  myGLCD.printNumF(tempA, 2, 312, 195);  // Temperatura ambiente


In leds
  if((tempH >= tempHR) || (tempA >= tempHR) )
  {
    reduzir = (1 - (potR *.01));
    temperatura_alta = true;
    temperatura_baixou = false;
  }
  if(temperatura_alta == true)
  {
    if((tempH <= (tempHR - 5)) && (tempA <= (tempHR - 5))) // Se a temperatura estiver 5°C abaixo do especificado a potência volta ao valor normal.   
    {
      reduzir = 1.00;
      temperatura_alta = false;
      temperatura_baixou = true;
    }
    else
    {
      reduzir = (1 - (potR *.01));
      temperatura_baixou = false;   
    }
  }   


In parametros
if(tempH < HtempMin) // Desativa os coolers se a temperatura estive abaixo da mínima definida.
  {
    digitalWrite(desativarFanPin, LOW);
  }
  else
  {
    digitalWrite(desativarFanPin, HIGH);
  }
  if(tempA < HtempMin) // Desativa os coolers se a temperatura estive abaixo da mínima definida.
  {
    digitalWrite(desativarFanPinA, LOW);
  }
  else
  {
    digitalWrite(desativarFanPinA, HIGH);
  }


Not sure if I need Fanspeed 1 & 2 or not.

Otherwise, how does this look to you :D

Guy

Post Number:#2 Post Thu Feb 19, 2015 8:10 pm
Posts: 1699
Topics: 38
Images: 301
Solve rating: 233
Joined: Mon Mar 03, 2014 5:59 pm
Topics: 38
Age: 39
Location: São Paulo
Gender: Male
National Flag:
Brazil

Hi!

Your case is similar but different. =))

I don't know wich version you are using but, I'll give the code based in latest version available on Github.

Try this:

In the tab Ferduino_with_webcontrol_beta add:
const byte fanPinA = 7;
const byte desativarFanPinA = free pin;

float HtempMinA = 30.5; // You can change this value.
float HtempMaxA = 40.5; // You can change this value.
int fanSpeedA = 0;


In the tab "parametros" find:

 else
{
digitalWrite(desativarFanPin, HIGH);
}


Add after:

 tempval = int(tempA * 10);
fanSpeedA = map(tempval, (HtempMinA * 10), (HtempMaxA * 10), 0, 255);
if (fanSpeedA < 0)
{
fanSpeedA = 0;
}
if (fanSpeedA > 255)
{
fanSpeedA = 255;
}
analogWrite(fanPinA, fanSpeedA);
if(tempA < HtempMinA)
{
digitalWrite(desativarFanPinA, LOW);
}
else
{
digitalWrite(desativarFanPinA, HIGH);
}


Best regards.
Post your doubts on forum because it can help another user too. Just PM me for support if it's absolutely necessary.

Post Number:#3 Post Tue Feb 24, 2015 6:24 pm
Posts: 61
Topics: 11
Solve rating: 1
Joined: Thu Aug 28, 2014 9:27 am
Topics: 11
Age: 43
Location: England
Gender: Male
National Flag:
Great Britain
Hi Fernando,

Thank you so much for this help, I was hoping that I was close, but no... not this time :))

Can I just check the following bit

tempval = int(tempA * 10);


should it be

int tempval = int(tempA * 10);


like it is in the below code?

int tempval = int(tempH * 10);


Thanks again

Post Number:#4 Post Tue Feb 24, 2015 6:42 pm
Posts: 1699
Topics: 38
Images: 301
Solve rating: 233
Joined: Mon Mar 03, 2014 5:59 pm
Topics: 38
Age: 39
Location: São Paulo
Gender: Male
National Flag:
Brazil

Hi!

Not, adding an "int" you are duplicating the variable in the function.

Try add debug messages like:

Serial.println(fanSpeedA);
Serial.println(digitalRead(fanPinA));


So, you can see if the problem is on code or circuit.

Best regards.
Post your doubts on forum because it can help another user too. Just PM me for support if it's absolutely necessary.

Post Number:#5 Post Tue Feb 24, 2015 6:44 pm
Posts: 61
Topics: 11
Solve rating: 1
Joined: Thu Aug 28, 2014 9:27 am
Topics: 11
Age: 43
Location: England
Gender: Male
National Flag:
Great Britain
Ignore that, sorry. You were right of course ^:)^




Return to Ferduino code





Who is online

Users viewing this topic: No registered users and 1 guest