Problem with Serial.println with many if conditions and loaded libraries

I have a problem when having many if statement to check incoming characters from combined with Serial.print command.
The problem is I’m unable to check for characters. It seems the Serial buffer has an overflow.
The combination having loaded libraries and many if statement, seems to be a problem.
Without loading any library it works well. But if I try to load ex. library ethernet.h, the serial incoming characters ignores or give me a random output. (see attached code).
But if I reduce the if statement and Serial.println lines, ex. remark #help, I can get it work.

So any idea what the problem is?

SerialMenu.txt (10.2 KB)

Easy, you have lots of "delay(2000);" all over the place - you'll have to replace all the delays with the blinkWithoutDelay style of coding.

After removing the delay(2000), I still have same problem. As explained if I remove lines where Serial.print occurs, I can get it works. It works when I remark the “#help” function, but when unremark or add more Serial.print lines, the Serial read does not work. Is there some kind of limitation for Serial.print and characters?

What board is this running on ?

It sounds to me like you are running out of memory and the fact that it works if you comment out the #help function with its multitude lines of text would also point to that. Your use of Strings will also contribute to any memory problem as it serves to fragment the available memory.

Have you added up how many chars in all those strings? Maybe you're blowing the RAM available. What Arduino is this running on?


Oh, and PLEASE get rid of all the duplicate code,

digitalWrite(led, HIGH);
digitalWrite(led, LOW);
autot = 0;

These lines are duplicated at least a 1000 times.


First, I removed the duplicated lines, still same problem. To recap my problem:
The program runs fine without any library loaded. I can have as many Serial.print line as I needed. But when i ex. load a library ethernet.h and add just few Serial.print “text…”, I’m unable to check incomming characters. The monitor returns only first Serial.print line. I can reduse Serial.print lines and/or printed text, to get it work again.
FYI the memory uses is beyond limit <32.000K (typical 20K used).

I may have RAM problem. If so, is there any possibility to clear RAM after serial reading characters successful?

Read and note the possible use of PROGMEM

I can reduse Serial.print lines and/or printed text, to get it work again.

Does this mean that if you reduce the number of strings it works? If so you have the answer to your problems several times above.

You didn't answer two questions about the chip you are using , but we can assume it's a Mega328 as you said 32k of program memory. So that's less than 2k of RAM available to your program, you will use that up in no time.