UART User interface to turn lights on


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("Input your password followed by an ENTER.");

void setup() {
  // initialize serial:
  // make the pins outputs:
  pinMode(ledPin, OUTPUT);

void loop() {
  // if there's any serial available, read it:
  while (Serial.available() > 0) {
    if (charRead != '\n' && charCount<MAXCHAR) {
       strRead [charCount] = charRead;
       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);
         digitalWrite(ledPin, LOW);
      else {
         Serial.println("Input Incorrect...");

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.