Go Down

Topic: Project 3 Love-o-meter: TMP doesn't seem to work (Read 14815 times) previous topic - next topic

rsub

So I am having a problem in this project with the TMP temperature input that is used.  Every time I open the serial monitor, the first value for temperature I get is very low and random. Each value after that is always -50.0, and the sensor value (out of 1023) is 0.  And when I tried to put my finger around the sensor, the readings did not change. Is my TMP not working, or is there another issue I am overlooking?

I believe that the program I wrote is the same as the one written in the kit's book, but I'm not sure, so I will post it below.





const int sensorPin = A0;
const float baselineTemp = 20.0;

void setup(){
  Serial.begin(9600);
  for(int pinNum = 2; pinNum < 5; pinNum++){
    pinMode(pinNum, OUTPUT);
    digitalWrite(pinNum, 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);
  float temp = (voltage - .5)*100;
  Serial.print(", degrees C: ");
  Serial.println(temp);
  if(temp < baselineTemp){
    digitalWrite(2,LOW);
    digitalWrite(3,LOW);
    digitalWrite(4,LOW);
  }else if (temp >= baselineTemp+2 && temp < baselineTemp+4){
    digitalWrite(2,HIGH);
    digitalWrite(3,LOW);
    digitalWrite(4,LOW);
  }else if(temp >= baselineTemp+4 && temp < baselineTemp+6){
    digitalWrite(2,HIGH);
    digitalWrite(3,HIGH);
    digitalWrite(4,LOW);
  }else{
    digitalWrite(2,HIGH);
    digitalWrite(3,HIGH);
    digitalWrite(4,HIGH);
  }
  delay(1000);
}

bobmon

I would suspect a wiring error.  Nothing obvious jumps out about your code.

If you replace the temperature sensor with a potentiometer, can you see the readings change?

blairSharpe

Hey did you ever get this working? because I am having the exact same problems as you are. If you did please tell me what you did.

Fabio881

#3
Jul 23, 2014, 12:06 pm Last Edit: Jul 23, 2014, 12:08 pm by Fabio881 Reason: 1
Hi guys!

If you are both (still) experiencing the same problem, I would also start checking for basic wiring issues: the code itself is quite simple, and very similar to what I also used (and which worked).
In particular, the fact that the problem already appears here:

Code: [Select]
int sensorVal = analogRead(sensorPin);

tells you already where to start looking at.
Is the TMP sensor really connected to pin A0 on the Arduino, as declared in the code? Are the connections done properly? (check the datasheet - be aware that the schematic view is from the bottom).
To prove that the component itself has problem, a nice way is to substitute it with a potentiometer, as suggested by the user here above.

Hope it helps a bit

chummer1010

I had similar issues as you. I didn't see anything wrong with the code. What I did is put the baselineTemp to whatever temperature it was in the room. For example:

Code: [Select]
const float baselineTemp 24.8889

Also, I found out that the original delay (delay(1) is too quick and gives an inaccurate reading, so I gave it a delay(1000).
Code: [Select]
#include <cheesy.quote>

Go Up