Pages: [1]   Go Down
Author Topic: Project 3 Love-o-meter: TMP doesn't seem to work  (Read 14491 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

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

Offline Offline
Newbie
*
Karma: 2
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
« Last Edit: July 23, 2014, 05:08:50 am by Fabio881 » Logged

New Paltz, NY
Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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).
Logged

youtube.com/codersworkshop123

Pages: [1]   Go Up
Jump to: