Interfacing neo-6 and Gsm 900 on Arduino uno

Hi I am new to arduino and new to this forum I have been following comments about a similar post for my project but that has closed and I can't reply there anymore. Anyways I am trying to get location, speed through neo6m and if it exceeds a certain limit I want the gsm module to send a message containing speed, latitude and longitude. I have a written a code an will be sharing that as well. I can't seem to get it work. please help in areas of the code which you think are wrong.

#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include <AltSoftSerial.h>

#define RX1 7
#define TX1 8

#define RX2 9
#define TX2 10

double Latitude, Longitude, Altitude, speed;

TinyGPSPlus gps;
SoftwareSerial gpsPort(RX1, TX1);
AltSoftSerial gsmPort(RX2, TX2);

void setup() {
  gsmPort.begin(9600);
  Serial.begin(9600);
  gpsPort.begin(9600);
  delay(100);
}

void loop() {

  while (gpsPort.available() > 0) {
    if (gps.encode(gpsPort.read()))
      getGPSdata();
  }

  if (Serial.available() > 0)
    switch (Serial.read()) {
      case 'SM':
        SendMessage();
        break;
      case 'RM':
        RecieveMessage();
        break;
    }

  if (gsmPort.available() > 0) {
    Serial.write(gsmPort.read());
  }
  
}

void getGPSdata() {

  if (gps.location.isValid()) {
    Latitude = gps.location.lat(), 6;   // Latitude in degrees (double)
    Longitude = gps.location.lng(), 6;  // Longitude in degrees (double)
  }

  if (gps.speed.isValid()) {
    speed = gps.speed.mps();  // Speed in meters per second (double)
  }

  if (gps.altitude.isValid()) {
    Altitude = gps.altitude.meters();  // Altitude in meters (double)
  }
}

void SendMessage() {

  gsmPort.println("AT+CMGF=1");                    //Sets the GSM Module in Text Mode
  delay(1000);                                     // Delay of 1000 milli seconds or 1 second
  gsmPort.println("AT+CMGS=\"+923111000913\"\r");  // Replace x with mobile number
  delay(1000);
  gsmPort.println("OverSpeeding");  // The SMS text you want to send
  gsmPort.println("Speed: ");
  gsmPort.println(speed, 6);
  gsmPort.println("Location: ");
  gsmPort.print(Latitude, 6);
  gsmPort.print(',');
  gsmPort.print(Longitude, 6);
  delay(100);
  gsmPort.println((char)26);  // ASCII code of CTRL+Z
  delay(1000);
}

void RecieveMessage() {
  gsmPort.println("AT+CNMI=2,2,0,0,0");  // AT Command to receive a live SMS
  delay(1000);
}

Welcome to the forum

So what does the code do or not do that it should ?

Hi Thanks,
Sorry about the late reply,
So the code was written to perform two functions;
One I wat it to collect gps data only the current speed, latitude and longitude
Second I want it to send this collected data to a number through sim900A module if the Speed exceeds a certain limit.
So basically the project is sending the vehicle's speed and location when it exceeds a speed limit.

The problem that I am having is that the code compiles and verifies and uploads on the uni without any errors or warnings, but does not perform its function and instead gives me gibberish readings on the serial monitor. It does not give me location or speed or sends the message.

have you tested the GSM and GPS devices in seperate test programs?
it looks like you are using a UNO - the probability of SoftwareSerial and AltSoftSerial receiving data concurrently and giving correct results is very low
if you need two serial ports move to a micro with hardware serial ports, e.g. a Mega
upload a schematic of the wiring - in particular how are you powering the devices?
upload serial monitor output in text (not image)

Yes I did those codes a re working fine.

You would be better off using an Arduino board that has multiple hardware serial ports. I have seen nothing but trouble when members attempt to use more than one software serial port.

So what board do think can be used instead of the UNO?

if the GSM and GPS devices use 5V logic an Arduino Mega - it has 4 hardware serial ports
if 3.3V logic an Arduino Due or an ESP32
give details of the GSM and GPS devices, e.g. part numbers
upload a schematic of the wiring - in particular how are you powering the devices?

For a Mega with a smaller footprint have a look at the Mega Pro.

I am using the 5V logicon the gps as well as the gsm.
The tx rx of gps is connected to pin 7 and 8.
The fsm tx rx are connected to pin 9 and 10.

What is I used a sim808 module would that work with uno?

$GPGSV,1,1,00*79$GPGLL,,,,,,V,N*64,,,,,,N*30$GPGGA,,,,,,0,00,99.99,,,,,,*48$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30$GPGSV,1,1,00*79$GPGLL,,,,,,V,N*64

This is what i get

  if (Serial.available() > 0)
    switch (Serial.read())
    {
      case 'SM':
        SendMessage();
        break;

You can only use switch/case where the case values are integers or resolve to integers. 'SM' is not an integer, neither is it a valid single character so this is wrong, particularly as Serial.read() only reads a single character anyway, so what it returns could never be 'SM' anyway

Looks like the GPS can't get a lock, take it outside.

These cases were present in the solo code for gsm as well. They work fine there.

Even if I go outside and get a lock on the gps. It still shows the same thing. The gps light blinks and all depicting that it has a lock on satellite.

If you say so, but you can't get away from the fact that Serial.read() returns a single character, that switch/case only works with cases that resolve to an integer and that 'SM' is not a valid character in C/C++

What specific changes do I need to make.

An easy fix to the switch/case problem would be to use a single character as the cases