One of the main concerns with HAJJ event has been solid waste management which impacts the health and environment due to the high density of visitors in this event. The detection, monitoring and management of wastes is one of the primary problems of the hajj event, especially in the most crowded places like the holy locations (Mina, Arafat and Muzdalifah). The traditional way of manually monitoring the wastes in trash bins is a cumbersome process and claims more human efforts, time, cost and makes uncomfortable environment for the visitors and this can easily be avoided with our present technologies. How can we enhance our waste management system using technology? Our Project idea CompaCAN comes in to do that. CompaCAN is a smart solar powered trash bin. All the trash bins in dense crowded places are connected through a network managed by web application, allows it to detect the full bins and send notification to the transfer station to pick them up. So our product will provide a well-organized waste collection and do it in the same time when pilgrims are present. An LCD screen is attached displaying videos to induce people to use these bins. As future work, we will make waste collection more efficient by compacting automatically its content once it’s full, increasing its capacity up to 8 times than a normal bin with a similar size. Also collecting data on the trash and sending it to the concerned scientists and researchers to discover and study the different problems due to garbage, as trash nature, improving recycling, caused diseases… Throughout our project, we will address Internet of Things segment, an innovative and a sustainable way that will help to keep the environment clean and healthy.

Code to read data from sensors and send it to the Cloud :

#include <DHT.h>  // Including library for dht

#include <WiFi.h>
#include <WiFiMulti.h>

String apiKey = "3GIP6Z0B9VF4YVXE";
const char *ssid =  "dESK";    
const char *pass =  "Atleast8";
const char* server = "api.thingspeak.com";
const int trigPin = 4;
const int echoPin = 2;
//float sensorValue,odor;
int sensorValue;
int flam = 5;
int per ;


// defines variables
long duration;
int distance;

  #define DHTPIN 15          

DHT dht(DHTPIN, DHT11);

WiFiClient client;

void setup() 
{
  pinMode( 25, INPUT);
  pinMode(flam , INPUT);
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
 // Starts the serial communication
       Serial.begin(115200);
       delay(10);

       dht.begin();

       Serial.println("Connecting to ");
       Serial.println(ssid);

               WiFi.begin(ssid, pass);

      while (WiFi.status() != WL_CONNECTED) 
     {
            delay(500);
            Serial.print(".");
     }
      Serial.println("");
      Serial.println("WiFi connected");


}
void loop() {
  // odor sensor 
  sensorValue = analogRead(25);

//flam detection 
int danger=0 ;
bool flame = digitalRead(flam);
if ( flame == HIGH )
{
 danger =10 ; 
}
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
per = 100-(distance*100)/19;
float h = dht.readHumidity();
       float t = dht.readTemperature();
       if (isnan(h) || isnan(t)) 
                 {
                     Serial.println("Failed to read from DHT sensor!");
                      return;
                 }
sensorValue=0;
                         if (client.connect(server,80))   //   "184.106.153.149" or api.thingspeak.com
                      {  

                             String postStr = apiKey;
                             postStr +="&field1=";
                             postStr += String(t);
                             postStr +="&field2=";
                             postStr += String(h);
                             postStr +="&field3=";
                             postStr += String(per);
                             postStr +="&field4=";
                             postStr += String(danger);
                             postStr +="&field5=";
                             postStr += String(sensorValue);
                             postStr += "\r\n\r\n";

                             client.print("POST /update HTTP/1.1\n");
                             client.print("Host: api.thingspeak.com\n");
                             client.print("Connection: close\n");
                             client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
                             client.print("Content-Type: application/x-www-form-urlencoded\n");
                             client.print("Content-Length: ");
                             client.print(postStr.length());
                             client.print("\n\n");
                             client.print(postStr);

                             Serial.print("Temperature: ");
                             Serial.print(t);
                             Serial.print(" degrees Celcius, Humidity: ");
                             Serial.print(h);
                             Serial.print(" percentage : ");
                             Serial.print(distance);
                             Serial.print(" percentage: ");
                             Serial.print(per);
                              Serial.print(" flam : ");
                             Serial.print(danger);
                              Serial.print(" smal : ");
                             Serial.print(sensorValue,DEC);
                             Serial.println("  . Send to Thingspeak.");
                        }
          client.stop();

          Serial.println("Waiting...");

  // thingspeak needs minimum 15 sec delay between updates, i've set it to 30 seconds
  delay(1000);
}




code to read data from cloud:

            using (WebClient wc = new WebClient())
            {
                root lo = new root();
                var json = wc.DownloadString("https://api.thingspeak.com/channels/551919/feeds.json?api_key=FIYLZ7IYD0Z7LTVB&results=2");
                lo = JsonConvert.DeserializeObject<root>(json);
                if (length.len != lo.feeds[lo.feeds.Length-1].entry_id)
                {
                    length.len = lo.feeds[lo.feeds.Length-1].entry_id;
                    string sqlstatment = "INSERT INTO Records";
                    sqlstatment += "(Id_T, Hem, Tem, Lev, firerAlarm, airQuality, DT)";
                    sqlstatment += "VALUES ";
                    sqlstatment += "(@Id_T, @Hem, @Tem, @Lev, @firerAlarm, @airQuality, @DT)";
                    SqlConnection con = new SqlConnection("data source=DESKTOP-3S2UFVT\\SQLEXPRESS;initial catalog=CompaCAN;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework");
                    SqlCommand cmd = new SqlCommand(sqlstatment, con);
                    cmd.Parameters.AddWithValue("@Id_T", 1);
                    cmd.Parameters.AddWithValue("@Hem", ((int)Convert.ToDecimal(lo.feeds[lo.feeds.Length - 1].field2)));
                    cmd.Parameters.AddWithValue("@Tem", ((int)Convert.ToDecimal(lo.feeds[lo.feeds.Length - 1].field1)));
                    cmd.Parameters.AddWithValue("@Lev", ((int)Convert.ToDecimal(lo.feeds[lo.feeds.Length - 1].field3)));
                    cmd.Parameters.AddWithValue("@firerAlarm", ((int)Convert.ToDecimal(lo.feeds[lo.feeds.Length - 1].field4)));
                    cmd.Parameters.AddWithValue("@airQuality", ((int)Convert.ToDecimal(lo.feeds[lo.feeds.Length - 1].field5)));
                    cmd.Parameters.AddWithValue("@DT", DateTime.Now);
                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                    }
                    catch (Exception err)
                    {

                    }
                }
                Console.Read();
            }

charts code:

$.ajax({
                url: "/Dashboards/List",
                type: "GET",
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                success: function (result) {
                    console.log(result);

                    var barOptions = {
                        series: {
                            bars: {
                                show: true,
                                barWidth: 0.6,
                                fill: true,
                                fillColor: {
                                    colors: [{
                                        opacity: 0.8
                                    }, {
                                        opacity: 0.8
                                    }]
                                }
                            }
                        },
                        xaxis: {
                            tickDecimals: 0,
                            scaleLabel: {
                                display: true,
                                labelString: 'probability'
                            }
                        },
                        colors: ["#1ab394"],
                        grid: {
                            color: "#999999",
                            hoverable: true,
                            clickable: true,
                            tickColor: "#D4D4D4",
                            borderWidth: 0
                        },
                        legend: {
                            show: false
                        },
                        tooltip: true,
                        tooltipOpts: {
                            content: "x: %x, y: %y"
                        }
                    };
                    var barData = {
                        label: "bar",
                        data: [
                            [1, result.airQuality],
                            [2, 85],
                            [3, 19],
                            [4, 34]
                        ]
                    };
                    var barData2 = {
                        label: "bar",
                        data: [
                            [1, result.Lev],
                            [2, 40],
                            [3, 85],
                            [4, 13]
                        ]
                    };
                    var barData3 = {
                        label: "bar",
                        data: [
                            [1, result.Tem],
                            [2, 25],
                            [3, 5],
                            [4, 85]
                        ]
                    };
                    var barData4 = {
                        label: "bar",
                        data: [
                            [1, result.Hem],
                            [2, 25],
                            [3, 85],
                            [4, 34]
                        ]
                    };

                    $.plot($("#flot-bar-chart"), [barData], barOptions);
                    $.plot($("#flot-bar-chart2"), [barData2], barOptions);
                    $.plot($("#flot-bar-chart3"), [barData3], barOptions);
                    $.plot($("#flot-bar-chart4"), [barData4], barOptions);


                },
                error: function (errormessage) {
                    alert(errormessage.responseText);
                }
            })

SMS Code :

private async Task PerformTaskAsync()
        {
            sendSMS sms = new sendSMS();

            using (WebClient wc = new WebClient())
            {
                root lo = new root();
                var json = wc.DownloadString("https://api.thingspeak.com/channels/551919/feeds.json?api_key=FIYLZ7IYD0Z7LTVB&results=2");
                lo = JsonConvert.DeserializeObject<root>(json);
                try
                {
                    if ((int)Convert.ToDecimal(lo.feeds[lo.feeds.Length - 1].field1) > 90)
                        sms.SendMessage(" تنبيه رطوبه");
                    if ((int)Convert.ToDecimal(lo.feeds[lo.feeds.Length - 1].field2) > 60)
                        sms.SendMessage(" تنبيه حراره");
                    if ((int)Convert.ToDecimal(lo.feeds[lo.feeds.Length - 1].field3) > 90)
                        sms.SendMessage(" تنبيه امتلاء الحاوية");
                    if ((int)Convert.ToDecimal(lo.feeds[lo.feeds.Length - 1].field4) > 0)
                        sms.SendMessage(" تنبيه حريق");
                    if ((int)Convert.ToDecimal(lo.feeds[lo.feeds.Length - 1].field5) > 50)
                        sms.SendMessage(" تنبيه تلوث الهواء");
                    bussy = false;
                }
                catch (Exception err)
                {
                    if ((int)Convert.ToDecimal(lo.feeds[lo.feeds.Length - 1].field1) > 90)
                        sms.SendMessage(" تنبيه رطوبه");
                    if ((int)Convert.ToDecimal(lo.feeds[lo.feeds.Length - 1].field2) > 60)
                        sms.SendMessage(" تنبيه حراره");
                    if ((int)Convert.ToDecimal(lo.feeds[lo.feeds.Length - 1].field3) > 90)
                        sms.SendMessage(" تنبيه امتلاء الحاوية");
                    if ((int)Convert.ToDecimal(lo.feeds[lo.feeds.Length - 1].field4) > 0)
                        sms.SendMessage(" تنبيه حريق");
                    if ((int)Convert.ToDecimal(lo.feeds[lo.feeds.Length - 1].field5) > 50)
                        sms.SendMessage(" تنبيه تلوث الهواء");
                    bussy = false;
                }
                Console.Read();
            }
        }

Built With

  • .net
  • .net-environment
  • api
  • arduino
  • bootstrap
  • c#
  • css
  • esp32
  • fire-sensor
  • flotjs
  • gas-sensor
  • html5
  • humidity-sensor
  • jquery
  • json
  • level-sensor
  • micro-c
  • microsoft-sql
  • microsoft-sql-server
  • small-trash-can
  • temperature-sensor
  • thingspeak(internet-of-things)-api
  • windows-service
Share this project:

Updates