Elechouse PN532 NFC Module V3 for Arduino etc.

  • Community Helper

    You see at the start where I just chopped out the mess and left it with the I2C stuff? Maybe try doing something like that and see what happens.

  • That's also not working...same error..!!

  • Community Helper

    Ok, so the code definitely works, and definitely works on an UNO with a PN532 V3 set to I2C mode.
    So, logically the only things that could be different in your case are the I2C wiring and the I2C mode setting on the board you have.
    Double check that your board is set to function in I2C mode, then double check your wires, maybe try swapping the two data wires around to see if that helps.

  • No change..still no success....same error

  • Community Helper

    Do you think you could take a picture of your setup?

  • Community Helper

    Ah, there's your problem - it's not set to I2C mode.

    See the little bank of two physical switches right near the I2C connection points? switch 1 needs to be in the UP position for on.

  • Community Helper

    How'd you go, @shagun_8 ? Did that work for you?

  • @Lokki Thanks for your help...now its working

  • NFC Ring Team

    Great job @Lokki !! :)

  • One more thing...the module is not reading my nfc tags having Topaz 512 chip...can u please tell me the module is compatible with which nfc tags other than mifare?

  • Community Helper

    No worries at all, dude. I like it best when things work!
    TBH I've only really used my gear with mifare classics and NTAG based tags/fobs/rings/etc. (I've never used a Topaz in any form.)

    From the manual it says this:

    RFID reader/writer mode support
     Mifare 1k, 4k, Ultralight, and DesFire cards
     ISO/IEC 14443-4 cards such as CD97BX, CD light, DesFire, P5CN072 (SMX)
     Innovision Jewel cards such as IRT5001 card
     FeliCa cards such as RCS_860 and RCS_854

    I have found though that your mileage may vary as to where and how well you read some things. You might need to play around with it a bit to get best results.

  • When I try to write on the mifare classic......the serial monitor shows....block authentication failed for 4..what to do?


    #include <Wire.h>
    #include <PN532_I2C.h>
    #include <PN532.h>   // The following files are included in the libraries Installed
    #include <NfcAdapter.h>
    PN532_I2C pn532_i2c(Wire);
    NfcAdapter nfc = NfcAdapter(pn532_i2c);  // Indicates the Shield you are using
    void setup() {
        Serial.println("NFC Tag Writer"); // Serial Monitor Message
    void loop() {
        Serial.println("\nPlace an NFC Tag that you want to Record these Messages on!"); // Command for the Serial Monitor
        if (nfc.tagPresent()) {
            NdefMessage message = NdefMessage();
            message.addTextRecord("Abc"); // Text Message you want to Record
                    boolean success = nfc.write(message);
            if (success) {
                Serial.println("Good Job, now read it with your phone!"); // if it works you will see this message 
            } else {
                Serial.println("Write failed"); // If the the rewrite failed you will see this message
    Yes you can wrap the code with 3 backticks.

  • It says "the tag is not NDEF Formatted"....so should it be NDEF formatted to use it with the module?

  • Community Helper

    Ah, you may have to look into that - have a read up on the mifare classic data sheet.

  • hey lokki
    long time no see

    I'm finally got some more free time so I'm back to working out what the hell I'm doing :P

    coud I ask with your mr crappy car code...if I'm getting a uid value as follows

    where does that information need to be put for the code to accept it as one of the valid keys?

  • Community Helper

    Howdy again, @MarkGabb
    It should look something like this:

    int triggerPin1 = 2;
    int triggerPin2 = 3;
    int triggerPin3 = 4;
    int indicatorPin1 = 5;
    int indicatorPin2 = 6;
    int indicatorPin3 = 7;
    int indicatorPin4 = 8;
    int handbrakePin1 = 9;
    int carRunState = 0;
    int handbrakeState = 0;
      #include <Wire.h>
      #include <PN532_I2C.h>
      #include <PN532.h>
      PN532_I2C pn532i2c(Wire);
      PN532 nfc(pn532i2c);
    void setup(void) {
      pinMode(triggerPin1, OUTPUT);
      pinMode(triggerPin2, OUTPUT);
      pinMode(triggerPin3, OUTPUT);
      pinMode(indicatorPin1, OUTPUT);
      pinMode(indicatorPin2, OUTPUT);
      pinMode(indicatorPin3, OUTPUT);
      pinMode(indicatorPin4, OUTPUT);
      pinMode(handbrakePin1, INPUT);
      Serial.println("Hello! I'm a Car!");
      uint32_t versiondata = nfc.getFirmwareVersion();
      if (! versiondata) {
        Serial.print("PN53x key scanner board not online");
        while (1); // halt
      // Got ok data, report state
      Serial.print("Reader Online, ");
      // Set the max number of retry attempts to read from a card
      // This prevents us from waiting forever for a card, which is
      // the default behaviour of the PN532.
      // configure board to read NFC tags
      Serial.println("Waiting for a valid key");
    void loop(void) {
      String ringUid;
      boolean success;
      uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
      uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
      // Wait for an ISO14443A type cards (NFC Ring, Mifare, etc.).  When one is found
      // 'uid' will be populated with the UID, and uidLength will indicate
      // if the uid is 4 bytes (Mifare Classic) or 7 bytes (NFC Ring or Mifare Ultralight)
      success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
      if (success) {
        // Display some basic information about the card
    //    Serial.print("  UID Length: "); Serial.print(uidLength, DEC); Serial.println(" bytes");
        Serial.print("  UID Value: ");
        for (uint8_t i = 0; i < uidLength; i++)
          Serial.print(uid[i], HEX);
          ringUid += String(uid[i], HEX);
        Serial.println(ringUid + "\n");
        if (ringUid == "42cbfd26f3f81" || ringUid == "xxxxxxxxxxxxxx" || ringUid == "xxxxxxxxxxxxxx" || ringUid == "xxxxxxxxxxxxxx"){
          Serial.println("Key accepted!");
        if ((ringUid == "42cbfd26f3f81" || ringUid == "xxxxxxxxxxxxxx" || ringUid == "xxxxxxxxxxxxxx" || ringUid == "xxxxxxxxxxxxxx") && (carRunState == 0)){
          Serial.println("PERMISSION GRANTED, SYSTEMS ON");
          digitalWrite(triggerPin3, HIGH);   // sets latching relay trigger on for ignition mode in car to allow start
          digitalWrite(indicatorPin2, HIGH); //show state, second LED
          delay(200);                  // waits briefly
          digitalWrite(triggerPin3, LOW);    // removes latching relay trigger
          carRunState = carRunState++;
        else if ((ringUid == "42cbfd26f3f81" || ringUid == "xxxxxxxxxxxxxx" || ringUid == "xxxxxxxxxxxxxx" || ringUid == "xxxxxxxxxxxxxx") && (carRunState == 1)){
          handbrakeState = digitalRead(handbrakePin1); //check if handbrake is on or off
          if (handbrakeState = 0){//if handbrake is on then safe to crank car, if not then skip this mode entirely
            Serial.println("ENGINE CRANKING");
            digitalWrite(triggerPin1, HIGH);   // triggers output for engine starting
            digitalWrite(indicatorPin3, HIGH); //show state, third LED
            delay(2000);                  // waits for a second
            digitalWrite(triggerPin1, LOW);    // removes triggered output 
            Serial.println("ENGINE CRANKING COMPLETE");
          carRunState = carRunState++;     
        else if ((ringUid == "42cbfd26f3f81" || ringUid == "xxxxxxxxxxxxxx" || ringUid == "xxxxxxxxxxxxxx" || ringUid == "xxxxxxxxxxxxxx") && (carRunState > 1)){
          Serial.println("SYSTEM OFF, SLEEP TIME");
          digitalWrite(triggerPin2, HIGH);   // Trigger latching relay to reset for vehicle OFF
          digitalWrite(indicatorPin1, HIGH); //show state, LED1 on
          digitalWrite(indicatorPin2, LOW); //LED2 off
          digitalWrite(indicatorPin3, LOW); //LED3 off
          delay(200);                  // waits briefly      
        digitalWrite(triggerPin2, LOW);    // Removes latching relay reset trigger
        carRunState = 0;
        digitalWrite(indicatorPin1, LOW); //LED1 off

    If you're not using one of the ringUid bits then just delete it, the sketch can work with only one ring set up or it can work with 12. I had it set up with two rings, front and back, so that myself and the girlfriend could start the car and didn't have to worry about which way the ring was facing.

  • Hmmm this script seems very different to the one I've got loaded.....made some improvments??

  • Ok so ill upload tonight, ive forgotten physical pin mapping
    Arduino nano

    I know my reader is in a4 and a5 and is correct because the reader is showing in the terminal

  • Community Helper

    yeah, I think the one you grabbed a while back would have been seperate cards for on/ignition/off. It was a while back.
    Just set the pins however you want them, it's pretty arbitrary. I think from memory the handbrakepin1 basically does nothing, you could chop that out.