When you send data to Arduino over the serial port, it arrives as a stream of ASCII numbers, therefore Arduino can't understand what you want these numbers to mean. It's a bit complicated (at least for me) to convert this, but I got some pieces of code from a tutorial by Nick Gammon and managed to do it. Here's the code with a few comments
const unsigned int max_input = 8;
byte brightness;
int ledPin = 9;
void setup()
{
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
static char input_line [max_input]; // buffer to hold your data
static unsigned int input_pos = 0; // index for your buffer
if(Serial.available()){
char inByte = Serial.read();
switch(inByte){
case '\n': // terminating new line character
input_line[input_pos] = 0;
brightness = (input_line[0] - '0') * 100 + (input_line[1] - '0') * 10 + (input_line[2] - '0');
// the previous line of code converts the ASCII stream of characters to a byte
analogWrite(ledPin, brightness);
Serial.println(brightness); // check if you receive what you give
input_pos = 0; //reset buffer for next time
break;
case '\r': // ignore carriage return
break;
default:
if(input_pos < (max_input - 1)) // if buffer is not full, keep of adding
input_line[input_pos++] = inByte;
break;
}
}
}
So, if you send the number 100, Arduino will receive 49 48 48 (49 is ASCII for 1 and 48 is ASCII for 0). The line that converts that data is multiplying the first number by 100 (after it subtracts ASCII 0, which is '0'), the second by 10 (after subtracting '0') and leaves the third intact. Mind that when sending values less than 100 you'll have to prepend a zero (e.g. 050 for 50). Note that on the serial monitor you have to set the correct baud rate and sending the New Line.
Maybe there's a simpler way to do this, but I don't know any..