1

First of all, I am a beginner with Arduino. I have a circuit consisting of: an Arduino Uno, an RFID RC522 card reader and the sender from an RF 433 MHz module.

I am trying to transmit the ID code of the RFID card with the RF 433MHz sender, but it does not work. First, I am reading the card and then I compose in one string the RFID code, for example "18016518623564".

With the code below, I cannot read the RFID card. (Nothing is seen on the serial monitor.) It seems to be a problem with vw_setup(2000);. If I comment it out, I can read the code one time. If I comment out also vw_wait_tx();, I can read the code twice. If I comment out also send("1");, I can read the code an unlimited number of times. But, whatever I do, nothing can be sent (the program stops at vw_wait_tx();).

Could please someone help me to solve the problem and be able to send the RFID code to the receiver?

Below is the code:

// includes for RFID
#include <SPI.h>
#include <RFID.h>
// includes for RF communication
#include <VirtualWire.h>
// defines for RFID
#define SS_PIN 10
#define RST_PIN 5
// variables for RFID
RFID rfid(SS_PIN, RST_PIN);
int serNum[5]; // array to store the RFID code
String rfid_string; // variable to store the concatenated card identifier

void setup() {
  Serial.begin(9600);
  SPI.begin();
  rfid.init();
  // initialize the IO and ISR for RF
  vw_setup(2000); // Bits per sec
}

void loop() {
  read_and_compose_rfid_code(); // read and compose the rfid code into one string
  send("1"); // send 1 throug RF - just for testing
  delay(1000);
}

void read_and_compose_rfid_code (void) {
  if (rfid.isCard()) {
    // check if rfid card is present nearby to the sensor antenna
    if (rfid.readCardSerial()) {
      // read card identifier into array defined in RFID class
      // concatenate the card identifier as one string
      rfid_string = String(rfid.serNum[0]) + String(rfid.serNum[1]) + String(rfid.serNum[2]) + String(rfid.serNum[3]) + String(rfid.serNum[4]);
      Serial.print(rfid_string); // test to see if the code is properly composed
      Serial.println();
    }
    rfid.halt();
    delay(1000); // set a delay of 1 second before the next card read
  }
}

/* function used to send the card identifier through RF */
void send (char *message) {
  vw_send((uint8_t *)message, strlen(message));
// "message" is an array of the bytes to send, and strlen(message) is the number of bytes stored in the array
  vw_wait_tx(); // wait until the whole message has been transmitted
}
dda
  • 6,030
  • 2
  • 25
  • 34
Adi S.
  • 53
  • 1
  • 10

1 Answers1

1

After several trials, I have reached to a solution.
If I initialize RF (vw_setup(2000);) before SPI and rfid, I can read the card and send the message. I do not know why it works, but it works. Maybe somebody can explain.

Adi S.
  • 53
  • 1
  • 10