confusion with variable types

I am trying to communicate serially between Matlab and Arduino Uno, and implement some flow control mechanisms that I study in college. Here the Arduino needs to take a number serially, and if it expected that number (there's a logic for figuring out which number it expects), write the same number to Serial after a certain delay, otherwise do nothing. the code I'm uploading to the board is -

byte prob, time=3, nwindow=4, iframe, eframe=0;

void setup()

void loop()
        Serial.println("inside the if");

I'm printing "inside the if" just for debugging purposes. Trouble is it never prints it to the serial monitor, meaning it never goes into the If condition (it should ATLEAST satisfy the If in the first iteration, when I give it a 0 serially).
Any idea why this is happening? The problem has been eating my brain since two days!

change this to Serial.print


Serial.write sends out binary, may be getting non-printing characters sent instead.
see for cross reference of the characters/ascii value/hex value

... (it should ATLEAST satisfy the If in the first iteration, when I give it a 0 serially).

Well, not really. Provided the sending end sends at 9600 baud, and it sends a 0x00 byte.

Do you mean:


That's a completely different kettle of fish.

Do you mean:

Alternatively, if you are only sending characters that represent decimal digits: - '0';

The Serial Monitor deals with strings. The number 0 is the character 0 as far as the Serial Monitor is concerned, so that character is what it sends to the Arduino, not the number 0.

thanks for the replies everybody! turns out the problem was something else altogether.

I wasnt pausing for enough time after writing the fopen(serial obj) in Matlab. Arduino resets everytime fopen() is executed, and so the poor thing was getting confused - data coming in serially while its still booting!

Thanks PaulS, one of your earlier posts came in handy!