Communication between Raspberry pi and Arduino via GPIO

The result of a digitalRead() call is either HIGH or LOW and not a numeric character as your code

if (PiState == 4 - '0') {

assumes .