#define IRLeft 7 // Defining that Left Infrared sensor is connected to Digital Pin 7 and it will be called as IRLeft #define IRRight 8 // Defining that Right Infrared sensor is connected to Digital Pin 8 and it will be called as IRRight #define IRBin 11 // Defining that Bin Infrared sensor is connected to Digital Pin 11 and it will be called as IRBin #define M1_a 3 // Defining pin no. and name of the pin to which 1st terminal of Left Motor is connected to Intel Galileo. #define M1_b 5 // Defining pin no. and name of the pin to which 2nd terminal of Left Motor is connected to Intel Galileo. #define M2_a 6 // Defining pin no. and name of the pin to which 1st terminal of Right Motor is connected to Intel Galileo. #define M2_b 9 // Defining pin no. and name of the pin to which 2nd terminal of Right Motor is connected to Intel Galileo. #include // Including Servo.h library used to interface Servo Motor with Intel Galileo #include // add 'Serial Peripheral Interface' Library #include // add the Ethernet Library // all variables declared here can be accessed within any function. Also known as Global Variable byte mac[] = // Enter the MAC address of your device { 0x98, 0x4F, 0xEE, 0x00, 0xCE, 0x50 }; /* Initialize the Ethernet server library with the IP address and port you want to use (port 80 is default for HTTP): */ EthernetServer server(80); // Create a server on port 80 String web_response; // Declare a string variable to know the response from web server EthernetClient client; // client is an object of class EthernetClient to Assign incoming client to 'client' String get_String; // Stores the numerical value in the web_response in string int get_Value=0; // Stores the numerical value in the get_String in 'int' format IPAddress ip(192, 168, 1, 20); // Assign custom IP address to 'ip' String Bin_Status="Available"; // Declaring a String type variable Bin_Status in which the status of the bin will be stored boolean left_ir; // Declaring a boolean type variable in which state of left IR Sensor will be stored. If there is something in front of it, then it returns true boolean right_ir; // Declaring a boolean type variable in which state of Right IR Sensor will be stored. If there is something in front of it, then it returns true boolean IR_Status; // Declaring a boolean type variable in which state of Bin IR Sensor will be stored. If there is something in front of it, then it returns true Servo Servo1; // Creating an object of Servo int count; // Initializing Global Variable Count in which the count will be stored that how many slots it collector has reached void setup() { pinMode (M1_a, OUTPUT); // Defining Left Motor as OUTPUT pinMode (M1_b, OUTPUT); // Defining Left Motor as OUTPUT pinMode (M2_a, OUTPUT); // Defining Right Motor as OUTPUT pinMode (M2_b, OUTPUT); // Defining Right Motor as OUTPUT pinMode(IRLeft,INPUT); // Defining that the Mode of Left IR Sensor is INPUT as we are taking some input from it pinMode(IRRight,INPUT); // Defining that the Mode of Left IR Sensor is INPUT as we are taking some input from it pinMode(IRBin,INPUT); // Defining that the Mode of Left IR Sensor is INPUT as we are taking some input from it Servo1.attach(10); Servo1.write(10); Serial.begin(9600); // begin serial communication at 9600 baud rate Ethernet.begin(mac,ip); // start the Ethernet connection server.begin(); // Start the Ethernet Server } void loop() { client = server.available(); // try to get client if (client) // Checking if the Client is connected or not. If connected, then client will return true value { boolean currentLineIsBlank = true; // Set 'currentLineIsBlank' as true; while (client.connected()) // while loop will be executed until the client is connected { if(client.available()) // Checking if some data is available from the client { // client data available to read char c = client.read(); // read 1 byte (character) from client web_response += c; // save the HTTP request 1 char at a time if (c == '\n' && currentLineIsBlank) // last line of client request is blank and ends with \n { // respond to client only after last line received host_server(); //host the server; Serial.println(web_response); //display web_response get_String=web_response.substring(6,7); //reads the string between 6th and 7th element get_Value=get_String.toInt(); //converts the string into integer Serial.println(get_Value); //display value perform_Task(get_Value); //performs the required task get_String=""; //empty the string web_response = ""; // finished with request, empty string break; //breaks from the loop } if (c == '\n') // every line of text received from the client ends with \r\n { // last character on line of received text currentLineIsBlank = true; // starting new line with next character read } else if (c != '\r') // a text character was received from client { currentLineIsBlank = false; } } // end if (client.available()) } // end while (client.connected()) delay(1); // give the web browser time to receive the data client.stop(); // close the connection } // end if (client) } void host_server() //defines host_server function { client.println("HTTP/1.1 200 OK\r\n" // send a standard http response header "Content-Type: text/html\r\n" // Defines the content type as text/html "Connection: close\r\n" // Closes the connection after the response is sent "\r\n"); // Prints a blank line in the HTML file client.println(""); // Defines document as HTML type client.println(""); // starting html tag client.println(""); // HTML file's head definition client.println("Smart Cleaning Solutions"); // Title is defined client.println(""); // Style of h1 is defined client.print("
=======Smart Cleaning Solutions======="); // Writing the Heading client.print("
 Garbage Bin Status:  "); client.println(Bin_Status); // It wil print the status of the Bin client.print("

=======Call Garbage Cleaning Rover======="); // Defining 4 Buttons so that house owners can click on their corresponding slot client.println("
 House Slot 1
"); client.println("
 House Slot 2
"); client.println("
 House Slot 3
"); client.println("
 House Slot 4
"); client.println(""); } void perform_Task(int slot_no) // defines perform_Task function { if(slot_no==1 || slot_no==2 || slot_no==3 || slot_no==4) // If the house slot is 1 or 2 or 3 or 4, || means or { reach_home(slot_no); // Call the reach_home function in which house slot is slot_no. Garbage Collector will reach the particular house slot Servo1.write(90); // Opening the Bin so that person can pun in their Garbage delay(10000); // Waiting for the Person to put the Garbage Servo1.write(0); // Closing the Bin u_turn(); // Calling the function u_turn() in which the garbage collector will take u turn based on IR Sensors count=0; // Resetting the Value of Count reach_home(slot_no); // Call the reach_home function so that the garbage collector can return to its Base station count=0; // Again resetting the value of count u_turn_right(); // Again taking u turn by turning right. IR_Status=digitalRead(IRBin); // Checking the status of the Bin. If IR_Status is true, that means bin is full if(!IR_Status) // If IR_Status is false i.e. there is space available for more garbage { Bin_Status="Available"; // Update the Bin_Status as Available } else if(IR_Status) // If IR_Status is tue i.e. there is no space available for more garbage { // Bin Status updated that no more garbage can be taken Bin_Status="Full!! Not Available for Service!! Sorry for the Inconvinience Caused"; } } // end of if condition else // If house slot is something else than 1, 2,3 or 4, then Garbage Cleaner will not visit any house and check the status of bin { Servo1.write(0); // Closing the Bin IR_Status=digitalRead(IRBin); // Reading the Status of the Bin. If IR_Status is true, that means bin is full if(!IR_Status) // If IR_Status is false i.e. there is space available for more garbage { Bin_Status="Available"; // Update the Bin_Status as Available } else if(IR_Status) // If IR_Status is tue i.e. there is no space available for more garbage { // Bin Status updated that no more garbage can be taken Bin_Status="Full!! Not Available for Service!! Sorry for the Inconvinience Caused"; } } // End of else condition } // End of Function void reach_home(int h_no) // Declaring the function reach_home() which will have an input Parameter that is the slot number we want the collector to reach { while(count