Friday, March 1, 2019

ESP32 with mfr522 electricalkida

          

ESP 32 With RFID MFRC522 Electricalkida.blogspot.com

ESP32 Microcontroller

ESP32 is best module for WiFi and bluetooth .It is also capable for arduino IDE.it is single 2.4 GHz Wi-Fi-and-Bluetooth combo chip designed with the TSMC ultra-low-power 40 nm technology. IT is also provided sleep Mode .It is designed to achieve the best power and RF performance, showing robustness, versatility and reliability in a wide variety of applications and power scenarios. ESP32 is created and developed by Espressif Systems, a Shanghai-based Chinese company. ESP32 is a highly-integrated solution for Wi-Fi-and-Bluetooth IoT applications, with around 20 external components. ESP32 Has 20GPIO pins:
Pin diagram of esp32:

3.2.2 RC-522 13.56 MHz RFID Reader
RFID means radio-frequency identification. RFID uses electromagnetic fields to transfer data over short distances. RFID is useful to identify people, to make transactions, Authnetication etc.


This low cost MFRC522 based RFID Reader Module is easy to use and can be used in a wide range of applications. RC522 is a highly integrated transmission module for contactless communication at 13.56 MHz this transmission module utilizes an outstanding modulation and demodulation concept completely integrated for different kinds of contactless communication methods and protocols at 13.56 MHz.





          

            


      



             Working Of RFID Reader
An RFID system basically consists of a transceiver with a decoder and an antenna and a transponder. And how it works? These cards have a reel inside them. When you approach them from the reader, they emit a radio signal through the antennas connected to the reader. The energized tag, which is the card, modulates the information stored in its memory and sends that data to the reader. This card then enters the reading field and receives power from the reader to perform the operations. The RFID reader receives the information sent by the tag, decodes and sends the data to the server application.

Steps:1
        Wring of MFRC-522 with EP32

S.NO
MFRC522
ESP32
1
SDA
G5
2
SCK
G18
3
MISO
G19
4
MOSI
G23
5
IRQ
Not used
6
GND
GND
7
RST            
Not used
8
3.3V
3.3V
Table 3.1.1: Connection of rfid reader to esp32


Steps:2
 you download the library of mfrc-522 from Arduino or Github Down-load rc522 library here 

 programming :Copy the Following Code

#include<SPI.h>

#include <MFRC522.h>
#define SS_PIN 5
#define RST_PIN 9//not used for esp32
byte readCard[4];
MFRC522 mfrc522(SS_PIN, RST_PIN);
void setup() {
  Serial.begin(115200);
  SPI.begin();       
  mfrc522.PCD_Init();
}

void loop() {

  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;
  }
  if ( ! mfrc522.PICC_ReadCardSerial()) { 
    return;
  }
  Serial.println(F("Scanned PICC's UID:"));
  for ( uint8_t i = 0; i < 4; i++) {
    readCard[i] = mfrc522.uid.uidByte[i];
    Serial.print(readCard[i], HEX);
  }
  Serial.println("");
  mfrc522.PICC_HaltA();

}

Note:If It Does Not Work Problem In Your ESP32 Board Serial Monitor.To Avoide This Problem we use to LCD for Print the Card Number-


Steps 3:
               LCD Connection With ESP32:
Connection:
SDA--------21
SCK--------22
GND------GND
5V---------5V
Programming:
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4);  

void setup()
{
  lcd.init();                     
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("Hello, world!");
  delay(699);
  lcd.clear();

}


void loop()
{
FINAL Programming Code

#include <SPI.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4);

#include <MFRC522.h>

#define SS_PIN 5

#define RST_PIN 9

byte readCard[4];

MFRC522 mfrc522(SS_PIN, RST_PIN);

void setup() 

{

  Serial.begin(115200);  

  SPI.begin();          

  mfrc522.PCD_Init();

 lcd.init();                      

 lcd.backlight();   

 lcd.setCursor(0,0);

 lcd.print("Hello, world!");
  delay(699);
  lcd.clear();

}

void loop()

 {  if ( ! mfrc522.PICC_IsNewCardPresent()) {

return;

  }

  if ( ! mfrc522.PICC_ReadCardSerial()) {   

return;

  }

 Serial.println("Scanned PICC's UID:");

  for ( uint8_t i = 0; i < 4; i++) { 

    readCard[i] = mfrc522.uid.uidByte[i];

Serial.print(readCard[i], HEX);

  lcd.setCursor(0,0);

  lcd.print(readcard[i]);

/*  lcd.print(readcard); try it's, if above code is not run

  lcd.print(readcard[i],HEX);// try it's, if above code is not run */

 delay(2000);

 lcd.clear();

  }






















5 comments:

  1. ERROR:
    'writeBlock' was not declared in this scope
    pls help

    ReplyDelete
  2. Thanks! This tutorial was a great help! I uploaded the sample code and am able to see output on my serial monitor, but when I tap my RFID chip on the reader nothing happens. I added debugging statements and it keeps going into this if line in the loop() method:
    if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;
    }
    Why?

    ReplyDelete
    Replies
    1. you should print the card by lcd not serial monitor, because serial monitor can not show card number

      Delete

ESP 32 FreeRTOS Task Create in Dual Core

ESP 32 FreeRTOS, LED Turn On and Turn Off: In This Artical i will explain you, how to  use FreeRTOS in ESP32 Board- Projects 1- Create three...