Introduction: WiFi RFID Reader

The main idea was to read in 13.56 MHz RFID (tags / tokes / stickers / wristbands / cards) by a magic box and post the RFID UID to a local database by WiFi network.

This instructable builds the base of the whole system - the first working RFID reader on ESP8266 WiFi SoC. (many thanks to nikxha from the ESP8266 forum for the initial help)

Step 1: Requirements

You have to install the Arduino IDE 1.6.4. or 1.6.5.

  • Arduino > Preferences > "Additional Boards Manager URLs:" and add: http://arduino.esp8266.com/package_esp8266com_index.json
  • Arduino > Tools > Board > Boards Manager > type in ESP8266 and install the board
  • download MFRC522 module (see Libraries) and copy folder to Arduino library path

Libraries

Step 2: Wiring RFID RC522 Module

wiring the MFRC522 to ESP8266 (ESP-12)
(please use wiring below instead of diagram above)

RST = GPIO05 (free GPIO)
SS = GPIO4 (free GPIO)
MOSI = GPIO13 (HW SPI)
MISO = GPIO12 (HW SPI)
SCK = GPIO14 (HW SPI)
GND = GND
3.3V = 3.3V

Step 3: Software

define RFID module

#include "MFRC522.h"
#define RST_PIN 15 // RST-PIN for RC522 - RFID - SPI - Modul GPIO15 
#define SS_PIN 2 // SDA-PIN for RC522 - RFID - SPI - Modul GPIO2
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance

Initialize RFID module

void setup() {
Serial.begin(9600); // Initialize serial communications
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
}

Read RFID tag

void loop() { 
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
delay(50);
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
delay(50);
return;
}
// Show some details of the PICC (that is: the tag/card)
Serial.print(F("Card UID:"));
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
Serial.println();
} // Helper routine to dump a byte array as hex values to Serial
void dump_byte_array(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], HEX);
}
}

Step 4: Final Steps ...

As I wrote at the beginn of this short instructable, this is just the base.
But you can make many funny projects by using this hard and software.

For my next project I'm using not only the RFID module (SPI), I will use a small OLED display (I2C), and toggle button.
The boxes are fully self configurable by one master RFID card.
There is also a webinterface to manage all boxes and add some topics, tags and description.

If I'm finished the project, I will upload it to instructables - so stay tuned.
There will be also a link here to the new tutorial.

Comments

author
omersiar (author)2017-08-13

Check out my project, too. It's in its early steps but it is also quite usable right now.
https://github.com/omersiar/esp-rfid

author
JorgenVikingGod (author)omersiar2017-08-13

I really can recommend this project!

author
inghaj (author)2017-04-22

Hi

Im a bit new to this. Im trying to use an ESP-12E and an RC522 to make this (no other Board, as I see some Arduino Boards in some of the pictures).

I've followed this instructions, and everything appears to work fine... except after "Scan for Card and print UID:" I get no cards read :-(

Im using Arduino IDE 1.6.5 and I've tried both pin combinations, but no joy

Should this work on just an ESP-12E?

Any suggestions ?

Thanks !

IMG_9750.JPG
author
PedroT54 (author)inghaj2017-06-07

Did u solved it? please if u did, tell me how!

author
JorgenVikingGod (author)PedroT542017-06-08

Hi Pedro, sorry did not see your comment. As I can see in your picture, you are using the NodeMCU board.
Maybe the pin mapping is different to the raw ESP-12E Board.

This wiring should work for you:
SS      - D4 (GPIO2)
SCK   - D5 (GPIO14) (hw spi)
MOSI - D7 (GPIO13) (hw spi)
MISO - D6 (GPIO12) (hw spi)
IRQ    -
GND  - G
RST   - D3 (GPIO0) (FLASH)
3.3V   - 3V3

and just use this defines into the demo sketch will do the job:
#define RST_PIN D3
#define SS_PIN D4

Best regards, Jorgen

esp8266_devkit_horizontal-01.png
author
PedroT54 (author)JorgenVikingGod2017-06-08

Thanks for the answer, but I already tried to use that pins, but without sucess. I tried all free GPIO as SS and RST, but it dont work. I switched my IDE for the 1.6.5 version hoping it works, but failed. My code is an example of the MFRC522 library that runs perfectly in arduino. Any other tips?

author
PuiuM2 (author)2017-01-17

Hi, did you managed to connect the OLED display?

author
JorgenVikingGod (author)PuiuM22017-01-19

Hi - yes it worked perfectly. But only with I2C. SPI is not working on the same port, because the RFID module is requesting different SPI header than most tft displays.

author
PuiuM2 (author)JorgenVikingGod2017-01-19

can u pls post the code and the schematic for ESP+I2C+RFID? I will try to modify it for my purpose. TY!

author
JorgenVikingGod (author)PuiuM22017-01-19

Sorry, I do not have a short example.
But you can just try to use f.e. this lib for I2C OLED display:
https://github.com/squix78/esp8266-oled-ssd1306
wiring is very simple: 3.3V, GND, SCL, SDA
Just use the SCL and SDA (I2C) Pins of ESP8266

author
RafaelS122 made it! (author)2017-01-18

Hi, thanks for this project! It's exactly what i was looking for.

I'm uploading the sketch and everything is fine. But after the serial message:

"....WiFi connected

Ready!

===============

Scan for Card and print UID:"

It don't print the UID card from my tags!

I'm using Arduino IDE 1.6.4

I tried to change gpio RST and SS but nothing happen!

There's anyway i can test my SPI connections?

I'm using an ESP-07

RST = GPIO15 and 5

SDA(SS) = GPIO2 and 4

MOSI = GPIO13

MISO = GPIO12

SCK = GPIO14

GND = GND

3.3V = 3.3V

Thank you JOrgen

16128714_1506984972663744_381330333_n.jpg16144629_1506984945997080_865413482_n.jpg
author

Hi Rafael,
maybe you have a old style ESP-12 clone with switched GPIO04/05 pins.
So you have to use GPIO04 for RST and GPIO05 for SS.
Hope it will work that way.

My git is more up to date - and maybe in some closed issues you can find more information.
https://github.com/Jorgen-VikingGod/ESP8266-MFRC52...

Best regards and good luck, Jorgen

author
thiagogm (author)2016-11-17

Hi, Can I use instead GPIO13 and 12, MOSI and MISO from the ESP12e?
And what I need to do for this?

Thanks!

author
Rene MisaelG made it! (author)2016-09-24

Exelente, funciona, ahora puedo hacer algunas practicas, les agradesco de corazon. Saludos desde GDL

IMG_20160924_105256.jpg
author
SaschaT2 (author)2016-09-07

hi, i try this one, and didnt get it work.

I cant upload the Code, when the rfid-rc522 board is connected.

i get this Message :

warning: espcomm_sync failed
error: espcomm_open failed
error: espcomm_upload_mem failed

When i disconnect the rfid Board, i can upload the Code. But it still doesnt work.
Does someone have a idea ? i try a diffrent esp12e, the same result.

author
SaschaT2 (author)SaschaT22016-09-14

i changed the rst and ss pin ... and everything works.

author
JorgenVikingGod (author)SaschaT22016-09-14

Good to hear.
Maybe you have one of these cheap chinies copy of ESP SoCs
where GPIO4 and GPIO5 is wrong labeled .

author
VasilisA1 (author)2016-08-25

Hello have you tried connecting the rfid to an esp12e and a servo?Because when i startup the esp with the servo connected i get constant reboots.

author

Hi Vasilis,
no I did not yet.
But I think this depends on how you are using your servo...

It is very important that you avoid using long delays or loops with heavy stuff - because the ESP is not "realtime" and using internal interrupts for the WiFi stack.

I had similar issues with servos in the past.
My solution was not to nice, but working fine:
- using a I2C multiplex PWM board - like this:
http://www.aliexpress.com/item/Free-Shipping-16-Channel-12-bit-PWM-Servo-Driver-I2C-interface-PCA9685-for-arduino-or-Raspberry/32228349211.html?spm=2114.01010208.3.20.S0u7WE&ws_ab_test=searchweb201556_10,searchweb201602_2_10057_10056_10065_10037_10055_10054_301_10059_10033_10058_10032_10017_107_10060_10061_10052_414_10062_10053_10050_10051,searchweb201603_9&btsid=2874df8f-e32b-4657-8c88-7a3924b5f506


So please check first your code, if you have long delays or loops and try to avoid them.
Or you have a board like that above - it should also work.

Hope you can fix your issues.

author

ok Jorgen thanks a lot i will check it out !

author
fablab 013 (author)2016-08-04

phew, after many frustration hours we can confirm that switching back from IDE 1.6.7 to IDE 1.6.4 helped a lot to get things working. We now have a MFRC522 hooked up to an espduino (ESP8266-13) and all is working fine.

To see more on our RFID + WIFI project and code example visit :

http://fablab013.nl/blog/internet-of-things-iot-es...

author

This is the reason I recommend the Arduino IDE 1.6.5
everything newer did not work :(

author
ChrisH436 (author)2016-06-19

I'm having issues getting this to run. The code compiles with no problem, but it just keeps searching for cards and isn't reading any of the tags. Do you know of any ways to debug where the issue is occurring? I'm using cards that I know are compatible.

author

Hi Chris, what pins did you use.
I have to change the description - not on each ESP8266 version the pin mapping is working.
Can you try following setup:
```
MISO - GPIO12 (hw spi)

MOSI - GPIO13 (hw spi)

SCK - GPIO14 (hw spi)

SS - GPIO04 (free GPIO)

RST - GPIO05 (free GPIO)
```

author

Thanks for the update, but still no luck! I have the pins setup as you indicated on the esp8266 huzzah (12 i think).

Is there any way to check if the RFID reader is connected? That might help determine if there is a card issue.

I do also get this warning when I upload code:

WARNING: library rfid-master claims to run on [avr architecture(s) and may be incompatible with your current board which runs on STM32F1 architecture(s).

author
MarcoM166 (author)ChrisH4362016-06-30

I got the same problems as Chris. The code works on the Arduino Uno, but not on my Sparkfun ESP8266 WiFi Shield. (I tried 4/5 and 2/15 links for SS/RST)

author
MalikS19 (author)2016-05-24

My problem when in build and display a description like this ,

"warning: espcomm_sync failed"

"error: espcomm_open failed"

"error: espcomm_upload_mem failed"

please explanation

author
JorgenVikingGod (author)MalikS192016-05-24

maybe you do not force the ESP8266 to flash mode?
Please connect CPIO0 to GND before power up, to force flash mode.

author
MalikS19 (author)JorgenVikingGod2016-05-24

thank you for advice , I will try

author
JorgenVikingGod (author)MalikS192016-05-24

you are welcome - hope it works

author
LeeB50 (author)2016-05-09

how long do the bateries last for ?

author
JorgenVikingGod (author)LeeB502016-05-09

not that long - it depends on the activity.
But if you want to react intime on new tags, you can not send the ESP8266 into deep sleep - this means the controller is online the whole time.
I would say (did not test it yet) with 3 AA batteries ~ 1 week...

author
GuohuiD (author)2016-04-29

Hi, guys, thank you very much, ’cause this is just what I am looking for.

author
MirosławD (author)2016-01-04

Will it work with bank proximity cards like visa/mastercard pay wave ?

It would be nice to get the UUID of that card, i do not need nothing more really.

Just need to use banking card as user ID card for opening refrigerator :)

SO i would like to add a banking card of a person as a key, adding a UUID of that card to the allow list for relay to open electromagnetic lock.

It must be cheap, i know that PN523 reader can read bank cards, because i have tested it with NfcLib under console, but does the RC522 much cheaper reader module can handle reading that cards serial number ? as far as i know it is different than mifare, because it has 10 bit number, and mifare has got 5 bit number.

Does moguls library handle it ?

author

I never tried this before. But I think it is possible to read the serial number.
The different between PN532 and RC522 is, that PN532 can also read active tags like smartphones (=NFC) and not only passive tags.
So the RFID chip of the creditcards is also passive and fits in the 13.56 MHz frequency

You have to try it out. If it did not work, you have to change some parts of the library to read in the correct section/block by amount of bits

I think it is not that hard to solve

author
MirosławD (author)2016-01-03

RFID-ESP:1: error: expected unqualified-id before '/' token

/define RFID module

^

In file included from /Users/test/Documents/Arduino/libraries/rfid/MFRC522.h:79:0,

from /Users/test/Documents/Arduino/RFID-ESP/RFID-ESP.ino:2:

/Users/test/Documents/Arduino/hardware/esp8266com/esp8266/libraries/SPI/SPI.h: In constructor 'SPISettings::SPISettings()':

/Users/test/Documents/Arduino/hardware/esp8266com/esp8266/libraries/SPI/SPI.h:46:66: error: 'SPI_MODE0' was not declared in this scope

SPISettings() :_clock(1000000), _bitOrder(LSBFIRST), _dataMode(SPI_MODE0){}

^

exit status 1

expected unqualified-id before '/' token

so not working for me with esp12

author

it seems like, you have a syntax error, by missing one / in the comment line

author

True , i missed that, but there is another problem with my hardware setup:

warning: serialport_set_baudrate: baud rate 921600 may not work

error: setattr stage 1 failed

error: espcomm_open failed

I'm working on OS X 10.11.2 with Arduino SDK 1.6.7

I'm using native standalone ESP12 on breadboard. and also i've tested with D1 board, that should work out of the box.

http://www.wemos.cc/d1/Main_Page

I use D1 retired version.

It seems that there are some problems on os x and actual version of arduino to work with esp.

Any idea how to fix it ?

=======

Second and most important question, as the reason i want to run that setup is to know if i can read UUID of MasterCard/visa canticles cards with this library .

I do not need to read all secure data, just the UUID/serial number of card.

author

As I know there is no stable ESP8266 board library for ArduinoIDE 1.6.7 yet.
So please use for this project the environment I wrote in this description.
And please read also once the manual of ESP8266 - this could help to avoid minor errors; like setting to high baud rates etc...

author

In fact i just cleaned the system, installed the arduino 1.6.4, configured the arduino adding board support, installed the tools.

Imported hello world sketch, and...

error: setattr stage 1 failed

error: espcomm_open failed

author

I just borrowed old PC laptop from a brother in low, and have the same problems, so 1.6.7 is "no go" for ARDUINO + ESP at this moment.

I'll try downgrading, as you suggest , i read "You have to install the Arduino IDE 1.6.4. or higher." 1.6.7 is higher :D

I've posted results from very high baud, but the same problem occures from 9600 to highest, so it is not baud relative.

Thank you for all your help.

author

Oh thanx for the hint with my bad description :D
I will change this. As I did this example I figured out it worked only on 1.6.4 and higher - but did not mind that arduino ide changes too fast for the ESP board fork...

Hope you can run the sketch with Arduino IDE 1.6.5 (this version is working fine for me)

author
filtaf made it! (author)2015-08-31

plz tell me how to make

temp_-1968681497.jpg
author
JorgenVikingGod (author)filtaf2015-09-01

Hi, what exactly you want to know?

author
DevishJ (author)JorgenVikingGod2015-12-26

Hi, I am creating a Wifi Rfid Card Reader.

I am using ESP8266 E 01, Arduino Uno, MFRC522 card reader.

I am able to communicate Arduino with ESP8266 and Arduino with MFRC522 individually, but I do not know how to integrate these both. Can you please help me with this.

Thanks in advance

author
JorgenVikingGod (author)DevishJ2015-12-29

If you have more space I will use a ESP8266 ESP-12 or ESP-07 instead. In that case you do not need the expensive and slow arduino - you can just connect the RFID reader module directly to the ESP SoC.

In other case you will read your cards by the Arduino by connecting the RFID module by SPI serial interface and the ESP8266 by UART (RX/TX)
There are mass of source code out there how to use WiFi with ESP connected by serial.

author
ChiaweiT (author)2015-10-25

Can use ESP8266 to be a webserver and show the RFID UID on webserver?

author
JorgenVikingGod (author)ChiaweiT2015-10-25

Yes of course you can. There are many examples out there - how to serve a webpage by ESP8266. You have only need to read the UID and post the data to your website content.

author
EcoExpatMike (author)2015-08-24

So this thing can scan my passport and new credit cards?

author

I do not have any passport with RFID chip here. But as I know, they have also 13.56 MHz frequency - really similar to the NFC standard. So it should be possible to read it by the MFRC522. Otherwise you need the newer RFID module (PN532).
If you have the components at home - it would be nice to see, if it can scan the passport as well.