Temperature Sensor always gives a value of 0

Hi all,

I just got my Arduino board today, so please excuse me if I miss something obvious.

I am trying to light up a few LEDs based on the temperature (Love-o-meter project).

The problem is, the sensor value is always 0.

Here is my code:

const int sensorPin = A0;
const float baseTemp = 20.0;

void setup(){
  
  //turn off the built-in led
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);


  Serial.begin(9600);
  
  //set up the led pins
  for (int pinNum = 2; pinNum <= 4; pinNum++){
    pinMode(pinNum, OUTPUT);
    digitalWrite(pinNum, LOW);
  }
}

void loop(){
  //get a value from the thermometer and print it
  int sensed = analogRead(sensorPin);
  Serial.print("Sensed: ");
  Serial.print(sensed);
  
  //print the voltage
  float voltage = (sensed/1024.0) * 5.0;
  Serial.print(" Volts: ");
  Serial.print(voltage);
  
  //print the temperature
  float temp = (voltage - .5) * 100.0;
  Serial.print(" Temp: ");
  Serial.println(temp);

  
  //light up the LEDs based on the temperature
  if (temp < baseTemp + 2) {
    for (int pinNum = 2; pinNum <= 4; pinNum++){
      digitalWrite(pinNum, LOW);
    }
  } 
  else if (temp >= baseTemp + 2 && temp < baseTemp + 4) {
    digitalWrite(2, HIGH);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
  } 
  else if (temp >= baseTemp + 4 && temp < baseTemp + 6){
    digitalWrite(2, HIGH);
    digitalWrite(2, HIGH);
    digitalWrite(3, LOW);
  } 
  else if (temp >= baseTemp + 6){
    for (int pinNum = 2; pinNum <= 4; pinNum++){
      digitalWrite(pinNum, HIGH);
    }
  }

  delay(1);
}

Here is a picture of my board:

What temperature sensor are you using? Can you provide a link to it's datasheet?

int sensed = analogRead(sensorPin);

try

int sensed = analogRead(A0);

I don't think A0 can be stored is an interger.

Tom.... :slight_smile:

const static uint8_t A0 = 14;  // From pins_arduino.h
...
const int sensorPin = A0;  // From OP's code

"A0" can't, but (int)A0 can.

You didn't say what model your temp sensor is, half your board is in shadow, and you probably couldn't read the label from that angle anyway, so it's hard to say if the hardware side is correct, but the software looks OK. (Are TO-220 temp sensors common?)