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()
{
Serial.begin(9600);
pinMode(photoPin, INPUT);
pinMode(tempPin, INPUT);
}
void loop()
{
float temperature = getVoltage(tempPin);
temperature = (temperature - 0.5) * 100;
Serial.print("Temperature: ");
Serial.println( temperature);
delay(500);
digitalWrite(9, HIGH);
light = analogRead(photoPin);
Serial.print("Light intensity: ");
Serial.println( light);
digitalWrite(9, HIGH);
delay(500);
digitalWrite(9, LOW);
delay(500);
}
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.