enter image description hereenter image description hereenter image description here

Here is the link : https://www.circuito.io/app?components=10167,11021,12083,13678,13959,975601

I'm just a beginner I don't have the idea on how GPS module wires should be connected

#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.listen();
 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); 

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

esp8266.listen();
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 = "<head><meta http-equiv=\"refresh\" content=\"5; 
     url=192.168.4.1/\"></head>";
     webpage += "<h1>Mabalacat City College Garbage Monitoring System</h1>";
    webpage += "<p><h2>";   
    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+= "<br>";
      webpage+="Distance: ";
      webpage+=distance;
      webpage+=" cm";
      webpage+= "<br>";
      webpage+="Temperature: ";
      webpage+= temp;
      webpage+=" celsius";
      webpage+= "<br>";
      webpage+= "Humidity: ";
      webpage+= hum;
      webpage+= " %";

 webpage += "</h2></p></body>";  
 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)
{
esp8266.listen();
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);
}
gps.listen();
return response;
}
  • Comments are not for extended discussion; this conversation has been moved to chat. – Majenko Nov 14 at 13:39
up vote 0 down vote accepted
GPS - Arduino
---------------
GND -  GND
TX  -  pin of SoftwareSerial RX
RX  -  pin of SoftwareSerial TX
Vcc -  3.3 V

Only one instance of SoftwareSerial can listen. Method listen() determines which one. So you must add esp8266.listen(); before talking to esp8266 and gps.listen(); before talking to GPS module.

  • in setup() add esp8266.listen() before first sendData call
  • in loop() add gps.listen() before while (gps.available())
  • in loop() add esp8266.listen() before if (esp8266.available())
  • Comments are not for extended discussion; this conversation has been moved to chat. – Majenko Nov 14 at 13:39
  • @Majenko, the system didn't offer move to chat and I could not create a chat with OP, because OP doesn't have reputation points to use the chat – Juraj Nov 14 at 13:41
  • The message is an automated moderator thing. I'm just cleaning up. – Majenko Nov 14 at 13:42

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.