Serial Communications Problems

I want to have a serial communication. I want to input a word, Input, have the program see if the word is the password. If the password is right say correct password. turn on a green LED. If the password is wrong say wrong password blink a red LED. I would like for the Red LED to blink until next input. Also i would like to clear the Correct or Wrong password message with each entry. HELP PLEASE!!! I'm assuming that i need to store the input into an array, I'm not very good with using arrays, and use a for loop to go through and check the input against the password. But, I want the array be big enough to store any length of word that the user will enter for the password but not make it a set size that is so large that the for loop takes forever to go though.

This is the error i get when i verify it. I don't under stand what it is saying. I'm not converting from an integer to a character? Array.ino: In function 'void loop()': Array:18: error: invalid conversion from 'int' to 'const char*' Array:18: error: initializing argument 1 of 'String& String::operator=(const char*)'

Does Serial.read() have limitations to reviving words? Does it need to be an integer?

This is the code i came up with. I added POS to store a position for the array to be in to index to the next array position. String Input; char Password[] = "True"; int LEDG = 10; int LEDR = 9; int POS;

void setup(){ Serial.begin(9600); Serial.println("What Is the Password?"); pinMode(LEDG,OUTPUT); pinMode(LEDR,OUTPUT); POS = 0; }

void loop(){

if (Serial.available()){ Input = Serial.read(); if (Input == Password){ digitalWrite(LEDR,LOW); Serial.println("Correct Password"); digitalWrite(LEDG,HIGH); } else { digitalWrite(LEDG,LOW); Serial.println("Incorrect Password"); digitalWrite(LEDR,HIGH); delay(500); digitalWrite(LEDR,LOW); delay(500); digitalWrite(LEDR,HIGH); delay(500); digitalWrite(LEDR,LOW); delay(500); digitalWrite(LEDR,HIGH); delay(500); digitalWrite(LEDR,LOW); delay(500); digitalWrite(LEDR,HIGH); } } }

Input = Serial.read();In your code Input is a String whereas Serial.read() returns an int (just one)

So, even if the code above worked then     if (Input == Password){wouldn't

Look at http://gammon.com.au/serial to see how to read a string (not a String) from serial, character by character, then you can consider comparing it with another string.

Serial.read() reads a single character/byte. If you want the user to send several characters it is up to you to capture them all and save them somewhere - probably in an array of chars.

The Arduino has very limited memory so you need to put an upper limit on the length of your password so that space may be set aside for it - perhaps 10 characters.

You also need to decide how the Arduino knows the user has finished entering a password that is less than 10 characters. Perhaps the user will press the RETURN key or some other special key. Your code will need to test for that.

If you count how many characters the user has entered you can easily invalidate passwords with the wrong length without having to check the individual characters.

If you want to make an LED blink use a FOR loop. Even better put the loop in a separate function that your code can call with something like ledBlink('R', 5).

Be aware that the Arduino can do nothing else useful while it is doing delay(). If that is a problem (i.e. if you want it to do something else) look at the technique in the Blink Without Delay example sketch.

...R

Depending upon how you wire things, this might be a good concept, but...

Serial.read() provides characters, not words. This: if (Input == Password){

is not how to compare words in C. It won't work.

delay(...) is handy for toy programs but usually creates problems in real programs. You are going to be advised to remove/replace it.