Can't read NEO 6m GPS module on arduino pins 0 and 1

I’m into a project that uses GPS module NEO-6M and ESP8266_01. The projects takes gps data and send them to thingspeak.

Independently, the arduino is working well with the two modules but when i tries to combine the two code, it fails to work. Instead of the arduino sending the latitude to cloud it keeps sending 0.

I’m using software serial to communicate with both the neo6m and the esp.

The full code is given below

#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#define RX 2
#define TX 3

int RXPin = 4;
int TXPin = 5;

double getSensorData();
void sendCommand(String command, int maxTime, char readReplay[]);

int GPSBaud = 9600;
TinyGPSPlus gps;

String AP = "SAMUEL";       // AP NAME
String PASS = "adedayo2020"; // AP PASSWORD
String API = "PTHARH9GLC0R1IJM";   // Write API KEY
String HOST = "";
String PORT = "80";
String field = "field1";
int countTrueCommand;
int countTimeCommand; 
boolean found = false; 
double valSensor = 1;
SoftwareSerial esp8266(RX,TX); 
SoftwareSerial gpsSerial(RXPin, TXPin);
void setup() {
  sendCommand("AT+CWJAP=\""+ AP +"\",\""+ PASS +"\"",20,"OK");

void loop() {

 valSensor = getSensorData();
 String getData = "GET /update?api_key="+ API +"&"+ field +"="+String(valSensor);
 sendCommand("AT+CIPSTART=0,\"TCP\",\""+ HOST +"\","+ PORT,15,"OK");
 sendCommand("AT+CIPSEND=0," +String(getData.length()+4),4,">");

double getSensorData(){

   while (gpsSerial.available() > 0)
    if (gps.encode(
      if (gps.location.isValid())

  // 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");

void sendCommand(String command, int maxTime, char readReplay[]) {

  Serial.print(". at command => ");
  Serial.print(" ");
  while(countTimeCommand < (maxTime*1))
      found = true;
  if(found == true)
    countTimeCommand = 0;
  if(found == false)
    countTrueCommand = 0;
    countTimeCommand = 0;
  found = false;

I come to discover that i can’t use two software serials in the same program so i decided to read the NMEA data of the GPS using the 0 and 1 pins. the code is given below but he data is not flowing whereas it worked well when i use software serial

String a;
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
void loop() {
while(Serial.available()) {
a= Serial.readString();// read the incoming data as string


Is there a way i can get around the problem since i have to use the two modules

The best way, in my opinion, is to use a Mega with 3 extra hardware serial ports. Trying to use the hardware serial (pins 0 & 1) for 2 devices (GPS and serial monitor) can be problematic.

I come to discover that i can't use two software serials

You can but it is not straightforward. See the 2 port receive example.

Also a good idea to provide a link as to exactly which ESP8266 board you are using, there are a lot of different versions out there.

A point to note, the ESP8266 is not actually an Arduino, its just a board that can be programmed with the Arduino IDE.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.