Reading Serail Messages between two Arduinos

I'm wondering how you could send characters through the TX pin of an Arduino Uno and the RX pin on an Arduino Nano, but the code I seem to be using for the Nano (the receiver in other words) isn't giving me the character(s) being sent by the Arduino Uno (transmitter) through the Serial Monitor.

Here's the Receiver's code. I only want it to display on the serial monitor on the computer to see if the correct characters are being received:

void setup() 
{
  Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
}
void loop() 
{
  // send data only when you receive data:
  if (Serial.available() > 0) 
  {
    Serial.println(Serial.read(),DEC);
  }
}

And in case the Transmitter code is wrong, I'll put it below:

const int buttonOne = 2;
int buttonOneState = 0;
void setup() 
{
   Serial.begin(9600); 
}
void loop() 
{
  buttonOneState = digitalRead(buttonOne);
  if(buttonOneState == HIGH)
  {
    Serial.println(1,DEC);
    delay(500);
  }
  else
  {
    Serial.println(0,DEC);
    delay(500);
  }

}

Try with Serial.write('1'); // or ('0')


if (Serial.available() > 0)
{
char ch=Serial.read();
if (ch=='0' || ch=='1') Serial.println(ch);
}

The transmitter is using println() which will send a carriage-return and a linefeed to mark the end of lines. These are character 10 and 13. Your receiver will receive these characters and print '10' and '13' in the output.

Is this what you are getting? Saying "It doesn't work" isn't descriptive enough.

To fix this, decide if you want this output to be human-readable or not. Does your final project require you to look at the communications, even if you are only verifying that your transmitter is sending the correct data? Then change the receiver to simply copy that output to the serial monitor. If human-readable is not required (you will always have a Nano translator available to check the output) then change the transmitter as Knut suggested.

I changed the "Serial.println("1");" to "Serial.write('1'):"and that had removed the "10" and "13" characters that I was getting, sorry for not elaborating on that in the initial post. So now I am just receiving one number depending on the input :).

But... even though I'm just sending 0, I'm receiving 48... and when I send 1, receive 49. Why is that now (even though I could just do it like that it'll be interesting to know why it does that)?

Thanks for the help ;D

48 is the ascii code for '0'.

Try using one of the examples in serial input basics.

...R