Read int from Serial
.parseInt() reads incoming text up until either it times out or until it reads something that isn't a number.

You are sending a number, and most likely a line-ending. If that line-ending is a simple \n then that will trigger the "end of number" and will be discarded and the number returned.  However, if you are sending \r\n (i.e., CRLF) then you effectively have two line endings there:

1\r\n


Parsed as:

1\r =&gt; return 1
\n =&gt; return 0


Relying on the (poorly written) Arduino stream parsing routines is not good. Not only are they blocking, but often they just don't work right.

Instead you should be reading the serial properly, taking account of line endings, and then converting the string you have read into a number using the likes of atoi().

Tutorial on reading serial: 


https://hackingmajenkoblog.wordpress.com/2016/02/01/reading-serial-on-the-arduino/