Skip to content

Instantly share code, notes, and snippets.

@jonmarkgo
Last active August 29, 2015 13:56
Show Gist options
  • Save jonmarkgo/9058657 to your computer and use it in GitHub Desktop.
Save jonmarkgo/9058657 to your computer and use it in GitHub Desktop.
// Modified by Worapoht K. and Jonathan Gottfried
#include <SoftwareSerial.h>
#include <Servo.h>
int val = 0;
char code[10];
int bytesread = 0;
int rfidPin = 2;
#define rxPin 8
#define txPin 9
SoftwareSerial RFID = SoftwareSerial(rxPin,txPin);
// RFID reader SOUT pin connected to Serial RX pin at 2400bps to pin8
Servo myservo;
int lock = 0;
int unlock = 180;
int servoPin = 12;
void setup()
{
Serial.begin(2400); // Hardware serial for Monitor 2400bps
pinMode(rfidPin,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(rfidPin, LOW); // Activate the RFID reader
RFID.begin(2400);
myservo.attach(servoPin);
myservo.write(lock); //my servo is locked at position 0, yours might be locked at position 180 - test this!
delay(1000); //pause while the servo moves to the locked position
}
void loop()
{
if((val = RFID.read()) == 10)
{ // check for header
bytesread = 0;
while(bytesread<10)
{ // read 10 digit code
val = RFID.read();
if((val == 10)||(val == 13))
{ // if header or stop bytes before the 10 digit reading
break; // stop reading
}
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}
if(bytesread == 10)
{ // if 10 digit read is complete
Serial.print("TAG code is: "); // possibly a good TAG
Serial.println(code); // print the TAG code
if (myservo.read() >= 90)
{
myservo.write(lock); //lock
delay(3000); //let the servo move before detecting another tag
}
else {
myservo.write(unlock); //unlock
delay(3000); //let the servo move before detecting another tag
}
}
bytesread = 0;
delay(500); // wait for a second
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment