Problem occurred when using GSM shield

Dear all,
I am trying to use GSM shield with my project using arduino mega. I have used digital pins 4, 5, 6, 8, ground, SDA, SCL,also spi pins 50,51,52,53 and 5v,3.3v. I am facing a problem that when I did not use the GSM everything worked fine. The moment I did the adjustment with the GSM and it worked the problem occured. The SD moudle didn't work anymore, as well as the RTC moudle... I don't know what I should do now.

The gsm shield I am using is:
https://store.arduino.cc/usa/arduino-gsm-shield-2-integrated-antenna

I have used this instruction to adjust the GSM by using a wire from tx to pin 10, and getting pin two out.

Did I miss up with something? it seems that when I added the gsm everything else doesn't work.

It is like either the gsm or the SD + RTC....

Please attach the current code and maybe also the working code before GSM being installed.

I have created two files and they both works. When I apply the one with GSM RTC, and SD moudle doesn't work, while when I try the one without GSM they both work fine. Here is the code with GSM and I will post the one without gsm in the next reply. I removed the function because the comment is more than 9000 char.

With GSM

#include <GSM.h>
#define PINNUMBER ""
GSM gsmAccess;
GSM_SMS sms;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
#include <MFRC522.h> // for the RFID
#include <SPI.h> // for the RFID and SD card module
#include <SD.h> // for the SD card
#include <RTClib.h> // for the RTC
// define pins for RFID
#define CS_RFID 53
#define RST_RFID 5
// define select pin for SD card module
#define CS_SD 4
// Create a file to store the data
File myFile;
// Instance of the class for RFID
MFRC522 rfid(CS_RFID, RST_RFID);
// Variable to hold the tag's UID
String Student;
// Instance of the class for RTC
RTC_DS1307 rtc;

// Define check in time
const int checkInHour = 01;
const int checkInMinute = 00;

//Variable to hold user check in
int userCheckInHour;
int userCheckInMinute;

// Pins for LEDs and buzzer
const int redLED = 8;
const int greenLED = 6;
const int buzzer = 23;

void setup() {
lcd.init(); // initialize the lcd
lcd.backlight();

// Set LEDs and buzzer as outputs
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(buzzer, OUTPUT);

// Init Serial port
Serial.begin(9600);
while(!Serial); // for Leonardo/Micro/Zero
Serial.println("SMS Messages Sender");
// connection state
boolean notConnected = true;

// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while (notConnected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
notConnected = false;

} else {
Serial.println("Not connected");
lcd.print("GSM not Connected");
delay(1000);
}
}

Serial.println("GSM initialized");
lcd.print("GSM Ready");
delay(1000);
lcd.clear();
// Init SPI bus
SPI.begin();
// Init MFRC522
rfid.PCD_Init();

// Setup for the SD card
Serial.print("Initializing SD card...");
lcd.print("Initializing ");
lcd.setCursor(0, 1);
lcd.print("SD card...");
delay(3000);
lcd.clear();

if(!SD.begin(CS_SD)) {
Serial.println("initialization failed!");
lcd.print("Initializing ");
lcd.setCursor(0, 1);
lcd.print("failed!");
return;
}
Serial.println("initialization done.");
Serial.println("SMS Messages Sender");
delay(200);

lcd.print("Please Swipe ID ");

// Setup for the RTC
if(!rtc.begin()) {
Serial.println("Couldn't find RTC");
lcd.clear();
lcd.print("Couldn't find RTC");
while(1);
}

else {
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(DATE), F(TIME)));
}

if(!rtc.isrunning()) {
Serial.println("RTC is NOT running!");
lcd.clear();
lcd.print("RTC Not Running!");
}
}

void loop() {
//look for new cards
MFRC522::MIFARE_Key key;
for (byte i = 0; i < 6; i++) {
key.keyByte = 0xFF;

  • }*
  • // Look for new cards*
  • if ( ! rfid.PICC_IsNewCardPresent()) {*
  • return;*
  • }*
  • // Select one of the cards*
  • if ( ! rfid.PICC_ReadCardSerial()) {*
  • return;*
  • }*
  • readRFID();*
    delay(10);
    }
    void readRFID() {
    lcd.clear();
    Serial.print("Card UID:");
  • for (byte i = 0; i < rfid.uid.size; i++) {*
    _ // Serial.print(mfrc522.uid.uidByte < 0x10 ? " 0" : " ");_
    _ // Serial.print(mfrc522.uid.uidByte*, DEC);
    }
    Serial.println();
    // Dump PICC type*
    * byte piccType = rfid.PICC_GetType(rfid.uid.sak);*
    * // Serial.print("PICC type: ");_
    //Serial.println(mfrc522.PICC_GetTypeName(piccType));
    if ( piccType != MFRC522::PICC_TYPE_MIFARE_MINI*

    * && piccType != MFRC522::PICC_TYPE_MIFARE_1K*
    * && piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
    _ //Serial.println("This sample only works with MIFARE Classic cards.");
    return;
    }
    // defining Cards here*
    * // student1 59 98 E3 2A*
    * if( (rfid.uid.uidByte[0] == 0x59) && (rfid.uid.uidByte[1] == 0x98) && (rfid.uid.uidByte[2] == 0xE3) && (rfid.uid.uidByte[3] == 0x2A) ) // student1 card*
    * {
    tone(buzzer, 2000);
    delay(200);
    noTone(buzzer);
    delay(200);
    lcd.clear();

    lcd.print("Attended");
    delay(1000);
    lcd.clear();
    lcd.print("Welcome Ahmed");
    Serial.println("Ahmed");
    delay(1000);
    Student= "Ahmed";
    // for gsm
    sms.beginSMS("+966568123988");
    sms.print("Ahmed Attended");
    sms.endSMS();
    logCard();
    verifyCheckIn();
    delay(1000);
    lcd.clear();
    lcd.print("Message sent");
    delay(2000);*_

* lcd.clear();*
* lcd.print("Swipe Your ID");*
* return;*
* }*

* // student29 A2 14 A4*
* if( (rfid.uid.uidByte[0] == 0x29) && (rfid.uid.uidByte[1] == 0xA2) && (rfid.uid.uidByte[2] == 0x14) && (rfid.uid.uidByte[3] == 0xA4) ) // student2 card*
* {*
* tone(buzzer, 2000);*
*delay(200); *
noTone(buzzer);
* lcd.clear();*
* lcd.print("Attended");*
* delay(1000);*
* lcd.clear();*
* lcd.print("Welcome Khaled");*
* Serial.println("Khaled");*
* delay(1000);*
* Student= "Khaled";*
* // for gsm *
* sms.beginSMS("+966568123988");*
sms.print("Ahmed Attended");
sms.endSMS();
* logCard();*
* verifyCheckIn();*
* delay(1000);*
* lcd.clear();*
* lcd.print("Message sent");*
* delay(2000);*

* lcd.clear();*
* lcd.print("Swipe Your ID");*

* return;*
* }*
* if( (rfid.uid.uidByte[0] == 0xE9) && (rfid.uid.uidByte[1] == 0x56) && (rfid.uid.uidByte[2] == 0x57) && (rfid.uid.uidByte[3] == 0xA2) ) // student1 card*
* {*
* tone(buzzer, 2000);*
*delay(200); *
noTone(buzzer);
* lcd.clear();*
* lcd.print("Attended");*
* delay(1000);*
* lcd.clear();*
* lcd.print("Welcome Omar");*
* Serial.println("Omar");*
* delay(1000);*
* Student= "Omar";*
* // for gsm *
* sms.beginSMS("+966568123988");*
sms.print("Ahmed Attended");
sms.endSMS();

* logCard();*
* verifyCheckIn();*
* delay(1000);*
* lcd.clear();*
* lcd.print("Message sent");*
* delay(2000);*

* lcd.clear();*
* lcd.print("Swipe Your ID");*
* return;*
* }*
* if( (rfid.uid.uidByte[0] == 0x69) && (rfid.uid.uidByte[1] == 0x5A) && (rfid.uid.uidByte[2] == 0x04) && (rfid.uid.uidByte[3] == 0xA4) ) // student1 card*
* {*
* tone(buzzer, 2000);*
*delay(200); *
noTone(buzzer);
* lcd.clear();*
* lcd.print("Attended");*
* delay(1000);*
* lcd.clear();*
* lcd.print("Welcome Fahad");*
* Serial.println("Fahad");*
* delay(1000);*
* Student= "Fahad";*
* // for gsm *
* sms.beginSMS("+966568123988");*
sms.print("Ahmed Attended");
sms.endSMS();

* logCard();*
* verifyCheckIn();*
* delay(1000);*
* lcd.clear();*
* lcd.print("Message sent");*
* delay(2000);*

* lcd.clear();*
* lcd.print("Swipe Your ID");*
* return;*
* }*
* if( (rfid.uid.uidByte[0] == 0xD9) && (rfid.uid.uidByte[1] == 0x30) && (rfid.uid.uidByte[2] == 0x04) && (rfid.uid.uidByte[3] == 0xA4) ) // student1 card*
* {*
* tone(buzzer, 2000);*
*delay(200); *
noTone(buzzer);
* lcd.clear();*
* lcd.print("Attended");*
* delay(1000);*
* lcd.clear();*
* lcd.print("Welcome Saleh");*
* Serial.println("Saleh");*
* delay(1000);*
* Student= "Saleh";*
* // for gsm *
* sms.beginSMS("+966568123988");*
sms.print("Ahmed Attended");
sms.endSMS();
* logCard();*
* verifyCheckIn();*
* delay(1000);*
* lcd.clear();*
* lcd.print("Message sent");*
* delay(2000);*

* lcd.clear();*
* lcd.print("Swipe Your ID");*
* return;*
* }*
* else *

* Serial.println("unregistered user");*

tone(buzzer, 2000);
*delay(200); *
noTone(buzzer);
lcd.print("Wrong class");
delay(2000);
lcd.clear();
lcd.print("Swipe your ID");

// Sound the buzzer when a card is read
delay(200);
}

Here are the functions:
void logCard() {
// Enables SD card chip select pin
digitalWrite(CS_SD,LOW);

// Open file
myFile=SD.open("DATA.txt", FILE_WRITE);

// If the file opened ok, write to it
if (myFile) {
Serial.println("File opened ok");
lcd.clear();
lcd.print("File opened ok");
delay(2000);
myFile.print(Student);
myFile.print(" , ");

// Save time on SD card
DateTime now = rtc.now();
myFile.print(now.year(), DEC);
myFile.print('/');
myFile.print(now.month(), DEC);
myFile.print('/');
myFile.print(now.day(), DEC);
myFile.print(',');
myFile.print(now.hour(), DEC);
myFile.print(':');
myFile.println(now.minute(), DEC);

// Print time on Serial monitor
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.println(now.minute(), DEC);
Serial.println("sucessfully written on SD card");

lcd.clear();
lcd.print(now.year(), DEC);
lcd.print(':');
lcd.print(now.month(), DEC);
lcd.print(':');
lcd.print(now.day(), DEC);
lcd.print(' ');
lcd.setCursor(11, 0);
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.setCursor(0, 1);
lcd.print("Written on SD...");
delay(2000);

myFile.close();

// Save check in time;
userCheckInHour = now.hour();
userCheckInMinute = now.minute();
}
else {

Serial.println("error opening data.txt");
lcd.clear();
lcd.print("error opening data.txt");
}
// Disables SD card chip select pin
digitalWrite(CS_SD,HIGH);
}

void verifyCheckIn(){
if((userCheckInHour < checkInHour)||((userCheckInHour==checkInHour) && (userCheckInMinute <= checkInMinute))){
digitalWrite(greenLED, HIGH);
delay(2000);
digitalWrite(greenLED,LOW);
Serial.println("On time");
lcd.clear();
lcd.print("On time");

}
else{
digitalWrite(redLED, HIGH);
delay(2000);
digitalWrite(redLED,LOW);
Serial.println("You are late...");
lcd.clear();
lcd.print("You are Late...");
delay(3000);
lcd.clear();

}
}

For the one without the shield I just remove the GSM library everything I have defined and gsm acceses and sms. Then remove this setup block as well as the one in the loop.
Serial.println("SMS Messages Sender");
// connection state
boolean notConnected = true;

// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while (notConnected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
notConnected = false;

} else {
Serial.println("Not connected");
lcd.print("GSM not Connected");
delay(1000);
}
}

I slept for few hours and now everything works? what. anyway thank you for the attempt of helping.

Haha. I've Heard those words wefore. Next time You post code read "How to use this Forum" #7, how to attach code using the code tags, </>.