Do I have a bad temp sensor?

Just got an arduino starter kit and I'm going through some tutorials.. I'm doing this one now (LCD displaying temperature)..

When I get it all wired up and upload the code, the temperature keeps bouncing around 93-97* F.. It's about 74* F in my house..

Do I have a bad sensor or could I have wired something wrong??

Thanks so much!

TMP36 sensor? Do you have the same one?

How should we know if you wired it wrong? Please take a photo and post it.

float tempVolts = tempReading * 5.0 / 1024.0;

Adjust the "5.0" to the actual supply voltage of your Arduino.
It might be 4.95 or 5.07

Change slightly and re-upload untill the reading is accurate.

If your supply is USB only, it could bounce a lot.
Different supplies is different results.
Bad..

There is better code around that uses the internal reference voltage of the Arduino and smoothing.
Leo..

aarg:
TMP36 sensor? Do you have the same one?

How should we know if you wired it wrong? Please take a photo and post it.

Yes, the TMP36.. I didn't expect you to know if I wired it wrong, just didn't know if that was a possibility with the issue I was having.

Thanks for the reply.

Wawa:
float tempVolts = tempReading * 5.0 / 1024.0;

Adjust the "5.0" to the actual supply voltage of your Arduino.
It might be 4.95 or 5.07

Change slightly and re-upload untill the reading is accurate.

If your supply is USB only, it could bounce a lot.
Different supplies is different results.
Bad..

There is better code around that uses the internal reference voltage of the Arduino and smoothing.
Leo..

Yes, it's via USB and it bounces like crazy.. I'll look around for some other code. Thanks a lot for the reply.

Here is some working TMP35/LM35/TMP36 code I wrote for serial moitor and LCD shield. Temps in C and F.
Make sure you read the header how to change the sketch for the TMP36.
Set your serial monitor to the same speed as in the code.
LCD is optional. Pinout is for a common cheap shield.
Leo..

// TMP35 or TMP36 temp sensor connected to Analogue input A1, 3.3volt and ground
// or LM35 temp sensor connected to A1, 5volt and ground
// temp range ~2C to ~105C
// display on serial monitor and/or LCD
// for a TMP36 (-40C to ~55C), change line 45 to:   tempC = total * Aref * 0.1 / numReadings - 50.0;
//
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // your LCD pins could be different
byte ledPin = 10; // backlight pin
const byte numReadings = 25; // number of readings for smoothing (max 64)
int readings[numReadings]; // readings from the analog input
byte index = 0; // index of the current reading
unsigned int total = 0; // running total
int inputPin = A1; // the pin that the TMP35 is connected to
float Aref = 1.0759; // change this value to the actual Aref voltage of ---YOUR--- Arduino (1.0 - 1.2), or adjust to get accurate readings
float tempC; // Celcius
float tempF; // Fahrenheit

void setup() {
  //analogWrite(ledPin, 200); // optional dimming
  analogReference(INTERNAL); // use the internal ~1.1volt reference | change (INTERNAL) to (INTERNAL1V1) for a Mega
  Serial.begin(115200); // ---set serial monitor to this value---
  lcd.begin(16, 2); // shield with 2x16 characters
  lcd.print("Thermometer"); // info text
  lcd.setCursor(0, 1); // second row
  lcd.print("0-100 Celcius");
  for (index = 0; index < numReadings; index++) { // fill the array for faster startup
    readings[index] = analogRead(inputPin);
    total = total + readings[index];
  }
  index = 0; // reset
  delay(2000); // info display time
}

void loop() {
  total = total - readings[index]; // subtract the last reading
  readings[index] = analogRead(inputPin); // one unused reading to clear ghost charge
  readings[index] = analogRead(inputPin); // read from the sensor
  total = total + readings[index]; // add the reading to the total
  index = index + 1; // advance to the next position in the array
  if (index >= numReadings) // if we're at the end of the array
    index = 0; // wrap around to the beginning

  // convert value to temp
  tempC = total * Aref * 0.1 / numReadings; // value to celcius conversion
  tempF = tempC * 1.8 + 32; // Celcius to Fahrenheit conversion

  // print to LCD
  if (total == 1023 * numReadings) { // if overflow
    lcd.clear();
    lcd.print("---TOO HOT---");
  }
  else {
    lcd.clear();
    lcd.print(tempC, 2); // two decimal places
    lcd.setCursor(6, 0); // position 6, first row
    lcd.print("Celcius");
    lcd.setCursor(0, 1); // second row
    lcd.print(tempF, 1); // one decimal place
    lcd.setCursor(6, 1); // position 6, second row
    lcd.print("Fahrenheit");
  }

  // print to serial monitor
  Serial.print("Raw average = ");
  Serial.print(total / numReadings);
  if (total == 1023 * numReadings) {
    Serial.println("  ----too hot----");
  }
  else {
    Serial.print("   The temperature is  ");
    Serial.print(tempC, 2);
    Serial.print(" Celcius  ");
    Serial.print(tempF, 1);
    Serial.println(" Fahrenheit");
  }

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

kmccb23:
Do I have a bad sensor or could I have wired something wrong??

Perhaps wrong wiring and wrong code.

You better use analog pins for analog readings. So change your code to:

int tempPin = A0;
int lightPin = A1;

and connect your sensors accordingly.

Some versions of the IDE accept also "0" instead of "A0" and "1" instead of "A1", but you will have to use the A0 and A1 pins for analogRead(), so better write A0 and A1 in the code, even if your IDE will (perhaps) also accept analogRead(0) instead of analogRead(A0) and analogRead(1) instead of analogRead(A1).

The programming example code is bad and relies on undocumented side effects with the analogRead() function.

kmccb23:
Yes, the TMP36.. I didn't expect you to know if I wired it wrong, just didn't know if that was a possibility with the issue I was having.

Thanks for the reply.

It's always a possibility with someone else's unknown experiment. Hence the request, which often yields positive results here.