Arduino TMP gives 0

Hi all,

I've just started to use Arduino and i've found my first problem :confused: .
In particular I've completed the example which use the TMP sensor and I've encountered these problems:

  1. The lecture is incorrect (I' ve used the code reported in the book);

  2. When I use the sensor alone, without any other components attached to the breadboard, the sensor reads the zero value.

Have someone faced these problems.

Best,
Antonino

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:

Hi Tom,

Thank you for your answer and you advice.

This is my code

const int sensorPin = 1;
const float baselineTemp = 15;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  for( int pinNumber=2;pinNumber<5;pinNumber++){
    pinMode(pinNumber,OUTPUT);
    //digitalWrite(pinNumber,HIGH);
  }

}

void loop() {
  // put your main code here, to run repeatedly:
  int sensorVal = analogRead(sensorPin);
  Serial.print("Sensor Value: ");
  Serial.print(sensorVal);

  
  float voltage = (sensorVal/1024.0)*5.0;
  Serial.print(", Voltage = ");
  Serial.print(voltage);

  Serial.print(", degree C: ");
  float temperature = (voltage-0.5)/0.01;

 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(1000);
}

As regards the schematics, see the attached image which represents the case when I use only the sensor and not the Led. I’ve used the serial to read the Data.
I would try to invert the polarization but I’m afraid to damage the sensor.
Wha dos You think?

Best,

Antonino

The program is reading analog input 1, but your wiring is to analog input 0.

Sorry but a has been an error during the copy&paste.

The right code:

const int sensorPin = A0;
const float baselineTemp = 15;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  for( int pinNumber=2;pinNumber<5;pinNumber++){
    pinMode(pinNumber,OUTPUT);
    //digitalWrite(pinNumber,HIGH);
  }

}

void loop() {
  // put your main code here, to run repeatedly:
  int sensorVal = analogRead(sensorPin);
  Serial.print("Sensor Value: ");
  Serial.print(sensorVal);

  
  float voltage = (sensorVal/1024.0)*5.0;
  Serial.print(", Voltage = ");
  Serial.print(voltage);

  Serial.print(", degree C: ");
  float temperature = (voltage-0.5)/0.01;

 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(1000);
}

I add also some values of the output

Sensor Value: 44, Voltage = 0.21, degree C: -28.52
Sensor Value: 40, Voltage = 0.20, degree C: -30.47
Sensor Value: 41, Voltage = 0.20, degree C: -29.98
Sensor Value: 42, Voltage = 0.21, degree C: -29.49
Sensor Value: 42, Voltage = 0.21, degree C: -29.49
Sensor Value: 41, Voltage = 0.20, degree C: -29.98
Sensor Value: 41, Voltage = 0.20, degree C: -29.98
Sensor Value: 38, Voltage = 0.19, degree C: -31.45
Sensor Value: 42, Voltage = 0.21, degree C: -29.49
Sensor Value: 48, Voltage = 0.23, degree C: -26.56
Sensor Value: 44, Voltage = 0.21, degree C: -28.52
Sensor Value: 39, Voltage = 0.19, degree C: -30.96
Sensor Value: 36, Voltage = 0.18, degree C: -32.42
Sensor Value: 46, Voltage = 0.22, degree C: -27.54
Sensor Value: 49, Voltage = 0.24, degree C: -26.07
Sensor Value: 37, Voltage = 0.18, degree C: -31.93
Sensor Value: 41, Voltage = 0.20, degree C: -29.98
Sensor Value: 42, Voltage = 0.21, degree C: -29.49
Sensor Value: 41, Voltage = 0.20, degree C: -29.98
Sensor Value: 44, Voltage = 0.21, degree C: -28.52
Sensor Value: 43, Voltage = 0.21, degree C: -29.00

Scheme

  1. When I use the sensor alone, without any other components attached to the breadboard, the sensor reads the zero value.

Obviously, that is not correct, as was the code you posted.

If you want help, take the time to make sure you give forum members accurate information.

At this point, we can't believe anything you post.

Hi,
What is your "TMP"?
A part number please..

Tom... :slight_smile:

Are you sure this is a TMP36.
Posted temps seem for an LM35.

Need to use 1.1volt Aref, and maybe even smoothing/averaging to get a stable temp.
Try this sketch first to see if you can get temps right.
Leo…

// LM35_TMP36 temp
// connect LM35 to 5volt A0 and ground
// connect TPM36 to 3.3volt A0 and ground
// calibrate temp by changing the last digit(s) of "0.1039"

float tempC; // Celcius
float tempF; // Fahrenheit

void setup() {
  analogReference(INTERNAL); // use internal 1.1volt Aref
  Serial.begin(9600);
}

void loop() {
  //tempC = ((analogRead(A0) * 0.1039)); // uncomment this line for an LM35
  //tempC = ((analogRead(A0) * 0.1039) - 50.0); // uncomment this line for a TMP36
  tempF = tempC * 1.8 + 32.0; // C to F
  Serial.print("Temperature is  ");
  Serial.print(tempC, 1); // one decimal place
  Serial.print(" Celcius  ");
  Serial.print(tempF, 1);
  Serial.println(" Fahrenheit");

  delay(1000); // use a non-blocking delay when combined with other code
}

Hi Leo,

thank you for your code.

However results are similar.

Temperature is -50.0 Celcius -58.0 Fahrenheit
Temperature is -45.5 Celcius -50.0 Fahrenheit
Temperature is -49.8 Celcius -57.6 Fahrenheit
Temperature is -49.5 Celcius -57.1 Fahrenheit
Temperature is -49.4 Celcius -56.9 Fahrenheit
Temperature is -49.0 Celcius -56.1 Fahrenheit
Temperature is -49.5 Celcius -57.1 Fahrenheit
Temperature is -49.5 Celcius -57.1 Fahrenheit
Temperature is -49.4 Celcius -56.9 Fahrenheit
Temperature is -46.9 Celcius -52.4 Fahrenheit
Temperature is -48.8 Celcius -55.8 Fahrenheit
Temperature is -49.5 Celcius -57.1 Fahrenheit
Temperature is -49.7 Celcius -57.4 Fahrenheit
Temperature is -49.1 Celcius -56.3 Fahrenheit
Temperature is -49.8 Celcius -57.6 Fahrenheit
Temperature is -48.6 Celcius -55.6 Fahrenheit

Did you uncomment the correct line for the sensor you're using (which one?).

If my code doesn't work then there could be a hardware problem (wiring, breadboard, fake sensor).
Post a real picture of the setup.
Leo..

The sensor is a TMP 36GZ

jremington:
Obviously, that is not correct, as was the code you posted.

If you want help, take the time to make sure you give forum members accurate information.

At this point, we can’t believe anything you post.

I’ve give this informations as surplus information because i’ve noticed this effect during removing the Led from the bread board. I think the code works correctly also without the attached LED which are turned on based on the value from the sensor.

A TMP36GZ should have 0.75volt (750mV) on it's output at a temp of 25C.
Maybe you could measure that with a DMM.

Raw A/D value should be ~153 at that temp with your sketch (not 40-ish).
Check/replace wiring and breadboard, and upload the picture requested.
Leo..

Hi,

AntoninoMasaracchia:
The sensor is a TMP 36GZ
I think the code works correctly also without the attached LED which are turned on based on the value from the sensor.

LED ? ? ?
What LED in your circuit?
Does it have a series current limit resistor and is it connected the right way.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Can you please post a picture of your project?
So we can see your component layout.
Thanks.. Tom... :slight_smile:

Hi, I start again from the beginning :wink:

Attached to this post there is the Scheme from which I’ve started (Scheme.jpg).
The sensor is a TMP 36GZ

The code that I’ve used is:

const int sensorPin = A0;
const float baselineTemp = 13;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  for( int pinNumber=2;pinNumber<5;pinNumber++){
    pinMode(pinNumber,OUTPUT);
    //digitalWrite(pinNumber,HIGH);
  }

}

void loop() {
  // put your main code here, to run repeatedly:
  int sensorVal = analogRead(sensorPin);
  Serial.print("Sensor Value: ");
  Serial.print(sensorVal);

  
  float voltage = (sensorVal/1024.0)*5.0;
  Serial.print(", Voltage = ");
  Serial.print(voltage);

  Serial.print(", degree C: ");
  float temperature = (voltage-0.5)/0.01;

 Serial.println(temperature);

 if(temperature< baselineTemp){
  //Serial.println("minore di baseline");
  digitalWrite(2,LOW);
  digitalWrite(3,LOW);
  digitalWrite(4,LOW);
 }
 else if(temperature>= baselineTemp +2 && temperature <baselineTemp+4){
  //Serial.println("temperature>= baselineTemp +2 && temperature <baselineTemp+4");
  digitalWrite(2,HIGH);
  digitalWrite(3,LOW);
  digitalWrite(4,LOW);
  
 }
else if(temperature>= baselineTemp +4 && temperature <baselineTemp+6){
  //Serial.println("temperature>= baselineTemp +4 && temperature <baselineTemp+6");
  digitalWrite(2,HIGH);
  digitalWrite(3,HIGH);
  digitalWrite(4,LOW);
  
 }
 else if(temperature>= baselineTemp+ 6){
  //Serial.println("temperature>= baselineTemp+ 6");
  digitalWrite(2,HIGH);
  digitalWrite(3,HIGH);
  digitalWrite(4,HIGH);
  
 }

 delay(1000);
}

In this configuration I read these values:

Sensor Value: 135, Voltage = 0.66, degree C: 15.92
Sensor Value: 135, Voltage = 0.66, degree C: 15.92
Sensor Value: 135, Voltage = 0.66, degree C: 15.92
Sensor Value: 135, Voltage = 0.66, degree C: 15.92
Sensor Value: 135, Voltage = 0.66, degree C: 15.92
Sensor Value: 134, Voltage = 0.65, degree C: 15.43
Sensor Value: 134, Voltage = 0.65, degree C: 15.43
Sensor Value: 134, Voltage = 0.65, degree C: 15.43
Sensor Value: 134, Voltage = 0.65, degree C: 15.43
Sensor Value: 134, Voltage = 0.65, degree C: 15.43
Sensor Value: 134, Voltage = 0.65, degree C: 15.43
Sensor Value: 134, Voltage = 0.65, degree C: 15.43
Sensor Value: 134, Voltage = 0.65, degree C: 15.43
Sensor Value: 134, Voltage = 0.65, degree C: 15.43
Sensor Value: 134, Voltage = 0.65, degree C: 15.43

Then I’ve removed some connection in order to obtain the Scheme in which there are only the connections to the sensor.
By using the same code in that configuration I read these values

Sensor Value: 130, Voltage = 0.63, degree C: 13.48
Sensor Value: 132, Voltage = 0.64, degree C: 14.45
Sensor Value: 129, Voltage = 0.63, degree C: 12.99
Sensor Value: 129, Voltage = 0.63, degree C: 12.99
Sensor Value: 129, Voltage = 0.63, degree C: 12.99
Sensor Value: 129, Voltage = 0.63, degree C: 12.99
Sensor Value: 129, Voltage = 0.63, degree C: 12.99
Sensor Value: 129, Voltage = 0.63, degree C: 12.99
Sensor Value: 129, Voltage = 0.63, degree C: 12.99
Sensor Value: 129, Voltage = 0.63, degree C: 12.99
Sensor Value: 130, Voltage = 0.63, degree C: 13.48
Sensor Value: 129, Voltage = 0.63, degree C: 12.99
Sensor Value: 129, Voltage = 0.63, degree C: 12.99
Sensor Value: 129, Voltage = 0.63, degree C: 12.99
Sensor Value: 120, Voltage = 0.59, degree C: 8.59
Sensor Value: 114, Voltage = 0.56, degree C: 5.66
Sensor Value: 113, Voltage = 0.55, degree C: 5.18
Sensor Value: 109, Voltage = 0.53, degree C: 3.22
Sensor Value: 90, Voltage = 0.44, degree C: -6.05
Sensor Value: 84, Voltage = 0.41, degree C: -8.98
Sensor Value: 5, Voltage = 0.02, degree C: -47.56
Sensor Value: 2, Voltage = 0.01, degree C: -49.02
Sensor Value: 2, Voltage = 0.01, degree C: -49.02
Sensor Value: 1, Voltage = 0.00, degree C: -49.51
Sensor Value: 0, Voltage = 0.00, degree C: -50.00
Sensor Value: 11, Voltage = 0.05, degree C: -44.63
Sensor Value: 0, Voltage = 0.00, degree C: -50.00
Sensor Value: 1, Voltage = 0.00, degree C: -49.51
Sensor Value: 4, Voltage = 0.02, degree C: -48.05
Sensor Value: 0, Voltage = 0.00, degree C: -50.00

As you can seen I’ve posted the evolution process.

I hope that now my explanation is more clear.

Thai you again for your comprehension.

Why do you keep on posting useless Fritzing pictures.
They only show what is should be, not what it is.
Leo..

Wawa:
Why do you keep on posting useless Fritzing pictures.
They only show what is should be, not what it is.
Leo…

Attached there is the image of the circuit

Thanks for posting the image. Seems to be wired ok.
If the wires are properly inserted, and it doesn't work with my code, then the sensor must be faulty.
You can still try if a 100n capacitor from 5volt to ground, close to the sensor, fixes the problem (sensor datasheet calls for one).
If not, ditch the sensor, and use a digital DS18B20 temp sensor.
Leo..

Thank you Leo.
I will try with the capacitor and I will Update you.
Thank you Again