Go Down

Topic: Dual tmp36 (Read 844 times) previous topic - next topic

Braindg

Jun 23, 2012, 12:41 am Last Edit: Jun 23, 2012, 01:07 am by Braindg Reason: 1
Hi all,

I've been looking online for a guide to running dual tmp36, with little success.

Could someone please point me in the direction of a article explaining how this can be achieved?

basicially i need two tmp36 to trigger a LED once they both hit a threshold.

I tried the following but it doesnt appear to be working.


Code: [Select]

int tempIn2 = 2;       
int tempIn3 = 3;       
int ledOut = 52;       
int aiValue = 0;
float setPoint2 = 24;
float setPoint3 = 25;
float deadband2 = 0.5;
float deadband3 = 0.5;

float degC;         
void setup()
{
  pinMode(ledOut, OUTPUT);   
  Serial.begin(9600);
}
void loop()
{

  degC = getTemperature(getVolts());   
   
  if ((degC > setPoint2) && (degC > setPoint3))
  {
    digitalWrite(ledOut, HIGH);     
    Serial.println(" | Output: ON.");
  }
  else
  {
      if ((degC < (setPoint2 - deadband2)) && (degC < (setPoint3 - deadband3)))
      {
      digitalWrite(ledOut, LOW);     
      Serial.println(" | Output: OFF.");
      }
  }   
  delay(1000);
}

float getVolts()
{
  int inputValue2;
    int inputValue3;
  inputValue2 = analogRead(tempIn2);
    inputValue3 = analogRead(tempIn3);
  float volts2;
    float volts3;
  volts2 = (((float)inputValue2 / 1024) * 5);
  volts3 = (((float)inputValue3 / 1024) * 5);
 
  Serial.print("Input Value2: ") ; Serial.print(inputValue2);
Serial.print("Input Value3: ") ; Serial.print(inputValue3);
  return volts2;
  return volts3;
}

float getTemperature(float volts2)
{
  float temp2 = (volts2 - 0.5) / 0.01 ;
 
  Serial.print(" | Temperature2: "); Serial.print(temp2); Serial.print(" 'C");
 
  return temp2;
}





Thanks
B

SimpleMindedMan

Please use code tags, oh and why run dual TMP's?

Braindg

New day, fresh thoughts..

Rewrote the code to make it a little more logical, seems to be working now - have i done it right or can it be omptimised?

Code: [Select]


int tempInpin2 = 2;     
int tempInpin3 = 3;       
int ledOut = 52;       
int aiValue = 0;
float setPointpin2 = 24;
float setPointpin3 = 25;
float deadbandpin2 = 0.5;
float deadbandpin3 = 0.5;

float degCpin2;
float degCpin3;
void setup()
{
  pinMode(ledOut, OUTPUT);
  Serial.begin(9600);
}
void loop()
{

  degCpin2 = getTemperaturepin2(getVoltspin2());
  degCpin3 = getTemperaturepin3(getVoltspin3());
   
  if ((degCpin2 > setPointpin2) && (degCpin3 > setPointpin3))
  {
    digitalWrite(ledOut, HIGH);   
    Serial.println(" | LED: ON.");
  }
  else
  {
      if ((degCpin2 < (setPointpin2 - deadbandpin2)) && (degCpin3 < (setPointpin3 - deadbandpin3)))
      {
      digitalWrite(ledOut, LOW);       
      Serial.println(" | LED: OFF.");
      }
  }   
  delay(1000);
}

float getVoltspin2()
{
  int inputValuepin2;
  inputValuepin2 = analogRead(tempInpin2);

  float voltspin2;

  voltspin2 = (((float)inputValuepin2 / 1024) * 5);

  Serial.print("Input Value PIN2: ") ; Serial.print(inputValuepin2);

  return voltspin2;

}

float getVoltspin3()
{

    int inputValuepin3;

    inputValuepin3 = analogRead(tempInpin3);

    float voltspin3;
  voltspin3 = (((float)inputValuepin3 / 1024) * 5);
 
Serial.print("Input Value PIN3: ") ; Serial.print(inputValuepin3);

  return voltspin3;
}

float getTemperaturepin2(float voltspin2)
{
  float temppin2 = (voltspin2 - 0.5) / 0.01 ;
 
  Serial.print(" | Temperature PIN2: "); Serial.print(temppin2); Serial.print(" 'C ");
 
  return temppin2;
}
float getTemperaturepin3(float voltspin3)
{
  float temppin3 = (voltspin3 - 0.5) / 0.01 ;
 
  Serial.print(" | Temperature PIN3: "); Serial.print(temppin3); Serial.print(" 'C ");
 
  return temppin3;
}




SimpleMindedMan

Trying to understand something. Why did you number every variable? for example:
int tempInpin2 = 2;     
int tempInpin3 = 3;
float setPointpin2 = 24;
float setPointpin3 = 25;
float deadbandpin2 = 0.5;
float deadbandpin3 = 0.5;

I understand why you would have the second one of each one of these numbered, but not the first. Unless you forgot to add code.

It seems clean enough. You could look into shrinking/modifying your code to run more efficiently, though I don't know how to.

What exactly are you trying to accomplish with the deal TMP's though?

Braindg

Hi,  thanks for the reply.

Well tbh, bit of a newbie and for me it seemed more logical to numer everything depending on which pin the temperature sensor was in, so I didn't get confused - later on I suppose I can rewrite it?  

Well, what I need to achieve with havin two (more to be included in future) is to trigger a relay which will activate a water sprayer on my intercooler.

So if both temps hit a threshold, relay is activated an then the water will be sprayed on my intercooler, helping to cool and this produce more BHP.

I have a main thread about this of you follow my profile.

http://arduino.cc/forum/index.php/topic,107198.msg804693.html#msg804693

Go Up