Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h> //Include the library Servo.
- #define resetRFID 13 //Define reset RFID as 13
- #define gate 8 //Define gate as 8
- String tag_read = "0000000000000"; //Creates the variable tag_read and "clean" the positions of ID
- String tag_CARD = "0B00487A7A43"; //Creates the variable tag_CARD with an ID of the Card
- int i; //Variable to count
- int position=90; //Starts with the initial value of the position of servomotor (90 degrees, closed gate)
- Servo servo; //Instance the library Servo.
- void setup()
- {
- Serial.begin(9600); //Initiates the serial with baud rate of 9600
- pinMode(resetRFID, OUTPUT); //Sets the pin D13 as an output
- servo.attach(gate); //Sets the pin D8 to be used with the servomotor
- servo.write(position); //Positions the cursor of the servomotor to the first position (90 degrees);
- digitalWrite(resetRFID, LOW); //Places the reset pin of ID12/20 module in low level (resetRFID, LOW);
- delay(5); //Wait 5 milliseconds
- digitalWrite(resetRFID, HIGH); //Places the reset pin of ID12/20 module in high level (resetRFID, HIGH);
- delay(5); //Wait 5 milliseconds
- }
- void loop ()
- {
- if(Serial.available() > 0) //If the serial receive data (ID)
- {
- le_tag(); //Execute the function of the TAG read
- identifies_tag(); //Identifies which TAG this ID belongs (Card or Capsule)
- clean_tag(); //Execute the function to clean the ID and reset the ID 12/20 module
- }
- delay(100); //Wait 100 milliseconds
- }
- void le_tag() //Funcition that reads the TAG and store the ID's TAG in a variable tag_read
- {
- i=0; //Resets the variable to read
- while(Serial.available() > 0) //While the serial receive data (ID)
- {
- tag_read[i] = Serial.read(); //Store the character that entered in serial on tag_read’s position
- i++; //Increments a variable of count
- }
- Serial.print("\n\nTAG Read:"); //Jump 2 lines and print at serial the phrase"TAG Read:"
- for(i=0;i<13;i++) Serial.print(tag_read[i]); //Take each position of ID and print at the same serial
- Serial.println(); //Jump a line at serial
- }
- void clean_tag() //Function that cleans the variable tag_read and resets the module ID 12/20 for a new read leitura
- {
- digitalWrite(resetRFID, LOW); //Places the reset pin of ID12/20 module in low level (resetRFID, LOW);
- delay(5); //Wait 5 milliseconds
- digitalWrite(resetRFID, HIGH); //Places the reset pin of ID12/20 module in high level (resetRFID, HIGH);
- delay(5); //Wait 5 milliseconds
- for(i=0;i<13;i++) tag_read[i] = '0'; //Lace to clean all the positions of the variable tag_read
- }
- void identifies_tag() //Function that identifies the TAG
- {
- boolean validate = true; //Creates a boolean variable to validate the TAG
- //Lace to compare the ID of the tag_read with the ID of the tag_CARD
- for(i=0 ; i<13 ; i++)
- {
- if(tag_read[i+1] != tag_CARD[i]) // If ID tag_read is different from the ID tag_card
- {
- validate = false; //Invalidates the tag_CARD
- }
- }
- //===========================================================
- if(validate == true)//If the "tag CARD" is not invalidated
- {
- //Changes the state of the Servo (Gate)
- if(position != 90) //If the variable position is different of 90 degrees
- {
- position = 90; //Store the value 90 in the variable position
- servo.write(position); //Positions the cursor of the servomotor at 90 degrees
- Serial.println("CARD >> Open Cancel"); //Prints in the serial the phrase "CARD >> Open Cancel"
- }
- else if(position != 175) //If the variable position is different of 175 degrees
- {
- position = 175; //Store the value 175 in the variable position
- servo.write(position); //Positions the cursor of the servomotor at 175 graus
- Serial.println("CARD >> Close Cancel"); //Prints in the serial the phrase "CARD >> Close Cancel"
- }
- delay(2000); //Wait 2 seconds to make a new reading;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement