1

Here is the code in Arduino online editor

#include <SoftwareSerial.h>

char tag1[12]={"123456789123"};
char tag2[12]={"123456789456"};
char  var[12]={"000000000000"};
int ok;
void setup() {
  // put your setup code here, to run once:
 
Serial.begin(9600);
}
boolean comparetag(char aa[14], char bb[14])
{
  boolean ff = false;
  int fg = 0;
  for (int cc = 0 ; cc < 12 ; cc++)
  {
    if (aa[cc] == bb[cc])
    {
      fg++;
    }
  }
  if (fg == 12)
  {
    ff = true;
  }
  return ff;
}
void check()
{
  ok = 0;
  // if it is 1 we have a match, zero is a read but no match,
  // -1 is no read attempt made
  if (comparetag(var, tag1) == true)
  {
    ok++;
  }
  if (comparetag(var, tag2) == true)
  {
    ok++;
  }
}

void reading_data()
{   ok=-1;
  int k=0;
  char val;
  Serial.println("entre the rfid id");
  while(!Serial.available())
  {
    // It waits
    }
    
  if(Serial.available()>0)
  {     
    for(int i=0;i<12;i++)
  {
    val=Serial.read();
    Serial.print(val);
    var[i]=val;
     while(!Serial.available())
  {
    // It waits
    }
    
    }
   check();
  }
  if (ok > 0) // if we had a match
  { Serial.println('\n');
    Serial.println("Accepted");
    

    ok = -1;
  }
  else if (ok == 0) // if we didn't have a match
  {Serial.println('\n');
    Serial.println("Rejected");

    ok = -1;
  }
  
  }

void loop() {
  // put your main code here, to run repeatedly:
reading_data();
}
  1. I have used the ATtiny85 library in Arduino IDE
  2. I'm getting an error as "Serial was not declared in this scope"
Weather Vane
  • 33,872
  • 7
  • 36
  • 56
Ajit
  • 11
  • 2
  • regarding: `char tag1[12]={"123456789123"}; char tag2[12]={"123456789456"}; char var[12]={"000000000000"}` those strings are 13 bytes long remember the NUL terminator byte) so, there is the first error – user3629249 Jun 22 '21 at 09:49
  • OT: The posted code contains some 'magic' numbers. 'magic numbers are numbers with no basis. .I.E.. 12, 14. 'magic' numbers make the code much more difficult to understand. Suggest using `#define` statements or an `enum` statement to give those 'magic' numbers meaningful names then use those meaningful names throughout the code – user3629249 Jun 22 '21 at 09:57
  • where is the `main()` function – user3629249 Jun 22 '21 at 10:03
  • strongly suggest reading about the `strcmp() function, those prototype is found in string.h` – user3629249 Jun 22 '21 at 10:06
  • regarding: `{ ok=-1;` For ease of readability and understanding, strongly suggest placing only one statement per line – user3629249 Jun 22 '21 at 10:08
  • Now the code works but the problem is I have set Serial.begin(9600) but I'm confused about what should I add clk frequency in proteus. – Ajit Jun 22 '21 at 14:15

1 Answers1

-1

You should probably include those lines:

#include <Arduino.h>
#include <HardwareSerial.h>
fpiette
  • 11,983
  • 1
  • 24
  • 46