Illogical Arduino

This bug has made me question my sanity for the better part of the day...

For some reason both if statements are being triggered. I can type anything and they are triggered. Nothing makes sense. This defies logic. Please help end this madness.

For example if I type "on" then the response is:

top feed on top feed off

If I type "off" then response is:

top feed on top feed off


String cmdstring = "";
String content = "";
char character;


while(Serial.available()) {
    character =;
  if (content != "") {
    cmdstring = content;
     if (cmdstring == 'on') {
      Serial.println("top feed on");

     if (cmdstring == 'off') {
      Serial.println("top feed off");

"on" "off"

I tried that too. Sorry I should have said that. I'll even give it another try right now. brb.

Ok so I tried that and I must have forgot as I tried that several hours ago. The issue with that setup is I don't any responses at all. I've tried it uppercase, lowercase etc. No responses from either on or off. I'm not new to Arduino and this has got me stumped.

I don't know why you aren't showing compilable code. You are missing Serial.begin().

    if (cmdstring == 'on') {Have you tried printing cmdstring before you test its value ?
What exactly are you typing into the Serial monitor ?
No quotes (on) ?
Single quotes ( ‘on’ )?
Double quotes ( “on” )?

Please post your complete code. Or a complete example that shows the behaviour.

Do you send a CR and/or LF? Do you ever clear the content variable? There is no guarantee that if you send 3 characters, they will all be caught in that while loop. You might read two and the next iteration of loop you will receive the next one.

Add a Serial.println(content) to see what is actually received.

Be aware that YOU need to make the communication reliable. Have a look at Serial Input Basics - updated.