Writing strings from the serial monitor to lcd

I'm trying write a program where I put in a string on the serial monitor and it displays it to the lcd but when I run it nothing is displayed. All my connections are fine as I've used it in a simple program. Here is the code:

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
String Word;
void setup() {
  // put your setup code here, to run once:
  lcd.begin(16, 2);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("Word of 16 characters:");
  while (Serial.available()==0){}
  Word = Serial.readString();
  lcd.clear();
  lcd.setCursor(0, 0);
  if (Word.length() > 16){
    lcd.print(Word);
  }
  else {
    lcd.print("Too Big!");
  }
  delay(500);
}

Is there anything wrong?

  • You do know this sends the serial data out of the Arduino to the serial monitor (or other terminal program) on the PC ?

Serial.println("Word of 16 characters:");

So then how do I read it from the computer?

Don't you actually want:

`if (Word.length() <= 16){

Thanks, though I don't know why it doesn't show 'too big' when the string is too long.

  • Open the Serial Monitor in the IDE.
  • Send Word of 16 characters: from the serial monitor to the Arduino.
  • Assembly the received characters in your program.
  • When you receive the : check the length of the received string.
  • Note, you can have the Serial Monitor send a termination CR and use that as you final character.

How do I code that (sorry).

Thanks, I'll read it carefully and can I reply if I have questions about that?

1 Like

shouldn't this be < 16 ?

(yes, you did)

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