UART User interface to turn lights on

Hi

I am trying to use an arduino microcontroller to turn some lights on. The communication method should be serial (UART).

Upon power up the arduino should ask for a password, which the user should input. after this is complete it should return the status of the digital inputs and allow the user to select a logical high or low level for the outputs.

I am familiar with everything with exception of the UART communication. How can I compare data received with a user stored password? Also how should I process the serial data so that I can change the status of the digital outputs?

Many thanks in advance

How the system return to the “looked mode”? It one perform one action after enter the password? Or you are thinking to have one command to return to that mode? Or will be after a certain amount of time without use?

To answer your question, you can follow this example:

#define MAXCHAR 10

const char strMem[]="test";

// pins for the LEDs:
const int ledPin = 13;

char charRead;
int charCount = 0;
char strRead[MAXCHAR];

void welcome_msg() {
   Serial.println();
   Serial.println("Input your password followed by an ENTER.");
   Serial.println();
}


void setup() {
  // initialize serial:
  Serial.begin(9600);
  // make the pins outputs:
  pinMode(ledPin, OUTPUT);
  
  welcome_msg();
}

void loop() {
  // if there's any serial available, read it:
  while (Serial.available() > 0) {
    charRead= Serial.read();
    if (charRead != '\n' && charCount<MAXCHAR) {
       strRead [charCount] = charRead;
       charCount++;
       strRead [charCount] = '\0'; //end of the string
    }
    else {
      // check if the password is correct
      if (strcmp(strRead, strMem) == 0) {
         Serial.println("Input Correct!");
         digitalWrite(ledPin, HIGH);
         delay(1000);
         digitalWrite(ledPin, LOW);
      }
      else {
         Serial.println("Input Incorrect...");
      }
      welcome_msg();
    }
  }
}

I think it have what you are asking for:
-read a “string” that is coming from the serial line;
-check it against one saved string.

Thank you for your reply.

It won't return to locked mode until it is reset again.