Pages: [1]   Go Down
Author Topic: Love-o-meter  (Read 1476 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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);
}
Logged

UK
Offline Offline
Jr. Member
**
Karma: 1
Posts: 62
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Fwiw, my baseline temp was 20, 35 seems awfully high smiley
Logged

Photography nut trying to make the flux capacitor of macro pho

ON, Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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!
Logged

Pages: [1]   Go Up
Jump to: