Go Down

Topic: How to write text on lcd display when I speak? (Read 238 times) previous topic - next topic


Hello I have a question I want to know reason of this

Now my problem is I can't write a text while I speak on lcd display

Code: [Select]

#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);

#define led 13
 String readString = "";
void setup() {
 pinMode(led, OUTPUT);
 digitalWrite(led, LOW);
void loop() {
 while (Serial.available()) {
 char c = (char)Serial.read();
 readString += c;
 if (readString.length() > 0) {
 if (readString == "light on") {
 digitalWrite(led, HIGH);
 lcd.print("Led is on");
 if(readString == "Display"){
  lcd.print("How are you");
 if (readString == "light off") {
 digitalWrite(led, LOW);
 lcd.print("Led is off");
 readString = "";

These are my codes
So While I give "Light on" Command is Running but I give "Display" Command is not working
What is reason of this ?
by the way I 'm new at arduino


You are assuming that all the data for a "command" arrives at one time. That is NOT the case.

What is sending the serial data to the Arduino? Can you control HOW it sends the data?
The art of getting good answers lies in asking good questions.


well, is this wrong ?

Code: [Select]

char serialA;

void loop() {
   if (Serial.available() > 0) {
  serialA = Serial.read();
  lcd.print("How are you");
  digitalWrite(led, LOW);


That code will read 1 byte from the serial port and print to the LCD.  Is that what you expect?

The serial input basics tutorial may be of help to you.


If you print the content of readString, you can see what is happening.

Code: [Select]
  Serial.print("readString contains: '");

Place it before the first if in loop() in your code in the opening post.

Robin's tutorial (linked in reply #3) provides a basis for a better approach.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Go Up