What code can print the data in the GPS Module? , I'm using GY-NEO6MV2.

I found this code (see attached file) online,
but I am not sure if it will print the data.

Also, I am confused on it's wiring because I already had a ESP8266 I think that I should connect it there?

Please help thank you :slight_smile:

gps code online.txt (256 Bytes)

see attached file)

I'd much rather you posted it.

What happens when you try it ?

AWOL can't you see the file?

biancadelos:
AWOL can't you see the file?

No. I'm posting from my phone.

AWOL here's the code:

/*
PPS->free
rxd->11
txd->10
gnd->gnd
vcc->5v
*/

#include "SoftwareSerial.h"
SoftwareSerial gps(10,11);
void setup(){
Serial.begin(9600);
gps.begin(9600);
}

void loop(){
while (gps.available())
Serial.write(gps.read());
}

biancadelos:
AWOL here's the code:

Where are the code tags?

What IS the problem? The code expects the GPS to be connected to pins 10 and 11, and will write (should be print, since GPSs only send ASCII data) what it reads from those pins to pins 0 and 1.

Here is the updated code (see also attached file) :

#include "DHT.h"
#include "NewPing.h"
#include <SoftwareSerial.h>
#define DEBUG true
SoftwareSerial esp8266(11,10);
SoftwareSerial gps(8,9);
#define DHTPIN 2 // DHT-11 Output Pin connection
#define DHTTYPE DHT11 // DHT Type is DHT 11 (AM2302)
#define TRIGGER_PIN 4
#define ECHO_PIN 3
#define MAX_DISTANCE 400

NewPing sonar(TRIGGER_PIN,ECHO_PIN,MAX_DISTANCE);

float hum;
float temp;

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin (9600);
Serial.println("START");
esp8266.begin(9600);
gps.begin(9600);
dht.begin();

pinMode(TRIGGER_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);

sendData("AT+RST\r\n",2000,DEBUG); // command to reset the module
sendData("AT+CWMODE=2\r\n",1000,DEBUG); // This will configure the mode as access point
sendData("AT+CIFSR\r\n",1000,DEBUG); // This command will get the ip address
sendData("AT+CIPMUX=1\r\n",1000,DEBUG); // This will configure the esp for multiple connections
sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // This command will turn on the server on port 80
}

void loop()
{

delay(2000); // Delay so DHT-11 sensor can stabalize

hum = dht.readHumidity(); // Get Humidity value
temp= dht.readTemperature(); // Get Temperature value

digitalWrite(TRIGGER_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGGER_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGGER_PIN, LOW);

long duration,distance;
duration= pulseIn(ECHO_PIN,HIGH);

distance = duration/58.2;

Serial.print("Humid: ");
Serial.print(hum);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.print(" C, ");
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(50);

while (gps.available())
Serial.write(gps.read());

if(esp8266.available()) // This command will that check if the esp is sending a message
{
if(esp8266.find("+IPD,"))
{
delay(1000);
int connectionId = esp8266.read()-48; /* We are subtracting 48 from the output because the read() function returns
the ASCII decimal value and the first decimal number which is 0 starts at 48*/
String webpage = "<meta http-equiv="refresh" content="5; url=192.168.4.1/">";
webpage += "

Mabalacat City College Garbage Monitoring System

";
webpage += "

";
if (distance<=5)
{
webpage+= " Trash can is Red";
}
if (distance == 20)
{
webpage+= " Trash can is Orange";
}
if (distance == 35)
{
webpage+= " Trash can is Light Orange";
}
if (distance == 50)
{
webpage+= " Trash can is Yellow";
}
if (distance == 70)
{
webpage+= " Trash can is 2st Light Yellow";
}
if (distance == 85)
{
webpage+= " Trash can is 1st Light Yellow";
}
if (distance == 95)
{
webpage+= " Trash can is Green";
}
if (distance >= 100)
{
webpage+= " Trash can is Empty";
}
webpage+= "
";
webpage+="Distance: ";
webpage+=distance;
webpage+=" cm";
webpage+= "
";
webpage+="Temperature: ";
webpage+= temp;
webpage+=" celsius";
webpage+= "
";
webpage+= "Humidity: ";
webpage+= hum;
webpage+= " %";

webpage += "

";
String cipSend = "AT+CIPSEND=";
cipSend += connectionId;
cipSend += ",";
cipSend +=webpage.length();
cipSend +="\r\n";

sendData(cipSend,1000,DEBUG);
sendData(webpage,1000,DEBUG);
String closeCommand = "AT+CIPCLOSE=";
closeCommand+=connectionId;
closeCommand+="\r\n";
sendData(closeCommand,3000,DEBUG);
}
}
}

String sendData(String command, const int timeout, boolean debug)
{
String response = "";
esp8266.print(command);
long int time = millis();
while( (time+timeout) > millis())
{
while(esp8266.available())
{
char c = esp8266.read();
response+=c;
}
}
if(debug)
{
Serial.print(command);
Serial.print("> ");
Serial.print(response);
}
return response;
}

= = = = =The output = = = = =

START
AT+RST

AT+CWMODE=2
AT+CIFSR
AT+CIPMUX=1
AT+CIPSERVER=1,80
Humid: 67.00 %, Temp: 31.00 C, Distance: 150 cm
Humid: 67.00 %, Temp: 30.00 C, Distance: 26 cm
Humid: 67.00 %, Temp: 30.00 C, Distance: 151 cm
Humid: 67.00 %, Temp: 30.00 C, Distance: 151 cm
Humid: 67.00 %, Temp: 30.00 C, Distance: 151 cm
Humid: 67.00 %, Temp: 30.00 C, Distance: 150 cm
Humid: 67.00 %, Temp: 30.00 C, Distance: 149 cm
Humid: 67.00 %, Temp: 30.00 C, Distance: 151 cm
Humid: 67.00 %, Temp: 30.00 C, Distance: 3501 cm
Humid: 68.00 %, Temp: 31.00 C, Distance: 13 cm
Humid: 67.00 %, Temp: 30.00 C, Distance: 151 cm
Humid: 67.00 %, Temp: 30.00 C, Distance: 149 cm
Humid: 67.00 %, Temp: 30.00 C, Distance: 3467 cm
Humid: 68.00 %, Temp: 31.00 C, Distance: 13 cm
Humid: 68.00 %, Temp: 31.00 C, Distance: 149 cm
Humid: 66.00 %, Temp: 30.00 C, Distance: 149 cm

arduino code.txt (4.49 KB)

arduino ouput.txt (861 Bytes)

Here when I comment out the gps related codes (see also attachment /output) :

#include "DHT.h"
#include "NewPing.h"
#include <SoftwareSerial.h>
#define DEBUG true
SoftwareSerial esp8266(11,10);
//SoftwareSerial gps(8,9);
#define DHTPIN 2 // DHT-11 Output Pin connection
#define DHTTYPE DHT11 // DHT Type is DHT 11 (AM2302)
#define TRIGGER_PIN 4
#define ECHO_PIN 3
#define MAX_DISTANCE 400

NewPing sonar(TRIGGER_PIN,ECHO_PIN,MAX_DISTANCE);

float hum;
float temp;

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin (9600);
Serial.println("START");
esp8266.begin(9600);
//gps.begin(9600);
dht.begin();

pinMode(TRIGGER_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);

sendData("AT+RST\r\n",2000,DEBUG); // command to reset the module
sendData("AT+CWMODE=2\r\n",1000,DEBUG); // This will configure the mode as access point
sendData("AT+CIFSR\r\n",1000,DEBUG); // This command will get the ip address
sendData("AT+CIPMUX=1\r\n",1000,DEBUG); // This will configure the esp for multiple connections
sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // This command will turn on the server on port 80
}

void loop()
{

delay(2000); // Delay so DHT-11 sensor can stabalize

hum = dht.readHumidity(); // Get Humidity value
temp= dht.readTemperature(); // Get Temperature value

digitalWrite(TRIGGER_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGGER_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGGER_PIN, LOW);

long duration,distance;
duration= pulseIn(ECHO_PIN,HIGH);

distance = duration/58.2;

Serial.print("Humid: ");
Serial.print(hum);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.print(" C, ");
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(50);

//while (gps.available())
//Serial.write(gps.read());

if(esp8266.available()) // This command will that check if the esp is sending a message
{
if(esp8266.find("+IPD,"))
{
delay(1000);
int connectionId = esp8266.read()-48; /* We are subtracting 48 from the output because the read() function returns
the ASCII decimal value and the first decimal number which is 0 starts at 48*/
String webpage = "<meta http-equiv="refresh" content="5; url=192.168.4.1/">";
webpage += "

Mabalacat City College Garbage Monitoring System

";
webpage += "

";
if (distance<=5)
{
webpage+= " Trash can is Red";
}
if (distance == 20)
{
webpage+= " Trash can is Orange";
}
if (distance == 35)
{
webpage+= " Trash can is Light Orange";
}
if (distance == 50)
{
webpage+= " Trash can is Yellow";
}
if (distance == 70)
{
webpage+= " Trash can is 2st Light Yellow";
}
if (distance == 85)
{
webpage+= " Trash can is 1st Light Yellow";
}
if (distance == 95)
{
webpage+= " Trash can is Green";
}
if (distance >= 100)
{
webpage+= " Trash can is Empty";
}
webpage+= "
";
webpage+="Distance: ";
webpage+=distance;
webpage+=" cm";
webpage+= "
";
webpage+="Temperature: ";
webpage+= temp;
webpage+=" celsius";
webpage+= "
";
webpage+= "Humidity: ";
webpage+= hum;
webpage+= " %";

webpage += "

";
String cipSend = "AT+CIPSEND=";
cipSend += connectionId;
cipSend += ",";
cipSend +=webpage.length();
cipSend +="\r\n";

sendData(cipSend,1000,DEBUG);
sendData(webpage,1000,DEBUG);
String closeCommand = "AT+CIPCLOSE=";
closeCommand+=connectionId;
closeCommand+="\r\n";
sendData(closeCommand,3000,DEBUG);
}
}
}

String sendData(String command, const int timeout, boolean debug)
{
String response = "";
esp8266.print(command);
long int time = millis();
while( (time+timeout) > millis())
{
while(esp8266.available())
{
char c = esp8266.read();
response+=c;
}
}
if(debug)
{
Serial.print(command);
Serial.print("> ");
Serial.print(response);
}
return response;
}

orig output.png

orig code.txt (4.5 KB)

Suppose that the distance measured is 34. What are you going to output? It makes no sense to have separate output statements for every discrete value. An output statement for a range of values does make sense.

For a cheap temperature/humidity sensor, it makes NO sense to output the values to 2 decimal places. If you get 1/2 degree or % resolution, you are doing good.

void loop()
{
 
  delay(2000);  // Delay so DHT-11 sensor can stabalize

Psst. That's just plain stupid. Even if you COULD use two instances of SoftwareSerial to listen to two devices at the same time (you can't), you would read NOTHING from the GPS for more than two seconds, while it continues to try to write data to the Arduino. Most of it's data is going to end up on the floor.

    long int time = millis();

RTFM. What kind of value does millis() return? It is NOT a signed value.

    while( (time+timeout) > millis())
    {
      while(esp8266.available())
      {
        char c = esp8266.read();
        response+=c;
      } 
    }

Great. A delay with lipstick. It is STILL blocking code.

long duration,distance;
duration= pulseIn(ECHO_PIN,HIGH);

More blocking code.

I guess you are in no hurry to get this project working.