Why am I getting gibberish characters?

I have code that reads from the analog0 input and prints it in serial:

float aread = analogRead(A0); Serial.println(aread);

Whenever I try to get it to do stuff, it outputs a whole bunch of jibberish in the serial console.
Now I know I have the right baud, the serial is setup, and the analog is definitely connected.

The setup I have is this:

// 5v------10k-------Sensor------GND
// |
// Analog

The sensor is a variable resistor. I know that it isn't the problem.

Thanks in advance!

analogRead returns an int.

int aread = analogRead(A0);

10-bit value back is from 0 to 1023.

@CrossRoads - Changing it to int didn't change anything

full code:

void setup()
{
  Serial.begin(9600);  //Start the serial connection with the computer
}

float getTemp() {
  int aread = analogRead(A0) / 1024;
  Serial.println("aread:"+aread);
  float resistance = 10000.0 / (5.0 / aread - 1.0);
  // Serial.println(resistance);
  float temp = 46 / pow(resistance, .40984);
  // Serial.println(temp);
  return temp;
}
 
void loop()
{
  getTemp();
  delay(1000);
}

That's weird. Changed it to 4800 baud and now it works. How odd.

4800 on which end? PC or arduino? and which arduino?

On the PC. The Arduino is set for 9600.
The Arduino is set up to use the 8MHz internal clock, could that be it?
It's also the non-picopower version of the atmega328.

"The Arduino is set up to use the 8MHz internal clock, could that be it? "
Yes.

pitaj:
On the PC. The Arduino is set for 9600.
The Arduino is set up to use the 8MHz internal clock, could that be it?
It's also the non-picopower version of the atmega328.

CrossRoads, is it because of this:

4800 = 9600 / 2

and

8MHz = 16 MHz / 2

?

The Arduino is set up to use the 8MHz internal clock, could that be it?

Does the IDE know that? If it does, it should adjust timings for serial output correctly, so the 9600 baud rate on the Arduino matched the 9600 baud rate on the PC.

That it didn't do the adjustment tells me that the IDE doesn't know that you are not running at 8MHz, which could cause other problems.

is it because of this

Yes.

pitaj,

You should be able to set the same baudrate (9600) in both the IDE serial monitor and on the Arduino. I just verified it works on my 8MHz chip. Here's the recipe to make it all work:

http://arduino.cc/forum/index.php/topic,124879.0.html

My guess is you've got a 16MHz 'Board' selected in the IDE.