Serrial Monitor Prints Repeatedly

whenever I press the command the serial monitor prints repeatedly could anyone tell me why??

Welcome to the forum

You started a topic in the Uncategorised category of the forum whose description is

:warning: DO NOT CREATE TOPICS IN THIS CATEGORY :warning:

Your topic has been moved to a relevant category

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Think about what value LED will have after you receive '0' or '1'

What will happen the next time you check its value, whether or not anything has been entered subsequently

Did you try pressing 0 ?
There are other things to consider,,,

typical problem where code that processes serial input is outside the block that tests if serial input is available and therefore executes all the time

where the code is a picture, and squinting at it leads to misreading.

    if (Serial.available())
     {
   LED= Serial.read();
}

@muaazulhassan - as @UKHeliBob says or hints LED keeps its value like a good variable will tend to do…

a7

Where would be a good place to add

char LED= Serial.read();

or

LED='';

to stop it from doing that?

On Edit: Sorry HeliBob, I edited my question

At the end of loop()

unfortunately there's no way to copy the code from your image. click the <code> and paste the code

void loop ()
{
    if (Serial.available())  {
        char c = Serial.read();

        if (c == '0')  {
            digitalWrite (13, LOW);
            Serial.println (" LED off");
        }
        else if (c == '1')  {
            digitalWrite (13, HIGH);
            Serial.println (" LED on");
        }
    }
}

This works if you crop the image.

void loop() {
  if (Serial.available()) {

    LED = Serial.read();
  }
  if (LED == '1') {
    digitalWrite(13, HIGH);  // tur
    Serial.print("LED ON \n");
  } else if (LED == '@') {
    digitalWrite(13, LOW);  // tur
    Serial.print("LED OFF\n");
  }
}

Of course, the configuration needs to be assumed...

int LED;
void setup() {
  Serial.begin(9600);
  Serial.println();
  pinMode(LED, OUTPUT);
}
void loop() {
  if (Serial.available()) {
    LED = Serial.read();
  }
  if (LED == '1') {
    digitalWrite(13, HIGH);  // tur
    Serial.print("LED ON \n");
  } else if (LED == '@') {
    digitalWrite(13, LOW);  // tur
    Serial.print("LED OFF\n");
  }
}

And it works.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.