Your presented code and the attached code don't seem to match. The attached code
char tag[] ="1C002492359F";
char input[12];
int count = 0;
boolean flag = 0;
int led=9;
int led2=8;
void setup()
{
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
}
void loop()
{
if(Serial.available())
{
count = 0;
while(Serial.available() && count < 12)
{
input[count] = Serial.read();
count++;
delay(5);
}
if(count == 12)
{
count =0;
flag = 1;
while(count<12)
{
if(input[count]==tag[count])
flag = 1;
else
flag= 0;
count++;
}
}
if(flag == 1)
{
Serial.println("Access Allowed!");
digitalWrite(led2,HIGH);
delay(4000);
digitalWrite(led2,LOW);
}
else
{
Serial.println("Access Denied");
digitalWrite(led,HIGH);
delay(4000);
digitalWrite(led,LOW);
}
for(count=0; count<12; count++)
input[count]= 'F';
count = 0;
}
}
So which one do you need comments on? For the above, print the received characters to serial monitor
void loop()
{
if(Serial.available())
{
count = 0;
while(Serial.available() && count < 12)
{
input[count] = Serial.read();
Serial.println(input[count]);
count++;
delay(5);
}
Serial.print("Receive finished; count = ");
Serial.println(count);
...
...
Does it consistently print 12 for the count?
And when posting code in a post, please use code tags
Type
** **[code]** **
before pasted code
Type
** **[/code]** **
after pasted code