background image

"7A005B0FF8D6"

};

 

//

 

Empty

 

array

 

to

 

hold

 

a

 

freshly

 

scanned

 

tag

char newTag[idLen];

void setup()

 

{

//

 

Starts

 

the

 

hardware

 

and

 

software

 

serial

 

ports

   

Serial.begin(9600);

   

rSerial.begin(9600);

//

 

Attaches

 

the

 

servo

 

to

 

the

 

pin

   

lockServo.attach(servoPin);

//

 

Put

 

servo

 

in

 

locked

 

position

   

lockServo.write(0);

}

 

void loop()

 

{

//

 

Counter

 

for

 

the

 

newTag

 

array

int i

 

= 0;

//

 

Variable

 

to

 

hold

 

each

 

byte

 

read

 

from

 

the

 

serial

 

buffer

int readByte;
//

 

Flag

 

so

 

we

 

know

 

when

 

a

 

tag

 

is

 

over

boolean tag

 

= false;

//

 

This

 

makes

 

sure

 

the

 

whole

 

tag

 

is

 

in

 

the

 

serial

 

buffer

 

bef

ore

//

 

reading,

 

the

 

Arduino

 

can

 

read

 

faster

 

than

 

the

 

ID

 

module

 

c

an

 

deliver!

if (rSerial.available()

 

== tagLen)

 

{

    

tag

 

= true;

  

}

 

if (tag

 

== true)

 

{

while (rSerial.available())

 

{

//

 

Take

 

each

 

byte

 

out

 

of

 

the

 

serial

 

buffer,

 

one

 

at

 

a

 

tim

e

      

readByte

 

= rSerial.read();

/*

 

This

 

will

 

skip

 

the

 

first

 

byte

 

(2,

 

STX,

 

start

 

of

 

tex

t)

 

and

 

the

 

last

 

three,

 

      

ASCII

 

13,

 

CR/carriage

 

return,

 

ASCII

 

10,

 

LF/linefeed,

 

an

d

 

ASCII

 

3,

 

ETX/end

 

of

  

      

text,

 

leaving

 

only

 

the

 

unique

 

part

 

of

 

the

 

tag

 

string.

 

I

t

 

puts

 

the

 

byte

 

into

 

      

the

 

first

 

space

 

in

 

the

 

array,

 

then

 

steps

 

ahead

 

one

 

spot

 

*/

if (readByte

 

!= 2 && readByte!= 13 && readByte

 

!= 10 &&

readByte

 

!= 3)

 

{

        

newTag[i]

 

= readByte;

        

i++;

      

}

 

//

 

If

 

we

 

see

 

ASCII

 

3,

 

ETX,

 

the

 

tag

 

is

 

over

if (readByte

 

== 3)

 

{

        

tag

 

= false;

      

}

 

    

}

 

  

}

 

//

 

don't

 

do

 

anything

 

if

 

the

 

newTag

 

array

 

is

 

full

 

of

 

zeroes

if (strlen(newTag)== 0)

 

{

Page 8 of 10

Содержание RFID Starter Kit

Страница 1: ...reader to a computer Recommended Reading The ID 12LA module has a serial output If you ve never worked with a serial device or a terminal program before you might want to take a look at these tutorial...

Страница 2: ...sy of EPC RFID Passive tags like the ones included with this kit gather electromagnetic energy from the card reader and use that to transmit their unique serial number More sophisticated tags may have...

Страница 3: ...ing features 1 A buzzer that sounds when a card is read If you are using the RFID kit in a stealth application you can disconnect the buzzer by removing the blob of solder on the Buzz jumper 2 A card...

Страница 4: ...Serial Monitor The default terminal settings 9600 baud no line ending are fine The monitor should be blank Wave a card over the reader You should hear a beep and see something like this Now we ll do...

Страница 5: ...an again Now the bread is visible That s cool right Example Project As fun as it is to watch your cards pop up in the serial terminal you d probably like to do something with all this power The exampl...

Страница 6: ...pins on the RFID USB Reader to the Arduino s 5V GND and D2 pins and connect the servo to 5V GND and D9 Upload the below code open your Serial Monitor by going to Tools Serial Monitor and start scanni...

Страница 7: ...y adapted from http bildr org 2011 02 rfid arduino include SoftwareSerial h include Servo h Choose two pins for SoftwareSerial SoftwareSerial rSerial 2 3 RX TX Make a servo object Servo lockServo Pick...

Страница 8: ...ing the Arduino can read faster than the ID module c an deliver if rSerial available tagLen tag true if tag true while rSerial available Take each byte out of the serial buffer one at a tim e readByte...

Страница 9: ...next tag read for int c 0 c idLen c newTag c 0 This function steps through both newTag and one of the know n tags If there is a mismatch anywhere in the tag it will r eturn 0 but if every character in...

Страница 10: ...the module removed so you can read the silk Resources and Going Further You can use the SparkFun RFID Reader Kit and an Arduino to control access to just about anything Instead of moving a servo how a...

Отзывы: