Serial monitor stream uncorrect numbers

Hello to all. I have a problem with the serial monitor:
I am working in communication with Max.msp. the serial port and the baud rate are corrects but a stream of -1 appears. they shouldn't exist given the sketch

const int led = 13;
int value;

void setup() {
pinMode(led, OUTPUT);
Serial.begin(9600);

}

void loop() {
// put your main code here, to run repeatedly:
if (Serial.available());{

value = Serial.read();

digitalWrite(led, value);
Serial.println(value);
}
}

You put in an extra semicolon. That empty statement is the only statement controlled by your 'if' statement.

1 Like

This may not do what you expect; most (all?) values you read are going to be non-zero, so the LED will always be lit.

Please remember to use code tags when posting code

-1 is what Serial.read returns when there is no data

Thanks to all. i think there is a problem with usb mapping because the serial monitor still doesn't work. Someone know how to fix it?

Have you tried a simple "hello world" sketch?

Hi,
Try this code, see what you get on the serial monitor.

const int led = 13;
int value;

void setup()
{
  pinMode(led, OUTPUT);
  Serial.begin(9600);
  Serial.println("Starting Monitor Basic test");
}

void loop()
{
  Serial.print("This UNO is Counting ");
  Serial.println(value);
  value = value + 1;
  delay(250);
}

Tom.... :smiley: :+1: :coffee: :australia:
PS. If you left click the icon circled, it will copy the code into your clipboard for you to paste in the IDE.