code upload issue

hello all,

i've been trying to upload a code to my arduino leonardo board where i'm reading the input from a temperature sensor in analog pin 0 and performing some operations on it.

the problem is that the board keeps executing the previous code where i was trying to get the temp in Celsius, and it doesn't execute the new one i'm trying to upload.

i get the following in the msg box but i'm not sure is it's related in any way!:
" avrdude: stk500_getsync(): not in sync: resp=0x31 "

this is the code i am truing to execute :

"
float tempC;
int tempPin = 0;
void setup ()
{
Serial.begin(9600);
}

void loop()
{
tempC = analogRead(tempPin);
Serial.println((byte)tempC);
delay(2000);
tempC = ((5.0tempC100.0)/1024); // convert analog input to temp in celesius
Serial.print("temp Fehr = ");
Serial.println((byte)tempC);
if (tempC>79)
{
Serial.print("temp is > 26 celsius = "); }
else
{
Serial.print("temp Fehr = ");
Serial.println((byte)tempC);
}
delay(2000); //2 seconds delay
} "

and the serial monitor outputs the following:

temp in C= 77
159
temp in C= 77
192
temp in C= 93
217
temp in C= 105
222
temp in C= 108
215
temp in C= 104
201
temp in C= 98

any idea what could be going on here? i have even tried resettingthe board in hand
I'd really appreciate any quick replies

Hi Sara91

That message is important :slight_smile: It means the Arduino IDE cannot communicate with the Leonardo so the upload fails. Hence, the previous program continues to run.

Have you previously uploaded to this Arduino from your computer?

Before you upload, do you select Tools - Board - Leonardo from the Arduino IDE menu?

And from Tools - Serial Port, do you see a COM port for your Leonardo?

Regards

Ray

Sara91:
the board keeps executing the previous code where i was trying to get the temp in Celsius,

i get the following in the msg box but i'm not sure is it's related in any way!:
" avrdude: stk500_getsync(): not in sync: resp=0x31 "

That error means that your upload is failing. That is why the previous sketch is executing.

http://arduino.cc/en/Main/arduinoBoardLeonardo
"Because of the way the Leonardo handles reset it's best to let the Arduino software try to initiate the reset before uploading, especially if you are in the habit of pressing the reset button before uploading on other boards. If the software can't reset the board you can always start the bootloader by pressing the reset button on the board."

aha!
the issue was probably due to the board selection, i don't know how i missed that ^^"
it's really my first time dealing with arduino, hence the silly mistake :confused:

anyways at least now i know what that msg means!

thank you both :slight_smile: