IoT Based Smart Garbage Monitoring System/Debjyoti Sinha and his group/Purdue School of Engineering and Technology

Dependencies:   mbed HCSR04 ESP8266

--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Dec 13 01:41:15 2018 +0000
@@ -0,0 +1,116 @@
+#include "mbed.h"
+#include "mbed.h"
+#include "hcsr04.h"
+#include "ESP8266.h"
+#define APIKEY QSL7YVXB73QHN2EK   //Put "Write key" of your channel in 
+#define IP ""       // IP Address of "\"
+const char *WIFI_SSID = "ssid"; // Enter your Wi-Fi name 
+const char *WIFI_PASS = "password" ; // Enter your Wi-Fi password
+//#define WIFI_SSID "ssid"
+//#define WIFI_PASS "password"
+HCSR04  usensor(PTC12,PTC4);
+DigitalOut trigger(PTC12);
+DigitalOut RED(LED1); //monitor trigger
+DigitalOut GREEN(LED2); //monitor echo
+InterruptIn echo(PTC4);
+Serial pc (USBTX, USBRX); //Serial Communication
+ESP8266 wifi (PTC17, PTC16, 115200); //Setting baud rate for Wifi Esp Module
+char snd[255], rcv[1000];
+#define IP ""//IP address of
+unsigned int pulsedur;
+Timer pulsetime;
+void wifi_send(void);
+int main()
+unsigned int distance;
+//Initializing Wi-Fi
+pc.printf("SET mode to AP\r\n");
+wifi.SetMode(1); //set the mode of ESP to 1
+wifi.RcvReply(rcv,1000); //receive response by ESP
+pc.printf("%s",rcv); //print the response
+pc.printf("Connect to the Wifi\r\n"); //wifi name & password
+wifi.RcvReply(rcv, 1000); //receive response by ESP
+pc.printf("%s\n",rcv); //print the response
+wait(8); //waiting for the response from ESP
+pc.printf("Getting IP\r\n"); //getting the IP address from the connected AP
+wifi.GetIP(rcv); //IP address received from AP
+pc.printf("%s\n",rcv); //print response on TeraTerm
+pc.printf("Initializing the Wi-Fi\r\n");
+//Loop to read distance, scale and print 
+pulsedur = pulsetime.read_us();
+distance= (pulsedur*343)/20000;
+pc.printf("Distance is %d cm\n\r" ,distance);
+pc.printf("Uploading status to the cloud\n\r");
+//wait before sending another ping since echo(s) may return
+   };
+//End of main program
+//Routing data to cloud
+void wifi_send(void)
+ unsigned int distance;
+pc.printf("Uploading Wi-Fi Data");
+pc.printf("\r\nSet Wi-Fi into Single Channel Mode\r\n");
+strcpy(snd,"AT+CIPMUX=0"); //set wi-fi into single channel mode
+pc.printf("\r\nMode status is %s",rcv);
+//Connecting to Thingspeak server
+pc.printf("\r\nConnecting to Thingspeak server\r\n");
+pc.printf("\r\nSending data: %s",snd);
+pc.printf("\r\nServer status: %s",rcv);
+//Deliver Data
+pc.printf("\r\nDelivering Characters");
+pc.printf("\r\nStatus sent: %s",rcv);
+//Upload values to cloud website
+pc.printf("Uploading data to Thingspeak\r\n");
+pc.printf("\r\nStatus sent: %s",rcv);
+//Closing connection
+pc.printf("\r\nClose the connection");
+strcpy(snd,"AT+CIPCLOSE");//Closing connection to the server