Serial LED control problem

I want to control a leds intensity with analogWrite(10, variable) over serial. Here's my code (Slightly modified from the "Dimmer" exemple):

const int ledPin = 10;
  byte brightness; //Is it ok if I use int instead of byte?

void setup()
{
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  if (Serial.available()) {

    brightness = Serial.read();

    analogWrite(ledPin, 0);

    analogWrite(ledPin, brightness);

    Serial.println(brightness); // This is for testing 
  }
}

The problem is that the led as a constant brightness, even if I send "0" over serial.

Thanks in advance !

P.S. I'm not using any resistor. I've tried to make it dim by itself (see "Fading" exemple) and it worked perfectly. And yes i'm using a PWM pin. I'm using an Arduino Duemilanove

well... what I would do would to be start over. Use the 'Fading' demo you used, make sure that works, and then modify it until you get what you want. This assures you are using the correct pin, your code is good, and you haven't missed anything. Sorry I couldn't be more help!

I don't think your if statement is using the Serial.avalible command correctly. See the examble in the below reference if (Serial.available() > 0) { http://www.arduino.cc/en/Tutorial/Foundations

I'm not using any resistor.

Then you are destroying your arduino.

http://www.thebox.myzen.co.uk/Tutorial/LEDs.html

even if I send "0" over serial.

If you send 0 over serial what you receive is the number 48. Serial uses ASCII to communicate not raw numbers. You can't send zero like this.

I don't think your if statement is using the Serial.avalible command correctly. See the examble in the below reference if (Serial.available() > 0)

It does not make any difference.

if (Serial.available())

is the same as

if (Serial.available() != 0)

which would have the same effect here.

Then you are destroying your arduino.

http://www.thebox.myzen.co.uk/Tutorial/LEDs.html

An LED connected to pin 9. use appropriate resistor as needed. For most common LEDs, you can usually do without the resistor, as the current output of the digital I/O pins is limited.

From: http://arduino.cc/en/Tutorial/Dimmer

Anyway I'll buy some resistor but for the moment i'm not using them.

Can I reconvert ASCII values to numbers? Or send decimals from another program (like VB.NET)?

its limited by the fact that if you get near or over 40ma its going to die, there is no protection on any pin of the arduino, where ever you got that quote from is wrong

Can I reconvert ASCII values to numbers? Or send decimals from another program (like VB.NET)?

You can.
'1' - '0' = 1
'2' - '0' = 2
'3' - '0' = 3

Perhaps you are beginning to detect a pattern, here.

I know 0=48 so x-48 (x being an ASCII value) = Decimal value. That's obvious

its limited by the fact that if you get near or over 40ma its going to die, there is no protection on any pin of the arduino, where ever you got that quote from is wrong

It's from http://arduino.cc/en/Tutorial/Dimmer
But I understand that it will slowly damage my arduino so i'll use some (when I got some)

I know 0=48 so x-48 (x being an ASCII value) = Decimal value.

Today, you remember that '0' = 48. But, 2 months from now, will you remember why toy are subtracting 48 from the value? Subtracting '0' results in the same value being subtracted, but, makes it much more obvious what is being subtracted and makes it more likely that you will remember why.

It's from http://arduino.cc/en/Tutorial/Dimmer
But I understand that it will slowly damage my arduino so i'll use some (when I got some

Probably worth a mention in "Bugs & Suggestions" then.

Today, you remember that '0' = 48. But, 2 months from now, will you remember why toy are subtracting 48 from the value? Subtracting '0' results in the same value being subtracted, but, makes it much more obvious what is being subtracted and makes it more likely that you will remember why.

True, I agree. But I knew about ASCII before, I just didn't though about it. Now I know that serial sends ASCII value, that's all I needed. Thanks a lot everybody. It's been really helpful.