arduino mega 2560 not working properly

Hi,
i have been using arduino mega 2560 from last two year and did some projects but now it's not working properly.when i tryed to do serial communication from arduino to another device or connect rx and tx of arduino to each for testing no reply comes.
i also tryed to analog read by connecting 5v to pin A0 but it shows yyyyy continuously but no value on serial monitor.

Is there any way to make it work fine?? i tryed reset button but nothing happened.

Thanks,
Ransher

Your Mega has 4 serial ports; which one are you talking about? Anything else connected to the Mega? If so, what and how (diagram please); also try without anything connected except for connection to PC.

It sounds like you can upload a sketch but I might be mistaken. Can you upload a sketch? If not, read the troubleshooting guide.

i run this code to check the output. This output comes continuously "" when i connect the pin 7 to 5v and nothing happens when connected to pin 9 on mega2560.

void setup()
{
  Serial.begin(9600);
  pinMode(9,OUTPUT);
  pinMode(7,INPUT);
  Serial1.begin(9600);
  
}
void loop()
{
  digitalWrite(9,HIGH);
  Serial.write(digitalRead(7));
  delay(100);
}

Use Serial.print / Serial.println instead of Serial.write. The Serial Monitor does not understand 0 or 1, only '0' and '1'.

happy it worked.
now i want to check that serial 1 pins rx & tx are working so i connect rx to tx for testing.
it display this
"104
104
104
104
104
104
104"

on serial monitor

void setup()
{
  Serial.begin(9600);
  Serial1.begin(9600);
  
}
void loop()
  {
  Serial1.write("hello"); 
  Serial.println(Serial1.read());
  delay(100);
  }

if change code this output comes after 10 times correct it starts show only h again and again.
:confused:

ÿhello
hello
hello
hello
hello
hello
hello
hello
hello
hello
helhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

void setup()
{
  Serial.begin(9600);
  Serial1.begin(9600);
}
void loop()
  {
  Serial1.println("hello"); 
  Serial.write(Serial1.read());
  delay(1000);
  }

You're overflowing the Serial1 software receive buffer. Don't write more than you read (for this sample code).

hi sterretje,
thanks for reply what is the solution for that?

In this case, read till you have received everything that you have send before sending again.

Read Serial Input Basics - updated for a general purpose way to read serial ports (examples are for Serial, but can easily be adapted for Serial 1/2/3.

Note that with println(), you add '\r\n' to the text that you send. The second example in linked thread will read till '\n'; you will probably want to strip the '\r' in real life as well; not necessary for this exercise.

Thanks for the reply i got your point.