Hi All. Its my first time working with Arduino Due ( or Any Arduino). So Last Nite I was Using My Arduino Due and It was working Fine. But When I used it Today, It Was Not Working so i tried to Check The Output To the Serial Monitor, I saw that its producing "ÿ ÿ" Extra !!!
This Is My Arduino Code:
//enter code here
int lock = 6; //pin 6 on Arduino
int unlock = 7;
int lock2 = 8;
int unlock2 = 9;
int lock3 = 10;
int unlock3 = 11;
char final[4]; //Characters the Arduino will receive
char correct[4] = {'A','A','A','A'}; //User-Defined Password
char correct2[4] = {'B','B','B','B'};
char correct3[4] = {'C','C','C','C'};
int pass_correct = 0; //Does Password match, 0=false 1=truevoid setup()
{
pinMode(lock, OUTPUT);
pinMode(lock2, OUTPUT);
pinMode(lock3, OUTPUT);
pinMode(unlock, OUTPUT);
pinMode(unlock2, OUTPUT);
pinMode(unlock3, OUTPUT);
Serial.begin(38400);
Serial2.begin(19200);
Serial3.begin(115200);digitalWrite(lock, HIGH); //By default, lock is active(locked)
digitalWrite(lock2, HIGH);
digitalWrite(lock3, HIGH);
digitalWrite(unlock, LOW);
digitalWrite(unlock2, LOW);
digitalWrite(unlock3, LOW);
}void loop()
{
while(Serial.available())
{
Serial.println("Serial 1 Available");
for(int i=0; i<4; i++) //While data is available read 4 bytes
{
final = Serial.read(); //Read 4 bytes into the array labled "final"
_ Serial.println(final*);*_* }*
* for(int i=0; i<4; i++)*
* {*
if(final_==correct*) //Compare each char received to each car in our password in order*
* {
Serial.println("Serial 1 Block");_
pass_correct = 1; //If we compare two chars and they match, set the pass_correct variable to true(1)** }*
else if(final_==correct2*)
{Serial.println("In Block 2");_
pass_correct = 2; //Second Lock*
* break; //End loop and stop comparing chars*
}else if(final_==correct3*){
Serial.println("Wrong block 3");_
pass_correct = 3;** }else {*
* Serial.println("Wrong Password");*
* pass_correct = 0; // if password does not match;
_ break; // end of loop stop comparing*
* }
}
}*_* while(Serial2.available())*
* {*
* for(int i=0; i<4; i++) //While data is available read 4 bytes*
* {*
_ final = Serial2.read(); //Read 4 bytes into the array labled "final"
* }*_* for(int i=0; i<4; i++)*
* {*
if(final_==correct*) //Compare each char received to each car in our password in order*
* {_
pass_correct = 1; //If we compare two chars and they match, set the pass_correct variable to true(1)
_ break;
}
else if(final==correct2)
{_
pass_correct = 2; //Second Lock*
* break; //End loop and stop comparing chars*
}else if(final_==correct3*){_
pass_correct = 3;
_ break;
}else {_
pass_correct = 0; // if password does not match;
_ break; // end of loop stop comparing*
* }
}
}*_* while(Serial3.available())*
* {*
* for(int i=0; i<4; i++) //While data is available read 4 bytes*
* {*
_ final = Serial3.read(); //Read 4 bytes into the array labled "final"
* }*_* for(int i=0; i<4; i++)*
* {*
if(final_==correct*) //Compare each char received to each car in our password in order*
* {_
pass_correct = 1; //If we compare two chars and they match, set the pass_correct variable to true(1)
_ break;
}
else if(final==correct2)
{_
pass_correct = 2; //Second Lock*
* break; //End loop and stop comparing chars*
}else if(final_==correct3*){_
pass_correct = 3;
_ break;
}else {_
pass_correct = 0; // if password does not match;
_ break; // end of loop stop comparing*
* }
}
}*_* if(pass_correct==1) //If all chars compared match, deactivate(unlock) the lock for 5 seconds*
* {*
* Serial.println("Unlocked");*
* digitalWrite(lock, LOW);*
* digitalWrite(unlock, HIGH);*
* delay(5000);*
* Serial.println("Locked");*
* pass_correct = 0;** } else if(pass_correct==2) //If all chars compared match, deactivate(unlock) the lock for 5 seconds*
* {*
* Serial.println("Unlocked");*
* digitalWrite(lock2, LOW);*
* digitalWrite(unlock2, HIGH);*
* delay(5000);*
* Serial.println("Locked");*
* pass_correct = 0;** } else if(pass_correct==3) //If all chars compared match, deactivate(unlock) the lock for 5 seconds*
* {*
* Serial.println("Unlocked");*
* digitalWrite(lock3, LOW);*
* digitalWrite(unlock3, HIGH);*
* delay(5000);*
* Serial.println("Locked");*
* pass_correct = 0;
_ }
else*
* {
digitalWrite(lock, HIGH); //Else if there was not a complete match, keep the lock high(locked)
}*__ /* FOR TESTING_
* Serial.print(final[0]);Serial.print(final[1]);Serial.print(final[2]);Serial.print(final[3]);*
* Serial.print(" | ");*
* Serial.print(correct[0]);Serial.print(correct[1]);Serial.print(correct[2]);Serial.print(correct[3]);*
* Serial.print(" ");*
* Serial.print(pass_correct);
_ Serial.println("");
/
delay(500);_* }[/quote]*
When I Enter "AAAA" in the Serial Monitor I should See Unlocked but instead i see...> Serial 1 Available
> A
> A
> A
> A
> Serial 1 Block
> Serial 1 Block
> Serial 1 Block
> Serial 1 Block
> Serial 1 Available
*> *
>
*> *
*> *
> ÿ
> ÿ
> Wrong Password
Is It Possible My Arduino Is Damaged?
Is There Any Possible Way To Fix it ?
Please Help As Soon Ass Possible.