7/24/2019 Arduino RFID Door Lock 01
1/41
Arduino RFID Door Lock
7/24/2019 Arduino RFID Door Lock 01
2/41
7/24/2019 Arduino RFID Door Lock 01
3/41
***Updated 8/9/2010***
I wanted to make an easy and secure way to enter my garage. RFID was theest way to un!ock my door" e#en w$th my hands %u!! I can un!ock the door andpush $t open& I u$!t a s$mp!e c$rcu$t w$th a as$c '()ega 18 ardu$no ch$p and aID+20 RFID reader to contro! an e!ectron$c door !ock.
7/24/2019 Arduino RFID Door Lock 01
4/41
(he c$rcu$t cons$sts o% , separate parts" a Reader to read RFID tags" a -ontro!!erto accept data %rom the reader and contro! the output o% the R D and the!ectr$c door !ock. (he door !ock $s %$rst $nsta!!ed $n a door and tested w$th a 9#attery to ensure correct $nsta!!at$on. In most cases you want a orma!!y 3penc$rcu$t on the door !ock" or Fa$! 4ecure. (h$s means the door stays !ocked whenno current passes through $t. 5hen 12#D- $s passed through the e!ectromagnet$n the door !ock" a p!ate $n the !ock g$#es way and a!!ows the door to e pushedopen %ree!y.
(he reader $s p!aced on the outs$de o% the door and $s separate %rom thecontro!!er on the $ns$de so that no one can c$rcum#ent the secur$ty y reak$ngopen the Reader and try$ng to short c$rcu$t the reader. (he contro!!er rece$#esser$a! data %rom the Reader and contro!s the R !ed and the Door !ock. In th$scase I ha#e put oth on separate read oards %or test$ng. 6ere $s a #$deo
o#er#$ew o% the system $n act$on Read on to see how to u$!d one %or your se!%&
**Update**'!! o% the code" schemat$cs" and 7- des$gns ha#e een tested and re%$ned.(hey are a!! posted here as o% 8/9/2010
Updated #$deo o% the %$na! system $nsta!!ed and work$ng.
Remo#e these ads ySigning Up
Step 1: Parts Needed
http://www.instructables.com/account/gopro?sourcea=removeads&nxtPgName=Arduino+RFID+Door+Lock&nxtPg=/id/Arduino-RFID-Door-Lock/?ALLSTEPShttp://www.instructables.com/account/gopro?sourcea=removeads&nxtPgName=Arduino+RFID+Door+Lock&nxtPg=/id/Arduino-RFID-Door-Lock/?ALLSTEPShttp://www.instructables.com/account/gopro?sourcea=removeads&nxtPgName=Arduino+RFID+Door+Lock&nxtPg=/id/Arduino-RFID-Door-Lock/?ALLSTEPS7/24/2019 Arduino RFID Door Lock 01
5/41
6ere are a !$st o% parts and !$nks to 4parkFun.com where I ought them. (h$s $sthe as$c set o% parts you need to u$!d and ardu$no and a c$rcu$t to read RFIDtags $nto the ardu$no. I am assum$ng you ha#e a readoard" power supp!y andhookup w$res a!ready.
Arduino Stuff
'(mega18 w$th 'rdu$no oot!oader.9:
-rysta! 1)6; 1.:0
-apac$tor -eram$c 22pF0.2:
Res$stor 10k 3hm 1/th 5att 7(60.2:
)$n$ 7ush utton 4w$tch0.,:
http://www.sparkfun.com/commerce/product_info.php?products_id=8846http://www.sparkfun.com/commerce/product_info.php?products_id=536http://www.sparkfun.com/commerce/product_info.php?products_id=8571http://www.sparkfun.com/commerce/product_info.php?products_id=8374http://www.sparkfun.com/commerce/product_info.php?products_id=97http://www.sparkfun.com/commerce/product_info.php?products_id=8846http://www.sparkfun.com/commerce/product_info.php?products_id=536http://www.sparkfun.com/commerce/product_info.php?products_id=8571http://www.sparkfun.com/commerce/product_info.php?products_id=8374http://www.sparkfun.com/commerce/product_info.php?products_id=977/24/2019 Arduino RFID Door Lock 01
6/41
(r$p!e 3utput D R + D$%%used1.9:
RFID stuff
$ther one o% these" 20 has etter range" 12 $s sma!!erRFID Reader ID+1229.9:RFID Reader ID+20,.9:
RFID Reader reakout0.9:
reak 'way 6eaders + 4tra$ght2.:0
RFID (ag + 12:k6; 1.9:
Other
(I7,1' trans$stor
Door ock $s %rom eay.Door Fa$! 4ecure access contro! !ectr$c 4tr$ke #: 31?.:0
7/24/2019 Arduino RFID Door Lock 01
7/41
7/24/2019 Arduino RFID Door Lock 01
8/41
7/24/2019 Arduino RFID Door Lock 01
9/41
7/24/2019 Arduino RFID Door Lock 01
10/41
(he %$rst step to u$!d$ng a RFID door !ock w$th a as$c 'rdu$no $s to read oardout a as$c work$ng ardu$no. )ost 'rdu$no pre+%!ashed '()ega 18 ch$ps comew$th the de%au!t !$nk program pre $nsta!!ed. -onnect a D to d$g$ta! output 1,
and #er$%y that e#eryth$ng $s work$ng.
(he hardware port$on o% th$s RFID reader wou!d e too s$mp!e $% we used aregu!ar ardu$no w$th u$!t $n U4 programmer. 4$nce I p!an on putt$ng th$s $nto thewa!! and not touch$ng $t aga$n I dont want to use a $g u!ky ,0 ardu$no oardwhen I can uy a : '()ega 18 and make a much sma!!er custom 7-.
ecause I chose to make a as$c 'rdu$no c$rcu$t myse!% I need an e=terna! U4+@4er$a! FDI( programmer. I ha#e $nc!uded ag!e schemat$cs o% the contro!!er w$tha power supp!y u$!t %rom a ?80: #o!tage regu!ator. In test$ng I used a read
oard power supp!y.
(o get an ardu$no up and runn$ng a!! you rea!!y need $s the '()ega18 w$th theardu$no so%tware %!ashed on $t" 2= 22pF capac$tors" 1mh; crysta!" 10k ohmres$stor" push utton and a readoard. (he hookup %or th$s $s we!! known utI ha#e $nc!uded the ent$re schemat$c %or the c$rcu$t.
(he ardu$no $s go$ng to tr$gger outputs" 1 each %or Red/reen/!ue Ds" and 1to tr$gger the (I7,1' to send 12#D- to the door !ock. (he ardu$no rece$#es ser$a!data $n on $ts R= !$ne %rom the ID+20 RFID reader.
Controller_PCB.pdf 12 A
Step 3: Build the RFID Reader
http://www.instructables.com/files/orig/FD7/QLKM/GCI8P9EO/FD7QLKMGCI8P9EO.pdfhttp://www.instructables.com/files/orig/FD7/QLKM/GCI8P9EO/FD7QLKMGCI8P9EO.pdfhttp://www.instructables.com/files/orig/FD7/QLKM/GCI8P9EO/FD7QLKMGCI8P9EO.pdf7/24/2019 Arduino RFID Door Lock 01
11/41
7/24/2019 Arduino RFID Door Lock 01
12/41
7/24/2019 Arduino RFID Door Lock 01
13/41
7/24/2019 Arduino RFID Door Lock 01
14/41
ow that you ha#e your ardu$no read oarded and work$ng you can put togetherthe RFID reader port$on o% the c$rcu$t that w$!! conta$n the ID+10 or ID+20 and RD to $nd$cate the status o% the c$rcu$t. Rememer that the reader w$!! e outs$de
and separate %rom the contro!!er $ns$de so that someone cannot eas$!y reak $n.
(o u$!d th$s" we are go$ng to send :#/round o#er %rom the pr$mary read oardto a secondary read oard we are u$!d$ng the Reader on. '!so send o#er ,w$res %rom , o% the ardu$no output p$ns to contro! the R D" one %or eachco!or. 3ne more w$re" rown $n the p$ctures" w$!! e a ser$a! connect$on %or the ID+20 to ta!k to the ardu$noBs R= ser$a! $nput. (h$s $s a #ery s$mp!e c$rcu$t to connect.DBs get res$stors and a %ew po$nts on the ID+20 are t$ed to ground/:# to set thecorrect status.
(o make $t eas$er to readoard the ID+10/ID+20 4park%un se!!s a reakout oardthat a!!ows you to attach !onger p$n headers that are spaced to %$t a read oard.(h$s part and the p$nheaders and !$sted $n the parts !$st.
(he schemat$c shou!d e stra$t %orward and easy to %o!!ow.
reader_PCB.pdf 8 A
Step 4: Prora!"
($me to program your ardu$no. (h$s can e a $t tr$cky us$ng a as$c ardu$no" youmay ha#e to press the reset utton mu!t$p!e t$mes e%ore and dur$ng the %$rst parto% the up!oad. ' #ery $mportant th$ng to rememer" you 5I get an up!oad error$% you do no temporar$!y d$sconnect the ID+20 ser$a! !$ne to the ardu$noBs R= !$ne.(he '()ega18 on!y has 1 R= $nput and $t uses $t to up!oad code to ta!k to theprogrammer. D$sconnect the ID+20 wh$!e programm$ng then p!ug $t ack $n whenyour done. I used a F(DI programmer wh$ch a!!ows you to program the ardu$no#$a U4 w$th on!y w$res. (he -ontro!!er schemat$c shows a p$n headerconnect$on to a!!ow you to p!ug one $n d$rect!y. 4park%un a!so se!!s th$s part ut
many may a!ready ha#e $t.
Cou can eas$!y up!oad my code to your ardu$no and ne#er !ook ack ut whatsthe %un $n that et me e=p!a$n the as$c $dea o% how $t works.
F$rst o% a!!" I d$d not want any e=terna! uttons/sw$tches/etc and I d$d not want toreprogram the ardu$no e#ery t$me I wanted to add a new card. (here%ore
http://www.instructables.com/files/orig/FQ9/OQAQ/GCI8P9FS/FQ9OQAQGCI8P9FS.pdfhttp://www.instructables.com/files/orig/FQ9/OQAQ/GCI8P9FS/FQ9OQAQGCI8P9FS.pdf7/24/2019 Arduino RFID Door Lock 01
15/41
I wanted to use on!y RFID to contro! the operat$on o% the c$rcu$t as we!! as contro!o#er the door !ock.
(he program turns on the !ue D to $nd$cate $t $s ready to read a new card.5hen the card $s read $t dec$des $% $t $s a #a!$d card or not y compar$ng what $tread $n to a !$st o% #a!$d cards. I% the user $s #a!$d" the ardu$no turns 3FF the !ueD and turns on the reen D %or : seconds. It a!so turns on another outputh$gh %or : seconds. (h$s output $s connected to the (I7,1' trans$stor and a!!owsthe t$ny ardu$no to contro! a much !arger 12# ,00m' door !ock w$thout e$ngdamaged. '%ter : seconds the door !ock re+!ocks and the D turns ack to !ueto wa$t %or another card to e read. I% the card $s $n#a!$d then the D changes toRD %or a %ew seconds and ack to !ue to wa$t %or another card.
It $s $mportant that the door !ock st$!! work e#en $% the ardu$no !oses power
o#ern$ght or $s reset. (here%ore a!! #a!$d card IDBs are stored $n7R3) memory. (he '()ega18 has :12 ytes o% 7R3) memory. achRFID card has a : 6e= yte ser$a! numer and a 1 6e= yte -heck sum that wecan use to #er$%y there were no errors $n the transm$ss$on etween the ID+20 andthe ardu$no.
Ea!$d cards are stored $n the 7R3) y us$ng the %$rst yte as a counter. Fore=amp!e" $% there are , #a!$d cards stored the %$rst yte $n the 7R3) wou!d e,. 7R3).read G ,. Anow$ng th$s" and the %act that each ID $s : ytes !ongwe know that 1+: $s card one" +10 $s card 2 and 11+1: $s card ,. 5e can make a
!oop that !ooks through the 7R3) : ytes at a t$me and tr$es to %$nd the cardthat was read $n y the reader.
ut how can we add new cards to the 7R3) a%ter the c$rcu$t $s $nsta!!edI ha#e read $n one o% the RFID cards I ha#e and hard coded $t to e the )asterRFID card. 4o e#en $% the ent$re 7R3) $s w$ped the master card w$!! st$!!%unct$on. 5hene#er a card $s read" $t checks %$rst to see $% $t $s the )aster card" $%not" then $t cont$nues to see $% $t $s a #a!$d card or not. I% the card $s the mastercard we ha#e the ardu$no go $nto a Hprogramm$ng modeH where $t %!ashes Rand wa$ts %or another #a!$d tag to e read. (he ne=t tag that $s read $s added to
the ne=t %ree spot $n the 7R3) and the counter $s $ncremented 1 $% the carddoes not a!ready e=$st $n the 7R3) memory. (he reader then returns tonorma! mode and wa$ts %or a new card to e read.
-urrent!y I ha#e not programmed a way to de!ete a card as the reasons %orde!et$ng a card wou!d most !$ke!y e $t was !ost or sto!en. 's th$s wou!d most !$ke!ye used w$th 1+10 peop!e the eas$est th$ng to do wou!d e to hard program a
7/24/2019 Arduino RFID Door Lock 01
16/41
)aster rase card that w$!! w$pe a!! cards %rom the 7R3) then re add thema!!" wh$ch on!y takes a %ew seconds. I ha#e added code to w$pe the 7R3) utI ha#e not $mp!emented th$s %eature yet. .
(he code $s attached $n a te=t %$!e a!ong w$th a copy o% the parts !$st.
RFIDLoc.t!t1 A
Updated_Code.t!t22 A
Step #: $%pand
(h$s $s on!y some o% the coo! stu%% you can do w$th RFID. Cou cou!d e=pand th$s
much %urther w$th a -D output" !ogg$ng o% who enters and when" network/tw$tterconnect$on etc. I p!an on mak$ng a %$n$shed 7- #ers$on o% th$s c$rcu$t. I ha#ene#er made a 7- e%ore so I am st$!! work$ng on the des$gn and !ayout o% theparts. 3nce I ha#e them comp!ete I w$!! post them as we!!. I encourage anyone totake the code I ha#e wr$tten and mod$%y $t to do e#en more coo! th$ngs&
http://www.instructables.com/files/orig/F3I/3G5E/G1YQE507/F3I3G5EG1YQE507.txthttp://www.instructables.com/files/orig/FLV/OEAK/GCEVBJMU/FLVOEAKGCEVBJMU.txthttp://www.instructables.com/files/orig/F3I/3G5E/G1YQE507/F3I3G5EG1YQE507.txthttp://www.instructables.com/files/orig/FLV/OEAK/GCEVBJMU/FLVOEAKGCEVBJMU.txt7/24/2019 Arduino RFID Door Lock 01
17/41
/*RFID Door Lock10/13/2009Brett Martinwww.pcmofo.com
Sytem for contro!!in" acce #y rea$in" 12%k&' RFID car$ an$ compairin" t&eID ta" to tore$ (()RM +a!,eMater RFID car$ ,e$ to pro"ram new car$ into t&e ytem.
ID-12/ID-12 RFID rea$er
in" parkf,n #reako,t #oar$1 D ro,n$42 /RS5 Reet Rea$er4 6onnect to 7%+D63 85 64 85 64% 6) 64 6ar$ )reent4
: 6; FS Format e!ect4 "ro,n$ t&i for 8S6II4&ttp?//peop!e.interaction-i+rea.it/&.#arra"an@// an$ co$e from A6 i!e -&ttp?//&c"i!e.wor$pre.com/reo,rce/rfi$Ci$12Cta"rea$er/// Mo$ifie$ for 8r,$ino #y $matic// Mo$ifie$ for ID-12 an$ c&eck,m #y Martin 5&e - &ttp?//www.martint&e.n!///// e t&e $rawin" from A6 i!e to wire ,p t&e ID-12.// Remark? $iconnect t&e r eria! wire to t&e ID-12 w&en ,p!oa$in" t&eketc&*/
Einc!,$e >(()RM.&@ // ee$e$ to write to (()RM tora"e
E$efine power)in 10E$efine fai!)in 11E$efine pa)in 12E$efine $oor)in 13
#oo!ean pro"ramMo$e fa!eG#oo!ean matc& fa!eG
7/24/2019 Arduino RFID Door Lock 01
18/41
#yte tore$6ar$:G // Store an ID rea$ from (()RM#yte rea$6ar$:G // Sotre an ID rea$ from t&e RFID rea$er#yte c&eck,m 0G // Store t&e c&eck,m to +erify t&e ID
+oi$ et,p4H// for int i 0G i > %12G i774 // ncoment to wipe t&e (()RM// (()RM.writei 04GpinMo$epower)in 5)54G // 6onnecte$ to B!,e on tri-co!or L(D toin$icate rea$er i rea$ypinMo$epa)in 5)54G // 6onnecte$ to reen on tri-co!or L(D toin$icate ,er i +a!i$pinMo$efai!)in 5)54G // 6onnecte$ to reen on tri-co!or L(D toin$icate ,er i 5 +a!i$ or rea$ fai!e$pinMo$e$oor)in 5)54G // 6onnecte$ to re!ay to acti+ate t&e $oor!ockSeria!.#e"in9:004G // 6onnect to t&e eria! portJ
+oi$ !oop 4H#yte +a! 0G // 5emp +aria#!e to &o!$ t&e c,rrent #yte
norma!Mo$en4G // orma! mo$e #!,e )ower L(D i on a!! ot&er are off
if pro"ramMo$e4 // )ro"ram mo$e to a$$ a new ID car$Hpro"ramMo$en4G // )ro"ram Mo$e cyc!e t&ro,"& RB waitin" to rea$ a newcar$
ifSeria!.a+ai!a#!e4 @ 04 // Kait for omet&in" to come on t&e eria! !ineHif+a! Seria!.rea$44 24 // Firt Byte &o,!$ #e 2 S5= #yteH"etID4G // et t&e ID et rea$6ar$ to t&e rea$ IDif iMaterrea$6ar$4 4 // 6&eck to ee if it i t&e mater pro"ramin"car$HwriteIDrea$6ar$4G // If not write t&e car$ to t&e (()RM otra"epro"ramMo$e fa!eG // 5,rn off pro"ramin" mo$ec&eck,m 0G // Make ,re t&e c&eck,m i emptyJJJJ// orma! peration...
e!eHifSeria!.a+ai!a#!e4 @ 04 // If t&e eria! port i a+ai!a#!e an$en$in" $ata...Hif+a! Seria!.rea$44 24 // Firt Byte &o,!$ #e 2 S5= #yteH"etID4G // et t&e ID et rea$6ar$ to t&e rea$ ID#yte #yterea$ 0G
7/24/2019 Arduino RFID Door Lock 01
19/41
for int i 0G i > %G i77 4 // Loop % timeHif rea$6ar$i > 1: 4 // )rint o,t 0 if > 1: to prepen$ o,tp,tSeria!.print04G
Seria!.printrea$6ar$i A(=4G // )rint o,t t&e &e +a!,e rea$ inSeria!.print 4GJSeria!.print!n4GSeria!.print6&eck,m? 4GSeria!.printrea$6ar$% A(=4G // 6&eck,m rea$ from t&e car$
if rea$6ar$% c&eck,m 4 // See if t&e %t& BN5( t&e c&eck,m4rea$ in from t&e rea$erH // matc&e t&e c&eck,m cac,!ate$c&eck,m 0G // If o we can empty t&e +aria#!etorin" t&e ca!c,!ate$ c&eck,m//Seria!.print!n pae$4G//Seria!.print!n4Gif iMater rea$6ar$ 4 4 // 6&eck to ee if t&e car$ i t&e mater
pro"ramin" car$Hpro"ramMo$e tr,eG // If o ena#!e pro"ramin" mo$eJe!eHif fin$IDrea$6ar$4 4 // If not ee if t&e car$ i in t&e (()RMHopenDoor%4G // If it i open t&e $oor !ockJe!eHfai!e$4G // If not &ow t&at t&e ID wa not +a!i$JJJe!e // If t&e c&eck,m fai!e$H // )rint o,t t&e c&eck,m/*Seria!.print!n error4GSeria!.print!n4GSeria!.print4GSeria!.printrea$6ar$% A(=4GSeria!.print 4GSeria!.printc&eck,m A(=4GSeria!.print 4G*/
JJJJJ
// If t&e eria! port i rea$y an$ we recei+e$ t&e S5= BN5( 24 t&en t&if,nction i ca!!e$// to "et t&e BN5( ID 7 1 BN5( c&eck,m. 5&e ID7c&eck,m i tore$ inrea$6ar$:
7/24/2019 Arduino RFID Door Lock 01
20/41
// Byte 0- are t&e % ID #yte #yte % i t&e c&eck,m+oi$ "etID4H#yte #yterea$ 0G#yte i 0G#yte +a! 0G#yte temp#yte 0G
// % A(= Byte co$e i act,a!!y 10 8S6II Byte.w&i!e #yterea$ > 12 4 // Rea$ 10 $i"it co$e 7 2 $i"it c&eck,mHif Seria!.a+ai!a#!e4 @ 04 // 6&eck to make ,re $ata i comin" on t&eeria! !ineH+a! Seria!.rea$4G // Store t&e c,rrent 8S6II #yte in +a!
if+a! 00D4OO+a! 0084OO+a! 0034OO+a! 00244H // If &ea$er or top #yte #efore t&e 10 $i"itrea$in"#reakG // Stop rea$in"
J
if +a! @ P0P 4 QQ +a! > P9P 4 4 // Do 8cii/Ae con+erionH+a! +a! - P0PGJe!e if +a! @ P8P 4 QQ +a! > PFP 4 4H+a! 10 7 +a! - P8PGJ
if #yterea$ Q 1 1 4 // (+ery two 8S6II c&aractor 1 BN5( in A(=formatH// Make ome pace for t&i &e-$i"it #y// &iftin" t&e pre+io, &e-$i"it wit& #it to t&e !eft?rea$6ar$#yterea$ @@ 1 +a! O temp#yte >> 44G
if #yterea$ @@ 1 % 4 // If wePre at t&e c&eck,m #yteHc&eck,m rea$6ar$#yterea$ @@ 1G // 6a!c,!ate t&e c&eck,m ,in" =RJGJe!e // If it i t&e firt A(=c&aractorHtemp#yte +a!G // Store t&e A(= in a temp +aria#!e
JG#yterea$77G // Increment t&e co,nter to keeptrackJJ#yterea$ 0GJ
// Rea$ an ID from (()RM an$ a+e it to t&e tore$6ar$: array
7/24/2019 Arduino RFID Door Lock 01
21/41
+oi$ rea$ID int n,m#er 4 // ,m#er poition in (()RM to "et t&e % BytefromHint tart n,m#er * % 4 - G // Fi",re o,t tartin" poition//Seria!.printStart? 4G//Seria!.printtart4G//Seria!.printnn4G
for int i 0G i > %G i77 4 // Loop % time to "et t&e % ByteHtore$6ar$i (()RM.rea$tart7i4G // 8i"n +a!,e rea$ from (()RM toarray/*Seria!.printRea$ 4GSeria!.printtart7i4GSeria!.print 4GSeria!.printtore$6ar$i A(=4GSeria!.print n4G*/J
J
// Krite an array to t&e (()RM in t&e net a+ai!a#!e !ot+oi$ writeID #yte a 4Hif fin$ID a 4 4 // Before we write to t&e (()RM c&eck to ee ifwe &a+e een t&i car$ #eforeHint n,m (()RM.rea$04G // et t&e n,mer of ,e$ pace poition 0 toret&e n,m#er of ID car$/*Seria!.print,m? 4GSeria!.printn,m4GSeria!.print n4G*/int tart n,m * % 4 7 1G // Fi",re o,t w&ere t&e net !ot tart
n,m77G // Increment t&e co,nter #y one(()RM.write 0 n,m 4G // Krite t&e new co,nt to t&e co,nter
for int 0G > %G 77 4 // Loop % timeH(()RM.write tart7 a 4G // Krite t&e array +a!,e to (()RM in t&eri"&t poition/*Seria!.printK4GSeria!.printtart74G
Seria!.print Ta!,e 4GSeria!.printa A(=4GSeria!.print n4G*/J,cceKrite4GJe!eHfai!e$Krite4G
7/24/2019 Arduino RFID Door Lock 01
22/41
JJ
// 6&eck two array of #yte to ee if t&ey are eact matc&e#oo!ean c&eck5wo #yte a #yte # 4Hif a0 LL 4 // Make ,re t&ere i omet&in" in t&e arrayfirtmatc& tr,eG // 8,me t&ey matc& at firt
for int k 0G k > %G k77 4 // Loop % timeH/*Seria!.print4GSeria!.printk4GSeria!.print Rea$6ar$ 4GSeria!.printak A(=4GSeria!.print Store$6ar$ 4GSeria!.print#k A(=4GSeria!.print n4G
*/if ak #k 4 // IF a # t&en et matc& fa!e one fai!a!! fai!matc& fa!eGJif matc& 4 // 6&eck to ee if if matc& i ti!! tr,eH//Seria!.printStrin" Matc& n4Gret,rn tr,eG // Ret,rn tr,eJe!e H//Seria!.printStrin" $o not matc& n4Gret,rn fa!eG // Ret,rn fa!eJJ
// Look in t&e (()RM to try to matc& any of t&e (()RM IDP wit& t&e pae$ID#oo!ean fin$ID #yte fin$ 4Hint co,nt (()RM.rea$04G // Rea$ t&e firt Byte of (()RM t&at// Seria!.print6o,nt? 4G // tore t&e n,m#er of IDP in(()RM// Seria!.printco,nt4G//Seria!.printn4Gfor int i 1G i > co,ntG i77 4 // Loop once for eac& (()RM entryH
rea$IDi4G // Rea$ an ID from (()RM it i tore$in tore$6ar$:if c&eck5wo fin$ tore$6ar$ 4 4 // 6&eck to ee if t&e tore$6ar$ rea$from (()RMH // i t&e ame a t&e fin$ ID car$pae$//Seria!.printKe &a+e a matc&e$ car$ n4Gret,rn tr,eG#reakG // Stop !ookin" we fo,n$ itJ
7/24/2019 Arduino RFID Door Lock 01
23/41
e!e // If not ret,rn fa!eH//Seria!.printo Matc& &ere.... n4GJ
Jret,rn fa!eGJ
// pen $oor an$ t,rn on t&e "reen L(D for etDe!ay econ$+oi$ openDoor int etDe!ay 4HetDe!ay * 1000G // Set $e!ay in econ$
$i"ita!Kritepower)in LK4G // 5,rn off #!,e L(D$i"ita!Kritefai!)in LK4G // 5,rn off re$ L(D$i"ita!Kritepa)in AIA4G // 5,rn on "reen L(D$i"ita!Krite$oor)in AIA4G // n!ock $oor
$e!ayetDe!ay4G // Ao!$ $oor !ock open for % econ$
$i"ita!Krite$oor)in LK4G // Re!ock $oor$i"ita!Kritepa)in LK4G // 5,rn off "reen L(DJ
// F!a&e Re$ L(D if fai!e$ !o"in+oi$ fai!e$4H$i"ita!Kritepa)in LK4G // Make ,re "reen L(D i off$i"ita!Kritepower)in LK4G // Make ,re #!,e L(D i off
// B!ink re$ fai! L(D 3 time to in$icate fai!e$ key$i"ita!Kritefai!)in AIA4G // 5,rn on re$ L(D$e!ay%004G$i"ita!Kritefai!)in LK4G // 5,rn off re$ L(D
$i"ita!Kritefai!)in AIA4G // 5,rn on re$ L(D$e!ay%004G$i"ita!Kritefai!)in LK4G // 5,rn off re$ L(D
$i"ita!Kritefai!)in AIA4G // 5,rn on re$ L(D$e!ay%004G$i"ita!Kritefai!)in LK4G // 5,rn off re$ L(DJ
// 6&eck to ee if t&e ID pae$ i t&e mater pro"ramin" car$#oo!ean iMater #yte tet 4
H#yte #yterea$ 0G#yte i 0G // (amp!e car$ rep!ace wit& one of yo,r yo, wantto #e t&e mater#yte +a!10 HP2PPPP0PP0PP6PP8PP%PP;PP
7/24/2019 Arduino RFID Door Lock 01
24/41
for i 0G i > 10G i77 4 // Firt we nee$ to con+ert t&e array a#o+e into a% A(= BN5( arrayHif +a!i @ P0P 4 QQ +a!i > P9P 4 4 // 6on+ert one c&ar to A(=H+a!i +a!i - P0PGJe!e if +a!i @ P8P 4 QQ +a!i > PFP 4 4H+a!i 10 7 +a!i - P8PGJ
if #yterea$ Q 1 14 // (+ery two &e-$i"it a$$ #yte to co$e?H// make ome pace for t&i &e-$i"it #y// &iftin" t&e pre+io, &e-$i"it wit& #it to t&e !eft?mater#yterea$ @@ 1 +a!i O temp#yte >> 44G
if #yterea$ @@ 1 %4 // If wePre at t&e c&eck,m #yteH
c&eck,m mater#yterea$ @@ 1G // 6a!c,!ate t&e c&eck,m... =R4JGJe!eHtemp#yte +a!iG // Store t&e firt &e $i"it firt...JG#yterea$77GJ
if c&eck5wo tet mater 4 4 // 6&eck to ee if t&e mater t&e tet IDret,rn tr,eGe!eret,rn fa!eGJ
// 6ontro! L(DP for orma! mo$e B!,e on a!! ot&er off+oi$ norma!Mo$en4H$i"ita!Kritepower)in AIA4G // )ower pin an$ rea$y to rea$ car$$i"ita!Kritepa)in LK4G // Make ,re reen L(D i off$i"ita!Kritefai!)in LK4G // Make ,re Re$ L(D i off$i"ita!Krite$oor)in LK4G // Make ,re Door i Locke$J
// 6ontro! L(DP for pro"ram mo$e cyc!e t&ro,"& RB
+oi$ pro"ramMo$en4H$i"ita!Kritepower)in LK4G // Make ,re #!,e L(D i off$i"ita!Kritefai!)in LK4G // Make ,re #!,e L(D i off$i"ita!Kritepa)in AIA4G // Make ,re "reen L(D i on$e!ay2004G$i"ita!Kritepower)in LK4G // Make ,re #!,e L(D i off$i"ita!Kritefai!)in AIA4G // Make ,re #!,e L(D i on$i"ita!Kritepa)in LK4G // Make ,re "reen L(D i off$e!ay2004G
7/24/2019 Arduino RFID Door Lock 01
25/41
$i"ita!Kritepower)in AIA4G // Make ,re #!,e L(D i on$i"ita!Kritefai!)in LK4G // Make ,re #!,e L(D i off$i"ita!Kritepa)in LK4G // Make ,re "reen L(D i off$e!ay2004GJ
// F!a&e t&e "reen L(D 3 time to in$icate a ,ccef,! write to (()RM+oi$ ,cceKrite4H$i"ita!Kritepower)in LK4G // Make ,re #!,e L(D i off$i"ita!Kritefai!)in LK4G // Make ,re #!,e L(D i off$i"ita!Kritepa)in AIA4G // Make ,re "reen L(D i on$e!ay2004G$i"ita!Kritepa)in LK4G // Make ,re "reen L(D i off$e!ay2004G$i"ita!Kritepa)in AIA4G // Make ,re "reen L(D i on$e!ay2004G$i"ita!Kritepa)in LK4G // Make ,re "reen L(D i off$e!ay2004G$i"ita!Kritepa)in AIA4G // Make ,re "reen L(D i on
$e!ay2004GJ
// F!a&e t&e re$ L(D 3 time to in$icate a fai!e$ write to (()RM+oi$ fai!e$Krite4H$i"ita!Kritepower)in LK4G // Make ,re #!,e L(D i off$i"ita!Kritefai!)in AIA4G // Make ,re re$ L(D i on$i"ita!Kritepa)in LK4G // Make ,re "reen L(D i off$e!ay2004G$i"ita!Kritefai!)in LK4G // Make ,re re$ L(D i off$e!ay2004G$i"ita!Kritefai!)in AIA4G // Make ,re re$ L(D i on$e!ay2004G$i"ita!Kritefai!)in LK4G // Make ,re re$ L(D i off$e!ay2004G$i"ita!Kritefai!)in AIA4G // Make ,re re$ L(D i on$e!ay2004GJ
/*85me"a1:< wit& 8r$,ino Boot!oa$er U.9%&ttp?//www.parkf,n.com/commerce/pro$,ctCinfo.p&pVpro$,ctCi$
7/24/2019 Arduino RFID Door Lock 01
26/41
&ttp?//www.parkf,n.com/commerce/pro$,ctCinfo.p&pVpro$,ctCi$9;
5rip!e ,tp,t L(D RB - Diff,e$ U1.9%&ttp?//www.parkf,n.com/commerce/pro$,ctCinfo.p&pVpro$,ctCi$92:
RFID Rea$er ID-12 U29.9%&ttp?//www.parkf,n.com/commerce/pro$,ctCinfo.p&pVpro$,ctCi$
7/24/2019 Arduino RFID Door Lock 01
27/41
/*RFID Door Lock10/13/2009Brett Martinwww.pcmofo.com
Mo$ifie$ #y ama on 21t Y,!y 2010 for etra feat,re.....
Sytem for contro!!in" acce #y rea$in" 12%k&' RFID car$ an$ compairin" t&eID ta" to tore$ (()RM +a!,eMater RFID car$ ,e$ to pro"ram new car$ into t&e ytem.
ID-12/ID-12 RFID rea$er
in" parkf,n #reako,t #oar$1 D ro,n$42 /RS5 Reet Rea$er4 6onnect to 7%+D63 85 64 85 64% 6) 64 6ar$ )reent4
: 6; FS Format e!ect4 "ro,n$ t&i for 8S6II4
7/24/2019 Arduino RFID Door Lock 01
28/41
#oo!ean pro"ramMo$e fa!eG // Initia!i'e pro"ram mo$e to fa!e#oo!ean $e!eteMo$e fa!eG // Initia!i'e $e!ete mo$e to fa!e#oo!ean wipeMo$e fa!eG // Initia!i'e wipe mo$e to fa!e#oo!ean matc& fa!eG // initia!i'e car$ matc& to fa!e
#yte tore$6ar$:G // Store an ID rea$ from (()RM#yte rea$6ar$:G // Sotre an ID rea$ from t&e RFID rea$er#yte c&eck,m 0G // Store t&e c&eck,m to +erify t&e ID
int a!arm 0G // (tra Sec,rity
+oi$ et,p4HpinMo$epower)in 5)54G // 6onnecte$ to B!,e on tri-co!or L(D to in$icaterea$er i rea$ypinMo$epa)in 5)54G // 6onnecte$ to reen on tri-co!or L(D to in$icate,er i +a!i$pinMo$efai!)in 5)54G // 6onnecte$ to Re$ on tri-co!or L(D to in$icate,er i 5 +a!i$ or rea$ fai!e$pinMo$e$oor)in 5)54G // 6onnecte$ to re!ay to acti+ate t&e $oor !ock
pinMo$ea!arm)in 5)54G // 6onnecte$ to a!arma!arm 0GSeria!.#e"in9:004G // 6onnect to t&e eria! portJ
+oi$ !oop 4H#yte +a! 0G // 5emp +aria#!e to &o!$ t&e c,rrent #ytenorma!Mo$en4G // orma! mo$e #!,e )ower L(D i on a!! ot&er are offif a!arm 34H$i"ita!Kritea!arm)in AIA4G // 8!armSeria!.#e"in9:004GifSeria!.a+ai!a#!e4 @ 04 // Kait for omet&in" to come on t&e eria! !ineHif+a! Seria!.rea$44 24 // Firt Byte &o,!$ #e 2 S5= #yteH"etID4G // et t&e ID et rea$6ar$ to t&e rea$ IDif iMaterrea$6ar$4 4 // 6&eck to ee if it i t&e mater pro"ramin" car$or $e!ete car$H$i"ita!Kritea!arm)in LK4Ga!arm 0Gc&eck,m 0G
Je!e
c&eck,m 0G
JJc&eck,m0GJe!eH
if pro"ramMo$e4 // )ro"ram mo$e to a$$ a new ID car$
7/24/2019 Arduino RFID Door Lock 01
29/41
Hpro"ramMo$en4G // )ro"ram Mo$e cyc!e t&ro,"& RB waitin" to rea$ a new car$ifSeria!.a+ai!a#!e4 @ 04 // Kait for omet&in" to come on t&e eria! !ineHif+a! Seria!.rea$44 24 // Firt Byte &o,!$ #e 2 S5= #yteH"etID4G // et t&e ID et rea$6ar$ to t&e rea$ IDif iMaterrea$6ar$4 OO iDe!eterea$6ar$4 OO iKiperea$6ar$44 // 6&eck toee if it i t&e mater pro"ramin" car$ or $e!ete car$Hpro"ramMo$e fa!eGif iMaterrea$6ar$44openDoor24Ge!efai!e$Krite4Gc&eck,m 0GJe!eHwriteIDrea$6ar$4G // If not write t&e car$ to t&e (()RM otra"e
pro"ramMo$e fa!eG // 5,rn off pro"ramin" mo$ec&eck,m 0G // Make ,re t&e c&eck,m i emptyJJJJe!e if $e!eteMo$e 4 // De!ete mo$e to $e!ete an a$$e$ ID car$H$e!eteMo$en4G // De!ete Mo$e cyc!e t&ro,"& RB waitin" to rea$ a new car$ifSeria!.a+ai!a#!e4 @ 04 // Kait for omet&in" to come on t&e eria! !ineHif+a! Seria!.rea$44 24 // Firt Byte &o,!$ #e 2 S5= #yteH"etID4G // et t&e ID et rea$6ar$ to t&e rea$ IDif iMaterrea$6ar$4 OO iDe!eterea$6ar$4 OO iKiperea$6ar$4 4 // 6&eckto ee if it i t&e mater pro"ramin" car$ or t&e De!ete 6ar$H$e!eteMo$e fa!eGc&eck,m 0Gfai!e$Krite4GJe!e //if iMaterrea$6ar$4 QQ iDe!eterea$6ar$4 4H$e!eteIDrea$6ar$4G // If not $e!ete t&e car$ from t&e (()RM otra"e$e!eteMo$e fa!eG // 5,rn off $e!ete mo$ec&eck,m 0G // Make ,re t&e c&eck,m i emptyJ
JJJe!e if wipeMo$e 4 // Kipe mo$e to wipe o,t t&e (()RMHSeria!.en$4GwipeMo$en4Gfor int i 0G i > %12G i774 // Loop repeat eZ,a! to t&e n,m#er of array in(()RMH
7/24/2019 Arduino RFID Door Lock 01
30/41
(()RM.writei 04GJwipeMo$e fa!eGwipeMo$en4GSeria!.#e"in9:004GJ// orma! peration...e!eHifSeria!.a+ai!a#!e4 @ 04 // If t&e eria! port i a+ai!a#!e an$ en$in"$ata...Hif+a! Seria!.rea$44 24 // Firt Byte &o,!$ #e 2 S5= #yteH"etID4G // et t&e ID et rea$6ar$ to t&e rea$ ID#yte #yterea$ 0Gfor int i 0G i > %G i77 4 // Loop % timeHif rea$6ar$i > 1: 4 // )rint o,t 0 if > 1: to prepen$ o,tp,tSeria!.print04G
Seria!.printrea$6ar$i A(=4G // )rint o,t t&e &e +a!,e rea$ inSeria!.print 4GJSeria!.print!n4GSeria!.print6&eck,m? 4GSeria!.printrea$6ar$% A(=4G // 6&eck,m rea$ from t&e car$if rea$6ar$% c&eck,m 4 // See if t&e %t& BN5( t&e c&eck,m4 rea$ infrom t&e rea$erH // matc&e t&e c&eck,m cac,!ate$c&eck,m 0G // If o we can empty t&e +aria#!e torin" t&e ca!c,!ate$c&eck,m//Seria!.print!n pae$4G//Seria!.print!n4Gif iMater rea$6ar$ 4 4 // 6&eck to ee if t&e car$ i t&e materpro"ramin" car$Hpro"ramMo$e tr,eG // If o ena#!e pro"ramin" mo$ea!arm 0GJe!e if iDe!ete rea$6ar$ 4 4 // 6&eck to ee if t&e car$ i t&e $e!etioncar$H$e!eteMo$e tr,eG // If o ena#!e $e!etion mo$ea!arm 0GJe!e if iKipe rea$6ar$ 4 4 // 6&eck to ee if t&e car$ i t&e $e!etioncar$
HwipeMo$e tr,eG // If o ena#!e $e!etion mo$ea!arm 0GJe!eHif fin$IDrea$6ar$4 4 // If not ee if t&e car$ i in t&e (()RMHopenDoor24G // If it i open t&e $oor !ocka!arm 0G
7/24/2019 Arduino RFID Door Lock 01
31/41
Je!eHfai!e$4G // If not &ow t&at t&e ID wa not +a!i$a!arm77GJJJe!e // If t&e c&eck,m fai!e$H // )rint o,t t&e c&eck,m/*Seria!.print!n error4GSeria!.print!n4GSeria!.print4GSeria!.printrea$6ar$% A(=4GSeria!.print 4GSeria!.printc&eck,m A(=4GSeria!.print 4G*/J
JJJJJ
// If t&e eria! port i rea$y an$ we recei+e$ t&e S5= BN5( 24 t&en t&if,nction i ca!!e$// to "et t&e BN5( ID 7 1 BN5( c&eck,m. 5&e ID7c&eck,m i tore$ inrea$6ar$:// Byte 0- are t&e % ID #yte #yte % i t&e c&eck,m+oi$ "etID4H#yte #yterea$ 0G#yte i 0G#yte +a! 0G#yte temp#yte 0G// % A(= Byte co$e i act,a!!y 10 8S6II Byte.w&i!e #yterea$ > 12 4 // Rea$ 10 $i"it co$e 7 2 $i"it c&eck,mHif Seria!.a+ai!a#!e4 @ 04 // 6&eck to make ,re $ata i comin" on t&e eria!!ineH+a! Seria!.rea$4G // Store t&e c,rrent 8S6II #yte in +a!if+a! 00D4OO+a! 0084OO+a! 0034OO+a! 00244H // If &ea$er or top #yte #efore t&e 10 $i"it rea$in"#reakG // Stop rea$in"
Jif +a! @ P0P 4 QQ +a! > P9P 4 4 // Do 8cii/Ae con+erionH+a! +a! - P0PGJe!e if +a! @ P8P 4 QQ +a! > PFP 4 4H+a! 10 7 +a! - P8PGJif #yterea$ Q 1 1 4 // (+ery two 8S6II c&aractor 1 BN5( in A(= format
7/24/2019 Arduino RFID Door Lock 01
32/41
H// Make ome pace for t&i &e-$i"it #y// &iftin" t&e pre+io, &e-$i"it wit& #it to t&e !eft?rea$6ar$#yterea$ @@ 1 +a! O temp#yte >> 44Gif #yterea$ @@ 1 % 4 // If wePre at t&e c&eck,m #yteHc&eck,m rea$6ar$#yterea$ @@ 1G // 6a!c,!ate t&e c&eck,m ,in" =RJGJe!e // If it i t&e firt A(= c&aractorHtemp#yte +a!G // Store t&e A(= in a temp +aria#!eJG#yterea$77G // Increment t&e co,nter to keep trackJJ#yterea$ 0GJ
// Rea$ an ID from (()RM an$ a+e it to t&e tore$6ar$: array
+oi$ rea$ID int n,m#er 4 // ,m#er poition in (()RM to "et t&e % BytefromHint tart n,m#er * % 4 - G // Fi",re o,t tartin" poition//Seria!.printStart? 4G//Seria!.printtart4G//Seria!.printnn4Gfor int i 0G i > %G i77 4 // Loop % time to "et t&e % ByteHtore$6ar$i (()RM.rea$tart7i4G // 8i"n +a!,e rea$ from (()RM toarray/*Seria!.printRea$ 4GSeria!.printtart7i4GSeria!.print 4GSeria!.printtore$6ar$i A(=4GSeria!.print n4G*/JJ
// Krite an array to t&e (()RM in t&e net a+ai!a#!e !ot+oi$ writeID #yte a 4Hif fin$ID a 4 4 // Before we write to t&e (()RM c&eck to ee if we &a+eeen t&i car$ #eforeH
int n,m (()RM.rea$04G // et t&e n,mer of ,e$ pace poition 0 toret&e n,m#er of ID car$/*Seria!.print,m? 4GSeria!.printn,m4GSeria!.print n4G*/int tart n,m * % 4 7 1G // Fi",re o,t w&ere t&e net !ot tartn,m77G // Increment t&e co,nter #y one(()RM.write 0 n,m 4G // Krite t&e new co,nt to t&e co,nter
7/24/2019 Arduino RFID Door Lock 01
33/41
for int 0G > %G 77 4 // Loop % timeH(()RM.write tart7 a 4G // Krite t&e array +a!,e to (()RM in t&eri"&t poition/*Seria!.printK4GSeria!.printtart74GSeria!.print Ta!,e 4GSeria!.printa A(=4GSeria!.print n4G*/J,cceKrite4GJe!eHfai!e$Krite4GJJ
// De!ete an array tore$ in (()RM from t&e $ei"nate$ !ot+oi$ $e!eteID #yte a 4Hif fin$ID a 4 4 // Before we $e!ete from t&e (()RM c&eck to ee if we&a+e t&i car$Hfai!e$Krite4G // If notJe!eHint n,m (()RM.rea$04G // et t&e n,mer of ,e$ pace poition 0 toret&e n,m#er of ID car$int !otG // Fi",re o,t t&e !ot n,m#er of t&e car$int tartG// n,m * % 4 7 1G // Fi",re o,t w&ere t&e net !ot tartint !oopin"G // 5&e n,m#er of time t&e !oop repeatint G
int co,nt (()RM.rea$04G // Rea$ t&e firt Byte of (()RM t&at// Seria!.print6o,nt? 4G // tore t&e n,m#er of IDP in (()RM// Seria!.printco,nt4G//Seria!.printn4G!ot fin$IDSL5 a 4G //Fi",re o,t t&e !ot n,m#er of t&e car$ to $e!etetart !ot * %4 - G!oopin" n,m - !ot4 * %4Gn,m--G // Decrement t&e co,nter #y one(()RM.write 0 n,m 4G // Krite t&e new co,nt to t&e co,nter
for 0G > !oopin"G 77 4 // Loop t&e car$ &ift timeH(()RM.write tart7 (()RM.rea$tart7%744G // S&ift t&e array +a!,e to %p!ace ear!ier in t&e (()RM/*Seria!.printK4GSeria!.printtart74GSeria!.print Ta!,e 4GSeria!.printa A(=4GSeria!.print n4G
7/24/2019 Arduino RFID Door Lock 01
34/41
*/Jfor int k 0G k > %G k77 4 //S&iftin" !oopH(()RM.write tart77k 04GJ,cceDe!ete4G
JJ// Fin$ t&e !ot n,m#er of t&e i$ to #e $e!ete$int fin$IDSL5 #yte fin$ 4Hint co,nt (()RM.rea$04G // Rea$ t&e firt Byte of (()RM t&at// Seria!.print6o,nt? 4G // tore t&e n,m#er of IDP in (()RM// Seria!.printco,nt4G//Seria!.printn4Gfor int i 1G i > co,ntG i77 4 // Loop once for eac& (()RM entryH
rea$IDi4G // Rea$ an ID from (()RM it i tore$ in tore$6ar$:if c&eck5wo fin$ tore$6ar$ 4 4 // 6&eck to ee if t&e tore$6ar$ rea$ from(()RMH // i t&e ame a t&e fin$ ID car$ pae$//Seria!.printKe &a+e a matc&e$ car$ n4Gret,rn iG // 5&e !ot n,m#er of t&e car$#reakG // Stop !ookin" we fo,n$ itJJJ
// 6&eck two array of #yte to ee if t&ey are eact matc&e#oo!ean c&eck5wo #yte a #yte # 4Hif a0 LL 4 // Make ,re t&ere i omet&in" in t&e array firtmatc& tr,eG // 8,me t&ey matc& at firt
for int k 0G k > %G k77 4 // Loop % timeH/*Seria!.print4GSeria!.printk4GSeria!.print Rea$6ar$ 4GSeria!.printak A(=4GSeria!.print Store$6ar$ 4GSeria!.print#k A(=4GSeria!.print n4G
*/if ak #k 4 // IF a # t&en et matc& fa!e one fai! a!! fai!matc& fa!eGJif matc& 4 // 6&eck to ee if if matc& i ti!! tr,eH//Seria!.printStrin" Matc& n4Gret,rn tr,eG // Ret,rn tr,eJe!e H
7/24/2019 Arduino RFID Door Lock 01
35/41
//Seria!.printStrin" $o not matc& n4Gret,rn fa!eG // Ret,rn fa!eJJ
// Look in t&e (()RM to try to matc& any of t&e (()RM IDP wit& t&e pae$ID#oo!ean fin$ID #yte fin$ 4Hint co,nt (()RM.rea$04G // Rea$ t&e firt Byte of (()RM t&at// Seria!.print6o,nt? 4G // tore t&e n,m#er of IDP in (()RM// Seria!.printco,nt4G//Seria!.printn4Gfor int i 1G i > co,ntG i77 4 // Loop once for eac& (()RM entryHrea$IDi4G // Rea$ an ID from (()RM it i tore$ in tore$6ar$:if c&eck5wo fin$ tore$6ar$ 4 4 // 6&eck to ee if t&e tore$6ar$ rea$ from(()RMH // i t&e ame a t&e fin$ ID car$ pae$//Seria!.printKe &a+e a matc&e$ car$ n4G
ret,rn tr,eG#reakG // Stop !ookin" we fo,n$ itJe!e // If not ret,rn fa!eH//Seria!.printo Matc& &ere.... n4GJ
Jret,rn fa!eGJ
// pen $oor an$ t,rn on t&e "reen L(D for etDe!ay econ$+oi$ openDoor int etDe!ay 4HetDe!ay * 1000G // Set $e!ay in econ$Seria!.en$4G$i"ita!Kritepower)in LK4G // 5,rn off #!,e L(D$i"ita!Kritefai!)in LK4G // 5,rn off re$ L(D$i"ita!Kritepa)in AIA4G // 5,rn on "reen L(D$i"ita!Krite$oor)in AIA4G // n!ock $oor
$e!ayetDe!ay4G // Ao!$ $oor !ock open for 2 econ$
$i"ita!Krite$oor)in LK4G // Re!ock $oor
$e!ayetDe!ay4G // Ao!$ "reen L(D om for 2 more econ$
$i"ita!Kritepa)in LK4G // 5,rn off "reen L(DSeria!.#e"in9:004GJ
// F!a&e Re$ L(D if fai!e$ !o"in+oi$ fai!e$4HSeria!.en$4G$i"ita!Kritepa)in LK4G // Make ,re "reen L(D i off
7/24/2019 Arduino RFID Door Lock 01
36/41
$i"ita!Kritepower)in LK4G // Make ,re #!,e L(D i off// B!ink re$ fai! L(D 3 time to in$icate fai!e$ key$i"ita!Kritefai!)in AIA4G // 5,rn on re$ L(D$e!ay12004GSeria!.#e"in9:004GJ
// 6&eck to ee if t&e ID pae$ i t&e mater pro"ramin" car$#oo!ean iMater #yte tet 4H#yte #yterea$ 0G#yte i 0G // (amp!e car$ rep!ace wit& one of yo,r yo, want to #e t&emater#yte +a!10 HP2PP9PP0PP0PP9PPPP0PPFPPFPP3P JG#yte mater:G#yte c&eck,m 0G#yte temp#yte 0G#yterea$ 0G
for i 0G i > 10G i77 4 // Firt we nee$ to con+ert t&e array a#o+e into a
% A(= BN5( arrayHif +a!i @ P0P 4 QQ +a!i > P9P 4 4 // 6on+ert one c&ar to A(=H+a!i +a!i - P0PGJe!e if +a!i @ P8P 4 QQ +a!i > PFP 4 4H+a!i 10 7 +a!i - P8PGJif #yterea$ Q 1 14 // (+ery two &e-$i"it a$$ #yte to co$e?H// make ome pace for t&i &e-$i"it #y// &iftin" t&e pre+io, &e-$i"it wit& #it to t&e !eft?mater#yterea$ @@ 1 +a!i O temp#yte >> 44Gif #yterea$ @@ 1 %4 // If wePre at t&e c&eck,m #yteHc&eck,m mater#yterea$ @@ 1G // 6a!c,!ate t&e c&eck,m... =R4JGJe!eHtemp#yte +a!iG // Store t&e firt &e $i"it firt...JG#yterea$77GJif c&eck5wo tet mater 4 4 // 6&eck to ee if t&e mater t&e tet ID
ret,rn tr,eGe!eret,rn fa!eGJ
// 6&eck to ee if t&e ID pae$ i t&e wipe memory car$#oo!ean iKipe #yte tet 4H#yte #yterea$ 0G
7/24/2019 Arduino RFID Door Lock 01
37/41
#yte i 0G // (amp!e car$ rep!ace wit& one of yo,r yo, want to #e t&emater#yte +a!10 HP2PP9PP0PP0PP9PP3PPDPP 10G i77 4 // Firt we nee$ to con+ert t&e array a#o+e into a% A(= BN5( arrayHif +a!i @ P0P 4 QQ +a!i > P9P 4 4 // 6on+ert one c&ar to A(=H+a!i +a!i - P0PGJe!e if +a!i @ P8P 4 QQ +a!i > PFP 4 4H+a!i 10 7 +a!i - P8PGJif #yterea$ Q 1 14 // (+ery two &e-$i"it a$$ #yte to co$e?
H// make ome pace for t&i &e-$i"it #y// &iftin" t&e pre+io, &e-$i"it wit& #it to t&e !eft?mater#yterea$ @@ 1 +a!i O temp#yte >> 44Gif #yterea$ @@ 1 %4 // If wePre at t&e c&eck,m #yteHc&eck,m mater#yterea$ @@ 1G // 6a!c,!ate t&e c&eck,m... =R4JGJe!eHtemp#yte +a!iG // Store t&e firt &e $i"it firt...JG#yterea$77GJif c&eck5wo tet mater 4 4 // 6&eck to ee if t&e mater t&e tet IDret,rn tr,eGe!eret,rn fa!eGJ
// 6&eck to ee if t&e ID pae$ i t&e $e!etion car$#oo!ean iDe!ete #yte tet 4H#yte #yterea$ 0G#yte i 0G // (amp!e car$ rep!ace wit& one of yo,r yo, want to #e t&e$e!etion
#yte +a!10 HP2PP9PP0PP0PP9PPPP2PP0PPPP2P JG#yte mater:G#yte c&eck,m 0G#yte temp#yte 0G#yterea$ 0Gfor i 0G i > 10G i77 4 // Firt we nee$ to con+ert t&e array a#o+e into a% A(= BN5( arrayHif +a!i @ P0P 4 QQ +a!i > P9P 4 4 // 6on+ert one c&ar to A(=H
7/24/2019 Arduino RFID Door Lock 01
38/41
+a!i +a!i - P0PGJe!e if +a!i @ P8P 4 QQ +a!i > PFP 4 4H+a!i 10 7 +a!i - P8PGJif #yterea$ Q 1 14 // (+ery two &e-$i"it a$$ #yte to co$e?H// make ome pace for t&i &e-$i"it #y// &iftin" t&e pre+io, &e-$i"it wit& #it to t&e !eft?mater#yterea$ @@ 1 +a!i O temp#yte >> 44Gif #yterea$ @@ 1 %4 // If wePre at t&e c&eck,m #yteHc&eck,m mater#yterea$ @@ 1G // 6a!c,!ate t&e c&eck,m... =R4JGJe!eHtemp#yte +a!iG // Store t&e firt &e $i"it firt...JG
#yterea$77GJif c&eck5wo tet mater 4 4 // 6&eck to ee if t&e $e!ete t&e tet IDret,rn tr,eGe!eret,rn fa!eGJ
// 6ontro! L(DP for orma! mo$e B!,e on a!! ot&er off+oi$ norma!Mo$en4H$i"ita!Kritepower)in AIA4G // )ower pin an$ rea$y to rea$ car$$i"ita!Kritepa)in LK4G // Make ,re reen L(D i off$i"ita!Kritefai!)in LK4G // Make ,re Re$ L(D i off$i"ita!Krite$oor)in LK4G // Make ,re Door i Locke$J
// 6ontro! L(DP for pro"ram mo$e cyc!e t&ro,"& RB+oi$ pro"ramMo$en4H$i"ita!Kritepower)in LK4G // Make ,re #!,e L(D i off$i"ita!Kritefai!)in LK4G // Make ,re #!,e L(D i off$i"ita!Kritepa)in AIA4G // Make ,re "reen L(D i on$e!ay2004G$i"ita!Kritepower)in LK4G // Make ,re #!,e L(D i off$i"ita!Kritefai!)in AIA4G // Make ,re #!,e L(D i on$i"ita!Kritepa)in LK4G // Make ,re "reen L(D i off
$e!ay2004G$i"ita!Kritepower)in AIA4G // Make ,re #!,e L(D i on$i"ita!Kritefai!)in LK4G // Make ,re #!,e L(D i off$i"ita!Kritepa)in LK4G // Make ,re "reen L(D i off$e!ay2004GJ
// 6ontro! L(DP for $e!ete mo$e cyc!e t&ro,"& RB+oi$ $e!eteMo$en4H
7/24/2019 Arduino RFID Door Lock 01
39/41
$i"ita!Kritepower)in LK4G // Make ,re #!,e L(D i off$i"ita!Kritefai!)in AIA4G // Make ,re re$ L(D i on$i"ita!Kritepa)in LK4G // Make ,re "reen L(D i off$e!ay2004G$i"ita!Kritepower)in AIA4G // Make ,re #!,e L(D i on$i"ita!Kritefai!)in LK4G // Make ,re re$ L(D i off$i"ita!Kritepa)in LK4G // Make ,re "reen L(D i off$e!ay2004GJ
// F!a&e t&e "reen L(D 3 time to in$icate a ,ccef,! write to (()RM+oi$ ,cceKrite4HSeria!.en$4G$i"ita!Kritepower)in LK4G // Make ,re #!,e L(D i off$i"ita!Kritefai!)in LK4G // Make ,re re$ L(D i off$i"ita!Kritepa)in LK4G // Make ,re "reen L(D i on$e!ay2004G$i"ita!Kritepa)in AIA4G // Make ,re "reen L(D i on$e!ay2004G
$i"ita!Kritepa)in LK4G // Make ,re "reen L(D i off$e!ay2004G$i"ita!Kritepa)in AIA4G // Make ,re "reen L(D i on$e!ay2004G$i"ita!Kritepa)in LK4G // Make ,re "reen L(D i off$e!ay2004G$i"ita!Kritepa)in AIA4G // Make ,re "reen L(D i on$e!ay2004GSeria!.#e"in9:004GJ
// F!a&e t&e re$ L(D 3 time to in$icate a fai!e$ write to (()RM+oi$ fai!e$Krite4HSeria!.en$4G$i"ita!Kritepower)in LK4G // Make ,re #!,e L(D i off$i"ita!Kritefai!)in LK4G // Make ,re re$ L(D i on$i"ita!Kritepa)in LK4G // Make ,re "reen L(D i off$e!ay2004G$i"ita!Kritefai!)in AIA4G // Make ,re re$ L(D i on$e!ay2004G$i"ita!Kritefai!)in LK4G // Make ,re re$ L(D i off$e!ay2004G$i"ita!Kritefai!)in AIA4G // Make ,re re$ L(D i on$e!ay2004G$i"ita!Kritefai!)in LK4G // Make ,re re$ L(D i off$e!ay2004G
$i"ita!Kritefai!)in AIA4G // Make ,re re$ L(D i on$e!ay2004GSeria!.#e"in9:004GJ
// F!a&e t&e #!,e L(D 3 time to in$icate a ,cce $e!ete to (()RM+oi$ ,cceDe!ete4HSeria!.en$4G$i"ita!Kritepower)in LK4G // Make ,re #!,e L(D i off
7/24/2019 Arduino RFID Door Lock 01
40/41
$i"ita!Kritefai!)in LK4G // Make ,re re$ L(D i off$i"ita!Kritepa)in LK4G // Make ,re "reen L(D i on$e!ay2004G$i"ita!Kritepower)in AIA4G // Make ,re #!,e L(D i off$e!ay2004G$i"ita!Kritepower)in LK4G // Make ,re #!,e L(D i off$e!ay2004G$i"ita!Kritepower)in AIA4G // Make ,re #!,e L(D i off$e!ay2004G$i"ita!Kritepower)in LK4G // Make ,re #!,e L(D i off$e!ay2004G$i"ita!Kritepower)in AIA4G // Make ,re #!,e L(D i off$e!ay2004GSeria!.#e"in9:004GJ
// 6ontro! L(DP for wipe mo$e cyc!e t&ro,"& B+oi$ wipeMo$en4H$i"ita!Kritepower)in LK4G // Make ,re #!,e L(D i off
$i"ita!Kritefai!)in LK4G // Make ,re re$ L(D i off$i"ita!Kritepa)in LK4G // Make ,re "reen L(D i off$e!ay%04G$i"ita!Kritepower)in AIA4G // Make ,re #!,e L(D i on$i"ita!Kritepa)in LK4G // Make ,re "reen L(D i off$e!ay2004G$i"ita!Kritepower)in LK4G // Make ,re #!,e L(D i off$i"ita!Kritepa)in AIA4G // Make ,re "reen L(D i on$e!ay2004G$i"ita!Kritepower)in AIA4G // Make ,re #!,e L(D i on$i"ita!Kritepa)in LK4G // Make ,re "reen L(D i off$e!ay2004G$i"ita!Kritepower)in LK4G // Make ,re #!,e L(D i off$i"ita!Kritepa)in AIA4G // Make ,re "reen L(D i on$e!ay2004G$i"ita!Kritepower)in LK4G // Make ,re #!,e L(D i off$i"ita!Kritepa)in LK4G // Make ,re "reen L(D i on$e!ay2004G$i"ita!Kritefai!)in AIA4G // Make ,re "reen L(D i onJ
/*85me"a1:< wit& 8r$,ino Boot!oa$er U.9%&ttp?//www.parkf,n.com/commerce/pro$,ctCinfo.p&pVpro$,ctCi$
7/24/2019 Arduino RFID Door Lock 01
41/41
Mini ),& B,tton Switc& U0.3%&ttp?//www.parkf,n.com/commerce/pro$,ctCinfo.p&pVpro$,ctCi$9;
5rip!e ,tp,t L(D RB - Diff,e$ U1.9%&ttp?//www.parkf,n.com/commerce/pro$,ctCinfo.p&pVpro$,ctCi$92:
RFID Rea$er ID-12 U29.9%&ttp?//www.parkf,n.com/commerce/pro$,ctCinfo.p&pVpro$,ctCi$