Go Down

Topic: Love-o-meter (Read 1 time) previous topic - next topic

Lotaxi

Hi all,

  I'm trying to muddle my way through learning Arduino applications, so I bought the starter kit. Everything's been going swimmingly, but I can't seem to get the darn Love-o-meter to work. I can't figure out where the problem is. The TMP36 is correctly placed in my circuit, my coding looks fine, I'm getting a good temperature reading in the serial monitor, and I know the LED's are good (a direct connection lights them). The LED's just refuse to light when I try to use the temperature probe. Any tips?

My code is below, thanks in advance for any help provided

-Lotaxi

Code: [Select]
const int sensorPin = A0;
const float baselineTemp = 35;

void setup(){

  Serial.begin(9600);
  for(int pinNumber = 2; pinNumber>5; pinNumber++){
  pinMode(pinNumber, OUTPUT);
  digitalWrite(pinNumber, LOW);
  }
}

void loop(){
 
  int sensorVal = analogRead(sensorPin);
  Serial.print("Sensor value: ");
  Serial.print(sensorVal);
 
  float voltage = (sensorVal/1024.0) * 5.0;
  Serial.print(", Volts: ");
  Serial.print(voltage);
  Serial.print(", Degrees: ");
 
  float temperature = (voltage - .5) * 100;
  Serial.println(temperature);
 
  if(temperature < baselineTemp){
 
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
 
  }else if(temperature >= baselineTemp+2 && temperature < baselineTemp+4){
 
    digitalWrite(2, HIGH);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
 
  }else if(temperature >= baselineTemp+4 && temperature < baselineTemp+6){
 
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, LOW);
 
  }else if(temperature >= baselineTemp+6){
   
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
  }
 
  delay(1);
}

nass

Fwiw, my baseline temp was 20, 35 seems awfully high :)
Photography nut trying to make the flux capacitor of macro pho

BranchofLight

Code: [Select]
const int sensorPin = A0;
const float baselineTemp = 35;

// Excluded

  if(temperature < baselineTemp){
 
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
 
  }else if(temperature >= baselineTemp+2 && temperature < baselineTemp+4){
 
    digitalWrite(2, HIGH);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
 
  }else if(temperature >= baselineTemp+4 && temperature < baselineTemp+6){
 
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, LOW);
 
  }else if(temperature >= baselineTemp+6){
   
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
  }
 
  delay(1);
}



Because you are using an else-if the second block will not execute unless the first block is not true. You have an if statement checking if the temperature is less than the baseline. Since the temperature will almost always be lower than the baseline (because the baseline is 35 which is quite hot) all LEDs will almost always be set to LOW/off. If the temperature is equal to or greater than baseline the second block will be checked. In your case it will execute when the temperature is equal to or greater than the baseline+2 and less than the baseline+4. That means it will only execute if the temperature is 37 to 39 (non inclusive)! That's a pretty high temperature.

I would try turning down the baseline quite a bit and seeing if that works. Check your serial as you're testing and see where your temperature is falling and what blocks should be executing. Good luck!

Go Up