Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. #include <Servo.h> //Include the library Servo.
  2.  
  3. #define resetRFID 13 //Define reset RFID as 13
  4. #define gate 8 //Define gate as 8
  5.  
  6. String tag_read = "0000000000000"; //Creates the variable tag_read and "clean" the positions of ID
  7. String tag_CARD = "0B00487A7A43"; //Creates the variable tag_CARD with an ID of the Card
  8.  
  9. int i; //Variable to count
  10. int position=90; //Starts with the initial value of the position of servomotor (90 degrees, closed gate)
  11.  
  12. Servo servo; //Instance the library Servo.
  13.  
  14. void setup()
  15. {
  16.  
  17. Serial.begin(9600); //Initiates the serial with baud rate of 9600
  18.  
  19. pinMode(resetRFID, OUTPUT); //Sets the pin D13 as an output
  20. servo.attach(gate); //Sets the pin D8 to be used with the servomotor
  21. servo.write(position); //Positions the cursor of the servomotor to the first position (90 degrees);
  22.  
  23. digitalWrite(resetRFID, LOW); //Places the reset pin of ID12/20 module in low level (resetRFID, LOW);
  24. delay(5); //Wait 5 milliseconds
  25. digitalWrite(resetRFID, HIGH); //Places the reset pin of ID12/20 module in high level (resetRFID, HIGH);
  26. delay(5); //Wait 5 milliseconds
  27.  
  28. }
  29.  
  30. void loop ()
  31. {
  32.  
  33. if(Serial.available() > 0) //If the serial receive data (ID)
  34. {
  35.  
  36. le_tag(); //Execute the function of the TAG read
  37. identifies_tag(); //Identifies which TAG this ID belongs (Card or Capsule)
  38. clean_tag(); //Execute the function to clean the ID and reset the ID 12/20 module
  39. }
  40.  
  41. delay(100); //Wait 100 milliseconds
  42.  
  43. }
  44.  
  45. void le_tag() //Funcition that reads the TAG and store the ID's TAG in a variable tag_read
  46. {
  47.  
  48. i=0; //Resets the variable to read
  49. while(Serial.available() > 0) //While the serial receive data (ID)
  50. {
  51. tag_read[i] = Serial.read(); //Store the character that entered in serial on tag_read’s position
  52. i++; //Increments a variable of count
  53.  
  54. }
  55.  
  56. Serial.print("\n\nTAG Read:"); //Jump 2 lines and print at serial the phrase"TAG Read:"
  57.  
  58. for(i=0;i<13;i++) Serial.print(tag_read[i]); //Take each position of ID and print at the same serial
  59. Serial.println(); //Jump a line at serial
  60.  
  61. }
  62.  
  63. void clean_tag() //Function that cleans the variable tag_read and resets the module ID 12/20 for a new read leitura
  64. {
  65.  
  66. digitalWrite(resetRFID, LOW); //Places the reset pin of ID12/20 module in low level (resetRFID, LOW);
  67. delay(5); //Wait 5 milliseconds
  68. digitalWrite(resetRFID, HIGH); //Places the reset pin of ID12/20 module in high level (resetRFID, HIGH);
  69. delay(5); //Wait 5 milliseconds
  70.  
  71. for(i=0;i<13;i++) tag_read[i] = '0'; //Lace to clean all the positions of the variable tag_read
  72.  
  73. }
  74.  
  75. void identifies_tag() //Function that identifies the TAG
  76. {
  77.  
  78. boolean validate = true; //Creates a boolean variable to validate the TAG
  79.  
  80. //Lace to compare the ID of the tag_read with the ID of the tag_CARD
  81. for(i=0 ; i<13 ; i++)
  82. {
  83.  
  84. if(tag_read[i+1] != tag_CARD[i]) // If ID tag_read is different from the ID tag_card
  85. {
  86. validate = false; //Invalidates the tag_CARD
  87. }
  88.  
  89. }
  90.  
  91. //===========================================================
  92.  
  93. if(validate == true)//If the "tag CARD" is not invalidated
  94. {
  95.  
  96. //Changes the state of the Servo (Gate)
  97. if(position != 90) //If the variable position is different of 90 degrees
  98. {
  99. position = 90; //Store the value 90 in the variable position
  100. servo.write(position); //Positions the cursor of the servomotor at 90 degrees
  101. Serial.println("CARD >> Open Cancel"); //Prints in the serial the phrase "CARD >> Open Cancel"
  102. }
  103.  
  104. else if(position != 175) //If the variable position is different of 175 degrees
  105. {
  106. position = 175; //Store the value 175 in the variable position
  107. servo.write(position); //Positions the cursor of the servomotor at 175 graus
  108. Serial.println("CARD >> Close Cancel"); //Prints in the serial the phrase "CARD >> Close Cancel"
  109.  
  110. }
  111.  
  112. delay(2000); //Wait 2 seconds to make a new reading;
  113. }
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement