Go Down

Topic: compare char to char (Read 695 times) previous topic - next topic


I'm trying to do something when rfid char match. here the code
Code: [Select]
// RFID reader for Arduino
// Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan>
// Modified for Arudino by djmatic
// Re-Modified for Arduino and 125Khz JsxzLz RFID Kit from Ebay by Biohazard

// RFID reader comes with 11 pins: D3 D2 D1 Rest Mcst Gnd L1 L2 PC TX VCC
// We need these to be connected:
// Rest to Arduino pin 2
// Gnd to Arduino GND
// L1 and L2 to the antenna
// TX to Arduino RX0
// VCC To Arduino 5V

int  val = 0;
char code[14];
char michael[14] = {'4', 'B', '0', '0', '1', '0', '8', '5', '1', '3', '4', '7', '0', 'F'};
// 2 digits manufacture code
// 10 digits card code
// 2 digits parity bits

int bytesread = 0;

void setup() {

  Serial.begin(9600);     // RFID reader TX pin, Baud rate: 9600, Data bits: 8, stop bit: 1.
  pinMode(2,OUTPUT);      // Set digital pin 2 as OUTPUT to connect it to the RFID RESET pin
  digitalWrite(2, HIGH);  // Activate the RFID reader

void loop() {

  if(Serial.available() > 0) {            // if data available from reader
    if((val = Serial.read()) == 10) {     // check for header
      bytesread = 0;
      while(bytesread < 14) {             // read 14 digit code
        if( Serial.available() > 0) {
          val = Serial.read();
          if((val == 10)||(val == 13)) {  // if header or stop bytes before the 10 digit reading
            break;                        // stop reading
          code[bytesread] = val;          // add the digit           
          bytesread++;                    // ready to read next digit 
      if(bytesread == 14) {         // if 14 digit read is complete
        Serial.print("TAG code is: ");    // possibly a good TAG
        Serial.println(code);             // print the TAG code
      bytesread = 0;
      digitalWrite(2, LOW);               // deactivate the RFID reader for a moment so it will not flood
      delay(1500);                        // wait for a bit
      digitalWrite(2, HIGH);              // Activate the RFID reader
  if (code = michael)
    Serial.print("welcome michael");


It give me this error when trying to copile it: error: invalid array assignment
Checked on the net without any clue
Thanks in advance


What does bytesread get up to, 14 or less?
Also something is wrong with this, "if (code = michael)" can you spot the mistake?
Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID


Also something is wrong with this, "if (code = michael)" can you spot the mistake?

Two things
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.


Even if you fix the = problem (with ==), that is only going to compare the address where the two arrays start. It will NOT compare the contents of the arrays. You could use memcmp() to see if the data is the same. You can not use strcmp() since you do not have strings (NULL terminated arrays of chars).

Code: [Select]
        Serial.println(code);             // print the TAG code
This is wrong, too, because code is not a string. It is an array of chars, but it is NOT NULL terminated. And there is no room for the NULL terminator.


My mistake, thanks for the ==. Don't no why i done that. Now the code working and it show me the 14 digit of the card in the serial monitor. I will try the memcmp() like you said and comeback to you thanks.

Go Up