Go Down

Topic: RFID Line Follower Robot (Read 916 times) previous topic - next topic

MohamedMostafaRagab

Mar 20, 2019, 06:27 pm Last Edit: Mar 20, 2019, 06:28 pm by MohamedMostafaRagab
Dear All Have A nice Day
i create anew robot 2 WD and RC522 Rfid Module and PNC532 NFC Module
he is the procedure i need
insert tag no 1 to RC522 RFID Reader so the robot start to move using line follower till achieve the target tag on the floor (floor tag scanned using NFC Reader)
as the shown in the photo attached
Please Help Me in coding
BR


PaulS

What have you tried so far?

Can you read the tag(s)? Can you read the line sensors? Can you follow the line? Can you read a tag at whatever speed the device is following the line?
The art of getting good answers lies in asking good questions.

MohamedMostafaRagab

#include <Wire.h>
  #include <PN532_I2C.h>
  #include <PN532.h>
  #include <NfcAdapter.h>
  PN532_I2C pn532i2c(Wire);
  PN532 nfc(pn532i2c);
//RC522

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN        9          // Configurable, see typical pin layout above
#define SS_PIN          10         // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN);

byte card_ID[4];
byte First_card_ID[4]={0x6B,0x37,0x68,0x89};
byte Second_card_ID[4]={0x19,0x73,0x78,0x28};
//byte Third_card_ID[4]={0x6B,0x37,0x68,0x89};
//byte Fourth_card_ID[4]={0x9E,0xDA,0x45,0x73};

boolean State=false;
uint8_t i=0;

int mot1=3;
int mot2=5;
int mot3=6;
int mot4=8;

int r = 2;
int c = 4;
int l = 7;

int lReading;
int cReading;
int rReading;



void setup(void) {
 
  Serial.begin(115200);
    Serial.println("Hello!");
//==================RC Set UP
 SPI.begin();  // Init SPI bus
 mfrc522.PCD_Init();

//==================NFC Set UP
  nfc.begin();
  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }
  // Got ok data, print it out!
  Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
  Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
  Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
  nfc.setPassiveActivationRetries(0xFF);
  nfc.SAMConfig();
   
  Serial.println("Waiting for Tag To Start");

  pinMode(r, INPUT);
  pinMode(c, INPUT);
  pinMode(l, INPUT);
 
  pinMode(mot1,OUTPUT);
  pinMode(mot2,OUTPUT);
  pinMode(mot3,OUTPUT);
  pinMode(mot4,OUTPUT);
}

void loop(void) {

  cmp_id();   
 
 
  if(State==true){ Serial.println("Accepted, Valid card");
  Serial.println("car move");
  forWard();
//  readSensors();
//  if ((rReading==1)&&(cReading==0)&&(lReading==1))// forword
//     { Serial.println("Going Forward");
//      forWard();}
//   else if ((rReading==0)&&(cReading==1)&&(lReading==1)){
//       Serial.println("Going RIGHT");
//       Right();}
//
//       else{
//        Serial.println("STOP");
//         Stop();}
     
}
NFC();
  if(State==false){Serial.println("denied! unValid card ! ");
Stop();
}
 
}

void cmp_id(){

    if ( ! mfrc522.PICC_IsNewCardPresent()) {
  return 0;
 }
 // Select one of the cards
 if ( ! mfrc522.PICC_ReadCardSerial()) {
  return 0;
 }
 
 for (byte i = 0; i < 4; i++) {
     card_ID=mfrc522.uid.uidByte;
 }

 Serial.print(F("Rover Reader: "));
  printDec(mfrc522.uid.uidByte, mfrc522.uid.size);
  Serial.println();
  mfrc522.PICC_HaltA();
  mfrc522.PCD_StopCrypto1();
     
    if(card_ID==First_card_ID){
     State=true;
  }
//  else{
//     State=false;
//     i=5;
//  }
  return 1;
}


//==============NFC
void NFC(){
  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)
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
 
  if (success) {
    Serial.println("Found a card!");
    Serial.print("UID Value: ");
    for (uint8_t i=0; i < uidLength; i++)
    {
      Serial.print(" 0x");Serial.print(uid, HEX);
    }
    Serial.println("");
    // Wait 1 second before continuing
    //delay(1);
  }
//  else
//  {
//    // PN532 probably timed out waiting for a card
//    Serial.println("Timed out waiting for a card");
//  }
  if((uid)==Second_card_ID){
                        Serial.println("Stop Car for tag1");
                        State=false;
                        return;}
}


//Print DEC Loop
void printDec(byte *buffer, byte bufferSize) {
  for (byte i = 0; i < bufferSize; i++) {
    Serial.print(buffer < 0x10 ? " 0" : " 0x");
    Serial.print(buffer, HEX);
  }
}







void readSensors(){
  rReading = digitalRead (2);
  cReading = digitalRead (4);
  lReading = digitalRead (7);
   Serial.print("rReading = "); Serial.println(rReading);
   Serial.print("cReading = "); Serial.println(cReading);
   Serial.print("lReading = "); Serial.println(lReading);
}
void forWard(){
  analogWrite (mot1,140);
  analogWrite (mot2,LOW);
  analogWrite (mot3,140);
  analogWrite (mot4,LOW);
}

void Stop(){
  analogWrite (mot1,LOW);
  analogWrite (mot2,LOW);
  analogWrite (mot3,LOW);
  analogWrite (mot4,LOW);
}

void leFt(){
  analogWrite (mot1,LOW);
  analogWrite (mot2,100);
  analogWrite (mot3,100);
  analogWrite (mot4,LOW);
}

void Right(){
   analogWrite (mot1,100);
   analogWrite (mot2,LOW);
   analogWrite (mot3,LOW);
   analogWrite (mot4,100);
}

MohamedMostafaRagab

 
What have you tried so far?

Can you read the tag(s)? Can you read the line sensors? Can you follow the line? Can you read a tag at whatever speed the device is following the line?
at first i have delay problem for reading RC tags
line follower delay
need to excite route to run through if you got me
can you help me?

PaulS

Quote
can you help me?
No, because you can't follow the rules. EVERY section of the forum has a sticky called "How to use this forum - Please read". You obviously didn't.

Before you post code again, CORRECTLY this time, put EVERY { and EVERY } on a line BY ITSELF, and use Tools + Auto Format to fix the indenting, AND delete commented out code.
The art of getting good answers lies in asking good questions.

PaulS

The code you posted, incorrectly, does something, but you failed to say what it actually does or how that differs from what you want.
The art of getting good answers lies in asking good questions.

MohamedMostafaRagab

No, because you can't follow the rules. EVERY section of the forum has a sticky called "How to use this forum - Please read". You obviously didn't.

Before you post code again, CORRECTLY this time, put EVERY { and EVERY } on a line BY ITSELF, and use Tools + Auto Format to fix the indenting, AND delete commented out code.
Dear Sir,
I'll check now the section "How to use this forum - Please read"
i plan to do this steps for my project

1- the robot is stopped at the start point

2- when i put the first tag (for RC522 RFID Module) the robot start moving and go to the target tag on the floor (NFC Module Scan and the robot Stop).

3-   and so on

the steps i proceed with
start reading from the (RFID) the robot move forward
NFC Scan the Target Tag The Stop
in this stage i noticed that ther are delay for (RFID) scan

i can't proced for the next stage Make the line follow active and Write correct steps to the route attached in the above photo


So, if you can help me i really appreciate that
thanks again

vinceherman

#8
Mar 21, 2019, 09:09 pm Last Edit: Mar 21, 2019, 09:16 pm by vinceherman
Help me out with your overview.
Your original pic


Quote
2- when i put the first tag (for RC522 RFID Module) the robot start moving and go to the target tag on the floor (NFC Module Scan and the robot Stop).
As I understand your description of this step, you mean that
The vehicle should be at a stop when powered up.
The vehicle should remain at a stop until is reads a card (you said i put the first card).
After a card read, the vehicle should start the line following logic common to all line followers.

Your image shows tags 1, 2 and 3.  
Are these tags places so that your card reader can read them while it is moving?
Should the vehicle do something after it reads a tag?
Should the vehicle stop at some point?

Edit: A good place to start with this project is to completely ignore your card reader and work on making the vehicle work as a line follower.

MohamedMostafaRagab

Help me out with your overview.
Your original pic


As I understand your description of this step, you mean that
The vehicle should be at a stop when powered up.======= yes
The vehicle should remain at a stop until is reads a card (you said i put the first card).==== yes 
After a card read, the vehicle should start the line following logic common to all line followers. ==== the vehicle go to the exact target tag if the insert tag is 1 it go through the route to achieve the target tag no1 on the floor   

Your image shows tags 1, 2 and 3.  ===== yes shown the target location 
Are these tags places so that your card reader can read them while it is moving?===== yes
Should the vehicle do something after it reads a tag? need to make it stop and if that possible to make the robot back that will be great
Should the vehicle stop at some point? yes

Edit: A good place to start with this project is to completely ignore your card reader and work on making the vehicle work as a line follower.===== agree for your advice but i can't figure that making the robot go through exact route


waiting your advice


neiklot

OP all you did in that last post was quote vinceherman's previous post back at us and add "waiting your advice" (inside the quote, which confused me for a bit.)

But he had asked you a few questions, which you didn't answer:

Your image shows tags 1, 2 and 3.  
Are these tags places so that your card reader can read them while it is moving?
Should the vehicle do something after it reads a tag?
Should the vehicle stop at some point?
Apart from the fact that it's not clear what you actually want your system to do, it's not clear what it actually does so far, and how that differs from the requirement.

(I'm guessing this is a uni/college project?)


MohamedMostafaRagab

Dear All
Many thanks for your support

you can imagine my project like a waiter line follower robot
at the start the robot is stop moving in the start position
when we call tag no1 (RFID module) read the tag
the robot start moving to achieve table no 1 (he know the route)
when it arrive to the table he confirm arriving by Reading the table tag (NFC Module)
then it return back to the start point again and waiting another tag to scan.

neiklot

Apart from the fact that it's not clear what you actually want your system to do, it's not clear what it actually does so far, and how that differs from the requirement.
Ok so now we know what it's supposed to do; what does it actually do and how is that wrong?


MohamedMostafaRagab

i don't know how to manage the loops for make the robot move to exact location using line follower

neiklot

#14
Mar 25, 2019, 12:57 pm Last Edit: Mar 25, 2019, 12:57 pm by neiklot
i don't know how to manage the loops for make the robot move to exact location using line follower
Have you yet got it set up and following just a line with a turn?.... never mind making decisions right now.

Have you followed any of the tutorials like this one at sparkfun, just as an example.

Once you have it following a path, you can think about how to make it decide to turn right at the first intersection or the second one...






Go Up