ACCELEROMETER adxl345 ,GPS NEO 6M ,GSM 800 not working together

Hi,
I am new to Arduino and trying to make a project on Accident detect and reporting system using ACCELEROMETER ADXL345 ,GPS NEO 6M ,GSM 800 but unable to them together . The Gsm and Adxl345 works fine together but not adxl345 and gps neo6m . When i upload the individual code for both Adxl345 and GPS while all three modules are connected it works but when i upload the code for all three component it the GPS and accelerometer doesn't work . PLEASE HELP !

the following is the complete code for the same.

#include <Wire.h>
#include <TinyGPS++.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
#include<SoftwareSerial.h>
SoftwareSerial Serial1(2,3); //make RX arduino line is pin 2, make TX arduino line is pin 3.
int RXPin = 10;
int TXPin = 11;

int GPSBaud = 9600;
TinyGPSPlus gps;
SoftwareSerial gpsSerial(RXPin, TXPin);
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);
int xsample=0;
int ysample=0;
int zsample=0;

#define samples 10

#define minVal -50
#define MaxVal 50

int i=0;
float latitude=0; 
float logitude=0;                       


void initModule(String cmd, char *res, int t)
{
  while(1)
  {
    Serial.println(cmd);
    Serial1.println(cmd);
    delay(100);
    while(Serial1.available()>0)
    {
       if(Serial1.find(res))
       {
        Serial.println(res);
        delay(t);
        return;
       }

       else
       {
        Serial.println("Error");
       }
    }
    delay(t);
  }
}

void setup() 
{
  Serial1.begin(9600);
  Serial.begin(9600);
   gpsSerial.begin(GPSBaud);
    if(!accel.begin())
  {
    /* There was a problem detecting the ADXL345 ... check your connections */
    Serial.println("Ooops, no ADXL345 detected ... Check your wiring!");
    while(1);
  }
    accel.setRange(ADXL345_RANGE_16_G);
  Serial.println("Initializing...."); 
  Serial.println("Initialized Successfully");
  
  for(int i=0;i<samples;i++)
  {
     sensors_event_t event; 
     accel.getEvent(&event);
    xsample+=event.acceleration.x;
    ysample+=event.acceleration.y;
    zsample+=event.acceleration.z;
  }

  xsample/=samples;
  ysample/=samples;
  zsample/=samples;

  Serial.println(xsample);
  Serial.println(ysample);
  Serial.println(zsample);
  delay(1000);
  
  get_gps();
  delay(2000);
  Serial.println("System Ready..");
}

void loop() 
{
    sensors_event_t event; 
     accel.getEvent(&event);

    int xValue=xsample-event.acceleration.x;
    int yValue=ysample-event.acceleration.y;
    int zValue=zsample-event.acceleration.z;
    
    Serial.print("x=");
    Serial.println(xValue);
    Serial.print("y=");
    Serial.println(yValue);
    Serial.print("z=");
    Serial.println(zValue);

    if(xValue < minVal || xValue > MaxVal  || yValue < minVal || yValue > MaxVal  || zValue < minVal || zValue > MaxVal)
    {
      get_gps();
      Serial.println("Sending SMS");
      Send();
      Serial.println("SMS Sent");
      delay(2000);
    }       
}
void get_gps()
{
  // This sketch displays information every time a new sentence is correctly encoded.
  while (gpsSerial.available() > 0)
    if (gps.encode(gpsSerial.read()))
      displayInfo();

  // If 5000 milliseconds pass and there are no characters coming in
  // over the software serial port, show a "No GPS detected" error
  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println("No GPS detected");
    while(true);
  }
}

void displayInfo()
{
  if (gps.location.isValid())
  {
    Serial.print("Latitude: ");
    Serial.println(gps.location.lat(), 6);
    latitude=(gps.location.lat(),6);
    Serial.print("Longitude: ");
    Serial.println(gps.location.lng(), 6);
float    longitude=(gps.location.lng(), 6);
   Serial.print("Altitude: ");
    Serial.println(gps.altitude.meters());
  }
  else
  {
    Serial.println("Location: Not Available");
  }
  Serial.println();
  Serial.println();
  delay(1000);
}
void Send()
{ 
   Serial1.println("AT");
   delay(500);
   serialPrint();
   Serial1.println("AT+CMGF=1");
   delay(500);
   serialPrint();
   Serial1.print("AT+CMGS=");
   Serial1.print('"');
   Serial1.print("**********8**");    //mobile no. for SMS alert
   Serial1.println('"');
   delay(500);
   serialPrint();
   Serial1.print("Latitude:");
   Serial1.println(latitude);
   delay(500);
   serialPrint();
   Serial1.print(" longitude:");
   Serial1.println(logitude);
   delay(500);
   serialPrint();
   Serial1.print("http://maps.google.com/maps?&z=15&mrt=yp&t=k&q=");
   Serial1.print(latitude,6);
   Serial1.print("+");              //28.612953, 77.231545   //28.612953,77.2293563
   Serial1.print(logitude,6);
   Serial1.write(26);
   delay(2000);
   serialPrint();
}

void serialPrint()
{
  while(Serial1.available()>0)
  {
    Serial.print(Serial1.read());
  }
}

finalproject.ino (5.15 KB)

Softwareserial isnt very good to handle two comm-lines..
Does phone word with only send connect ? ..and gps allow receive only?'
Can this work win just one softserial ?

knut_ny:
Softwareserial isnt very good to handle two comm-lines..
Does phone word with only send connect ? ..and gps allow receive only?'
Can this work win just one softserial ?

The problem is not with a GSM and GPS they work fine with together with different software serial .The problem is with ADxl345 Accelerometer and GPS they are not working together .

For informed help, please read and follow the directions in the "How to use this forum" post.

Explain what "not working together" means.

jremington:
For informed help, please read and follow the directions in the "How to use this forum" post.

Explain what "not working together" means.

The Accelerometer Adxl345 and the Gsm NEO 6M modules are not working together .The adxl345 is giving the out but the GPS module NEO 6m is not giving any output when interfaced with ADXL345.