Temperature sensor not displaying accurate readings

Hello everyone, I’m new to programming and Arduino and was wondering whether someone could point me in the right direction in regards to an issue I’m having. My temperature sensor is displaying a figure of 370-380 instead of something along the lines of 25-28 degrees celsius. Here is the code:

int photoPin = 9;
int tempPin = 0;
int light;
void setup()
   pinMode(photoPin, INPUT);
   pinMode(tempPin, INPUT); 
 void loop()
   float temperature = getVoltage(tempPin);
   temperature = (temperature - 0.5) * 100;
   Serial.print("Temperature: ");
   Serial.println( temperature);
  digitalWrite(9, HIGH); 
  light = analogRead(photoPin);
  Serial.print("Light intensity: ");
  Serial.println( light);
  digitalWrite(9, HIGH);
  digitalWrite(9, LOW);
 float getVoltage(int tempPin){
   return (analogRead(tempPin) * .004882814);

My temperature sensor is connected to Analog pin 0 and the light sensor is connected to pin 9. I know there’s something fundamentally wrong and it’s most likely a simple mistake, so any input at all would be appreciated.

You need to say what sensor you have and how you have wired it up if anyone is going to stand any chance of answering this.

Sorry, it is the TMP36 temperature sensor with an Arduino Uno. I have it hooked up like this with the exception of the pins, where the TMP36 is connected to Analog 0 and the Photo-Resistor is connected to pin 9.

Thanks a lot.

You haven't connected the 5V up to the TMP36. Also check it is the right way round because that diagram looks like it is the wrong way round.

The light sensor that you are reading is not connected to digital pin 9. Why you are doing an analogRead on a digital pin is a mystery, too.

The analogRead() function only works on analog pins.

with the lm35 i have to use this LM35: temp = (5.0 * analogRead(tempPin) * 100.0) / 1024 if i dont then i get the 300 and something reading you mention, maybe you have to do someting similar for the tmp36