On inputing any value to arduino UNO, it read it only as 0 , what to do ?

I am having some serious problem with communication with arduino UNO ,When i send any value through serial monitor, arduino take input as Zero only
On printing the sent value theough ' Serial.println(val) '
It only print 0 , no matter what i send..
I using code code as Serial.(9600) . Plz help

Post your code USING CODE TAGS(</> button on the toolbar).

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

I have done serial programming severel times
..
Jst about 1 week ago upload a program which uses serial monitor, it was okay then,
But now it is giving this error..
I mean every serially input value is being read as 0

That's a little bit interesting.

SGanorkar:
I mean every serially input value is being read as 0

By what program ?

...R

int x ;

void setup ()
{
Serial.begin(9600);
}

void loop ()
{
while (Serial.available()==0);
x = Serial.read()-48;
Serial.println(x) ;
}

On serial monitor , when i send any number it print 0

Have you tried the examples in the link I gave you?

...R

SGanorkar:
int x ;
On serial monitor , when i send any number it print 0

No, you NEVER "read the number!

You read the number of bytes in the Serial input buffer,
and in case the input buffer is empty, you try to read something from an empty input buffer!

Perhaps try something like that;

void loop ()
{
  char c=Serial.read(); // here we read -1 in most cases /in case input buffer is empty)
   if (c>='0' && c<='9') Serial.println(c); // in case we read a digit character, print it in a line on the serial monitor
}

@jurs

No, you NEVER "read the number!
You read the number of bytes in the Serial input buffer,
and in case the input buffer is empty, you try to read something from an empty input buffer!

I don't understand your comment. The sketch blocks waiting for some non zero return from Serial.available and then reads and prints the next character.

Can you please explain what you mean?

The posters sketch works as intended with my uno and the standard ide serial monitor. I enter a character in the monitor, press enter or send, and the value is printed on my screen. I have no clue as to the poster's actual problem.

int x ;

void setup ()
{
Serial.begin(9600);
}
void loop ()
{
while (Serial.available()==0);
x = Serial.read()-48;
Serial.println(x) ;
}

What are your serial monitor settings?

SGanorkar:
int x ;

void setup ()
{
Serial.begin(9600);
}

void loop ()
{
while (Serial.available()==0);
x = Serial.read()-48;
Serial.println(x) ;
}

On serial monitor , when i send any number it print 0

I'm having trouble believing you didn't notice my request to use code tags in capitalized, bold, red text. I'm instituting a new policy of three strikes before putting people on my personal blacklist. First strike was not reading the How to use this forum post, second strike was not following my request.