Advertisement
Guest User

Untitled

a guest
Jun 11th, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. // RFID reader for Arduino
  2. // Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan>
  3. // Modified for Arudino by djmatic
  4. // Re-Modified for Arduino and 125Khz JsxzLz RFID Kit from Ebay by Biohazard
  5.  
  6. // RFID reader comes with 11 pins: D3 D2 D1 Rest Mcst Gnd L1 L2 PC TX VCC
  7. // We need these to be connected:
  8. // Rest to Arduino pin 2
  9. // Gnd to Arduino GND
  10. // L1 and L2 to the antenna
  11. // TX to Arduino RX0
  12. // VCC To Arduino 5V
  13.  
  14.  
  15. int val = 0;
  16. char code[14];
  17. // 2 digits manufacture code
  18. // 10 digits card code
  19. // 2 digits parity bits
  20.  
  21. int bytesread = 0;
  22.  
  23. void setup() {
  24.  
  25. Serial.begin(9600); // RFID reader TX pin, Baud rate: 9600, Data bits: 8, stop bit: 1.
  26. pinMode(2,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID RESET pin
  27. digitalWrite(2, HIGH); // Activate the RFID reader
  28. }
  29.  
  30.  
  31. void loop() {
  32.  
  33. if(Serial.available() > 0) { // if data available from reader
  34. if((val = Serial.read()) == 10) { // check for header
  35. bytesread = 0;
  36. while(bytesread < 14) { // read 14 digit code
  37. if( Serial.available() > 0) {
  38. val = Serial.read();
  39. if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
  40. break; // stop reading
  41. }
  42. code[bytesread] = val; // add the digit
  43. bytesread++; // ready to read next digit
  44. }
  45. }
  46. if(bytesread == 14) { // if 14 digit read is complete
  47. Serial.print("TAG code is: "); // possibly a good TAG
  48. Serial.println(code); // print the TAG code
  49. if(code == "3E000574393108") {
  50. Serial.print("CORRECT!");
  51. }
  52. }
  53. bytesread = 0;
  54. digitalWrite(2, LOW); // deactivate the RFID reader for a moment so it will not flood
  55. delay(250); // wait for a bit (1500)
  56. digitalWrite(2, HIGH); // Activate the RFID reader
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement