In this case, the LED is not affected by the data. I guess that because of the serial only sends strings and the analog out in Arduino uses bytes. There might be some really simple solution for this. But I can't figure it out.
int ledPin = 9;
int val;
void setup()
{
// begin the serial communication
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop()
{
// check if data has been sent from the computer
if (Serial.available()) {
// read the most recent byte (which will be from 0 to 255)
val = Serial.read();
// set the brightness of the LED
analogWrite(ledPin, val);
}
}
But my requirement is to give inputs via a web page not from the serial. Please someone help me on this. Please!! Please!!!