Go Down

Topic: NOT getting how to use SERIAL PORT as a passkey INPUT (Read 517 times) previous topic - next topic


Hello World ,
I am recently facing a problem in a program in which I have to take input from the user using the Serial port but i am not able to process the input properly

Code: [Select]

String pass=0;
void setup()
void loop()
    Serial.println("Correct passkey");
   else if(pass!="1234")
   Serial.println("Incorrect passkey");


Serial.read(); reads a single character so what is read will never equal "1234"
Have a look at the Serial.readStringUntil() function

Even better, look at Serial input basics - updated and don't use Strings at all
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.


Simple serial echo test code that captures characters and sends them back to the serial monitor.

Code: [Select]
//zoomkat 6-29-14 Simple serial echo test
//type or paste text in serial monitor and send

String readString;

void setup() {
  Serial.println("Simple serial echo test"); // so I can keep track of what is loaded

void loop() {

  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the String readString
    delay(3);  //slow looping to allow buffer to fill with next character

  if (readString.length() > 0) {
    Serial.println(readString);  //so you can see the captured String
    readString = "";
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

Go Up