GPS and RFID not working together

hey.... i am trying to connect GPS and RFID reader together to an arduino UNO but, when i do so the gps does not give readings but rfid works properly... i guess is there any problem with the SS port..?? but i dont have any idea what changes should i make into my code... can someone please help asap...

Please read and follow the instructions in "How to use this forum".

jremington:
Please read and follow the instructions in "How to use this forum".

Sir.. i am not getting you... i previously posted other posts also in the same way... can someone help me wid the solution?? so kindly do...

Sir.. i am not getting you

What part of

Please read and follow the instructions in "How to use this forum".

do you not understand?

Let me spell it out.
Those instructions How to use this forum will tell you about asking a question. Key to this is posting a schematic of what you have and the code you are trying to run. This along with links to the parts you have will enable us to see what you are actually doing. Only then can we begin to try and work out what you are doing wrong.

Grumpy_Mike:
Let me spell it out.
Those instructions How to use this forum will tell you about asking a question. Key to this is posting a schematic of what you have and the code you are trying to run. This along with links to the parts you have will enable us to see what you are actually doing. Only then can we begin to try and work out what you are doing wrong.

am so srry.. finally i understood... following is my code... its basically a vehicle security device... but am using rfid and gps on the same arduino uno board thus, the rfid is working properly but gps does not work at all.. but if i connect only gps modem then it gives me accurate reading... i guess the SS pin is problem.. is there any coding way by which i can assign a separate pin or something gps...

Key to this is posting a schematic of what you have and the code you are trying to run.

#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
SoftwareSerial gsm(1,0);
SoftwareSerial mySerial(3, 2);
Adafruit_GPS GPS(&mySerial);
boolean usingInterrupt = false;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
#define GPSECHO  true
#define TRIGPIN 4
#define ECHOPIN 5
#define RST_PIN 9 // Configurable, see typical pin layout above 
#define SS_PIN 10 // Configurable, see typical pin layout above 
#define MASTERCARD 4294943745
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance 
void setup() {
  
  Serial.begin(115200);
  mySensor.initSensitivity(2); // Good for "Tilt" measurements

  SPI.begin();  // Init SPI bus 
  mfrc522.PCD_Init(); // Init MFRC522 
  mfrc522.PCD_DumpVersionToSerial();  // Show details of PCD - MFRC522 Card Reader details 
  Serial.println(F("PLease Scan Your MASTERCARD...")); 
  pinMode(ECHOPIN, INPUT);
  pinMode(TRIGPIN, OUTPUT);
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input
  pinMode(pinSpeaker, OUTPUT);
 // pinMode(buttonPin, INPUT);
  GPS.begin(9600);
   GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
  GPS.sendCommand(PGCMD_ANTENNA);
 
  useInterrupt(false);
  mySerial.println(PMTK_Q_RELEASE);
}
SIGNAL(TIMER0_COMPA_vect) {
  char c = GPS.read();

#ifdef UDR0
  if (GPSECHO)
    if (c) UDR0 = c;  
#endif
}

void useInterrupt(boolean v) {
  if (v) {
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
    usingInterrupt = true;
  } else {

    TIMSK0 &= ~_BV(OCIE0A);
    usingInterrupt = false;
  }
}

uint32_t timer = millis();

//THE TOUGHEST AND CRUCIAL PART i.e THE ACTUALL PROGRAMMING 

unsigned long getID(){ 
if ( ! mfrc522.PICC_ReadCardSerial()){
return -1; 
}
unsigned long hex_num; 
hex_num = mfrc522.uid.uidByte[0] << 24; 
hex_num += mfrc522.uid.uidByte[1] << 16; 
hex_num += mfrc522.uid.uidByte[2] << 8; 
hex_num += mfrc522.uid.uidByte[3]; 
mfrc522.PICC_HaltA(); // Stop reading 
return hex_num; 
}

void loop() {
  
unsigned long uid; 
if(mfrc522.PICC_IsNewCardPresent()) { 
uid = getID(); 
if(uid != -1)
    { 
    Serial.print("Card detected, UID: "); Serial.println(uid); 
    if((uid==MASTERCARD) && (mfrc522.PICC_IsNewCardPresent())){
        
        Serial.println("Enjoy Your Drive.. :)");
        digitalWrite(ledPin,HIGH);
        delay(1000);
 //GPS CODING...!!!!!
  
    if (! usingInterrupt) {
    // read data from the GPS in the 'main loop'
    char c = GPS.read();
    
    // if you want to debug, this is a good time to do it!
    if (GPSECHO)
      if (c) Serial.print(c);
  }
  
  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {  
    if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
    return;  // we can fail to parse a sentence in which case we should just wait for another
  }

  // if millis() or timer wraps around, we'll just reset it
  if (timer > millis())  timer = millis();

  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 2500) { 
    timer = millis(); // reset the timer
    
    Serial.print("\nTime: ");
    Serial.print(GPS.hour, DEC); Serial.print(':');
    Serial.print(GPS.minute, DEC); Serial.print(':');
    Serial.print(GPS.seconds, DEC); Serial.print('.');
    Serial.println(GPS.milliseconds);
    Serial.print("Date: ");
    Serial.print(GPS.day, DEC); Serial.print('/');
    Serial.print(GPS.month, DEC); Serial.print("/20");
    Serial.println(GPS.year, DEC);
    Serial.print("Fix: "); Serial.print((int)GPS.fix);
    Serial.print(" quality: "); Serial.println((int)GPS.fixquality); 
//    if (GPS.fix) {
      Serial.print("Location: ");
      Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
      Serial.print(", "); 
      Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
      Serial.print("Location (in degrees, works with Google Maps): ");
      Serial.print(GPS.latitudeDegrees, 4);
      Serial.print(", "); 
      Serial.println(GPS.longitudeDegrees, 4);
      Serial.print("Speed (knots): "); Serial.println(GPS.speed);
      Serial.print("Angle: "); Serial.println(GPS.angle);
      Serial.print("Altitude: "); Serial.println(GPS.altitude);
      Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
      //delay(10000);
      Serial.println("");
      Serial.println("Sending to Database...");
      Serial.println("");
      Serial.println("");
  //  }
  }
}

Please edit your post and USE CODE TAGS, not quote tags, as instructed in "How to use this forum".

I can see that this is going to take a while.

When you get around to it (tomorrow or the next day, no one really cares), also post a wiring diagram.

jremington:
Please edit your post and USE CODE TAGS, not quote tags, as instructed in "How to use this forum".

I can see that this is going to take a while.

When you get around to it (tomorrow or the next day, no one really cares), also post a wiring diagram.

hey... i hav edited my code... can u just have a look?? i am really very screwed with SS pin thtz SPI bus... plz can u provide some hlp asap... i hav to submit my project in few days.. :frowning: its kind of urgent :frowning:

Yes, this seems to be extremely urgent. It took you 4 days to edit the previous post.

Where is your wiring diagram?

jremington:
Yes, this seems to be extremely urgent. It took you 4 days to edit the previous post.

Where is your wiring diagram?

No sir.. i edited it the same day.,, but i thought u might see it... but there weren't any replies so i posted again today...

m confused with how to upload my wiring diagram... :frowning:

Draw the diagram on pencil and paper, then scan or take a photo and post it. The instructions are in "How to use this forum".

sir.. i have modified my code... thtz below..

#include <LiquidCrystal.h>
#include <SPI.h> 
//#include <Wire.h> //Include the Wire library
#include <MMA_7455.h> //Include the MMA_7455 library
#include <MFRC522.h> 
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>

int SS_PIN = 14;  
int RST_PIN = 9;  

SoftwareSerial gsm(10,9);
SoftwareSerial mySerial(16,15 );
MMA_7455 tilt = MMA_7455();                                                                  //Make an instance of MMA_7455
LiquidCrystal lcd(0, 1, 5, 4, 3, 2);
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance 
Adafruit_GPS GPS(&mySerial);
char xVal, yVal, zVal;                                                                                   
int backLight = 6;
int TRIGPIN =  7;
int ECHOPIN = 8;                                                                                     
int pir = 17;                                                                                      
int pirState = LOW;                                                                                 
int val = 0;                                                                                       
int speaker = 13;     
int red = 12;
int green = 11;

#define GPSECHO  true
#define MASTERCARD  4294943745


void setup() {
  SPI.begin();  
  Serial.begin(9600);
  pinMode(backLight, OUTPUT);
  digitalWrite(backLight, HIGH);
  lcd.begin(16, 2);
  lcd.clear();
  lcd.print(F("Please Insert Ur"));
  lcd.setCursor(2,1);
  lcd.print(F("MASTERCARD"));
  delay(10000);
  digitalWrite(backLight, LOW);
  delay(2000);
  digitalWrite(backLight, HIGH);
  delay(1000);
  digitalWrite(backLight,LOW);
  delay(100);
  tilt.initSensitivity(2);   
  mfrc522.PCD_Init(); // Init MFRC522 
  mfrc522.PCD_DumpVersionToSerial();  
  Serial.println(F("PLease Scan Your MASTERCARD...")); 
  pinMode(ECHOPIN, INPUT);
  pinMode(TRIGPIN, OUTPUT);
  pinMode(red, OUTPUT);  
  pinMode(green,OUTPUT);    
  pinMode(pir, INPUT);     
  pinMode(speaker, OUTPUT);
  GPS.begin(9600);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
  GPS.sendCommand(PGCMD_ANTENNA);
}
/*Code to get Card UID */

unsigned long getID(){ 
if ( ! mfrc522.PICC_ReadCardSerial()){
return -1; 
}
unsigned long hex_num; 
hex_num = mfrc522.uid.uidByte[0] << 24; 
hex_num += mfrc522.uid.uidByte[1] << 16; 
hex_num += mfrc522.uid.uidByte[2] << 8; 
hex_num += mfrc522.uid.uidByte[3]; 
mfrc522.PICC_HaltA(); // Stop reading 
return hex_num; 
}

void loop() {
  analogWrite(SS_PIN,100);
  
unsigned long uid; 
if(mfrc522.PICC_IsNewCardPresent()) { 
uid = getID(); 
if(uid != -1)
    { 
    Serial.print(F("Card detected, UID: ")); Serial.println(uid); 
    if(uid==MASTERCARD){
        delay(10);
        lcd.clear();
        lcd.print(F("Enjoy Your Drive.. "));
        lcd.setCursor(0,1);
        lcd.print(F(":)"));
        pinMode(backLight,HIGH);
        delay(10000);
        lcd.clear();     
        digitalWrite(green,HIGH);
        delay(1000);
        digitalWrite(green,LOW);
        delay(1000);
        digitalWrite(green,HIGH);
            xVal = tilt.readAxis('x'); //Read out the 'x' Axis
            yVal = tilt.readAxis('y'); //Read out the 'y' Axis
            zVal = tilt.readAxis('z'); //Read out the 'z' Axis
              if (xVal < -20 || xVal >  20 || zVal < -45 )
                   {
                      Serial.println("");
                      tone(speaker, 500, 1000);
                      lcd.clear();
                      lcd.setCursor(2,0);
                      lcd.print(F("Accident")); 
                      lcd.setCursor(2,1);
                      lcd.print(F("Detected")); 
                      digitalWrite(red,HIGH);// turn LED On
                      delay(1000);
                      digitalWrite(red,LOW);// turn LED On
                   
     //GPS CODING...!!!!!
  /*
    if (! usingInterrupt) {
    // read data from the GPS in the 'main loop'
    char c = GPS.read();
    
    // if you want to debug, this is a good time to do it!
    if (GPSECHO)
      if (c) Serial.print(c);
  }
  
  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {  
    if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
    return;  // we can fail to parse a sentence in which case we should just wait for another
  }

  // if millis() or timer wraps around, we'll just reset it
  if (timer > millis())  timer = millis();

  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 2500) { 
    timer = millis(); // reset the timer
    
    Serial.print("\nTime: ");
    Serial.print(GPS.hour, DEC); Serial.print(':');
    Serial.print(GPS.minute, DEC); Serial.print(':');
    Serial.print(GPS.seconds, DEC); Serial.print('.');
    Serial.println(GPS.milliseconds);
    Serial.print("Date: ");
    Serial.print(GPS.day, DEC); Serial.print('/');
    Serial.print(GPS.month, DEC); Serial.print("/20");
    Serial.println(GPS.year, DEC);
    Serial.print("Fix: "); Serial.print((int)GPS.fix);
    Serial.print(" quality: "); Serial.println((int)GPS.fixquality); 
*/
    if (GPS.fix) {
      Serial.print("Location: ");
      Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
      Serial.print(", "); 
      Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
      Serial.print("Location (in degrees, works with Google Maps): ");
      Serial.print(GPS.latitudeDegrees, 4);
      Serial.print(", "); 
      Serial.println(GPS.longitudeDegrees, 4);
      Serial.print("Speed (knots): "); Serial.println(GPS.speed);
      Serial.print("Angle: "); Serial.println(GPS.angle);
      Serial.print("Altitude: "); Serial.println(GPS.altitude);
      Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
      //delay(10000);
      Serial.println("");
      Serial.println("Sending to Database...");
      Serial.println("");
      Serial.println("");
  }
  
    // Ultrasonic Sensor...!!!!
      digitalWrite(TRIGPIN, LOW);
      delayMicroseconds(1000);
      digitalWrite(TRIGPIN, HIGH);
      delayMicroseconds(1000);
      digitalWrite(TRIGPIN, LOW);
      
      //Distance calculation
      float distance = pulseIn(ECHOPIN, HIGH);
      distance= distance/58;
      delay(1000);
      if (distance>=2 && distance<=50){
      lcd.clear();
      lcd.setCursor(1,0);
      lcd.print(distance);
      lcd.println(F(" cm"));
      lcd.setCursor(3,1);
      lcd.print("DANGER");
      digitalWrite(red,HIGH);
      tone(speaker, 500, 500);
      Serial.println("");
      
  }
  else {
      lcd.clear();
      digitalWrite(red,LOW);
      noTone(speaker);
  }
  }
  }
  
  // IF FAKE CARD INSERTED...!!!
    else {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.println(F("Access Denied..."));
        lcd.clear();
        lcd.setCursor(0,1);
        lcd.println(F(":( ..."));
        digitalWrite(TRIGPIN, LOW);
        tone(speaker, 500, 500);
        exit;
        }
    }  
    

  // PIR MOTIION SENSOR WHEN CARD IS ABSENT....!!!
    else
        {
        digitalWrite(TRIGPIN, LOW);
        val = digitalRead(pir);             // read Sensor_Pin
        if (val == HIGH)                        // check if the input is HIGH
          {            
          digitalWrite(red,HIGH);          // turn LED On
          tone(speaker, 500, 500);
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print(F("UNAUTHORISED"));
          lcd.setCursor(2,1);
          lcd.print("ACCESS...");
}
        else {
              digitalWrite(red,LOW);
              noTone(speaker);
             }
          }
}

and i have come up with this wiring diagram... will tht be a good reference to u??
Sir kindly let me knw if its still isn't proper... i'll make the necessary changes...
sorry as its a little unclear...

Lots of ground connections missing in your diagram. You didn't mention the LCD, the GSM module or the ultrasonic sensor in your original post.

I don't see how this can ever work -- the most obvious problem is that according to the diagram and the code, the LCD is using the serial pins D0 and D1, but that conflicts with using those pins for the serial port, which is also defined in the code.

You need to separate out the individual pieces and get each one working before putting everything together.

jremington:
Lots of ground connections missing in your diagram. You didn't mention the LCD, the GSM module or the ultrasonic sensor in your original post.

I don't see how this can ever work -- the most obvious problem is that according to the diagram and the code, the LCD is using the serial pins D0 and D1, but that conflicts with using those pins for the serial port, which is also defined in the code.

You need to separate out the individual pieces and get each one working before putting everything together.

Yes... i added the components after posting the original post... as my project includes them...

And When i enable the lcd in actual practise.. i remove the serial commands...

and that abt gnd and vcc i have connected them all to the breadboard properly...
i thought this wiring diagram wud give the rough and basic idea of wat m trying to do...
Thanks fr the info u gav me...
also can u suggest something more tht i can do??
can spi or I2c help??