#include // Add 'SPI' library #include // Add 'Ethernet' library // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network: // 'mac' stores the MAC Address of your device byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; IPAddress ip(192, 168, 1, 177);//Assign custom IP address to 'ip' // Initialize the Ethernet server library // with the IP address and port you want to use // (port 80 is default for HTTP): EthernetServer server(80); float sensor=A0;//configure sensor value at analog pin A0 whose data type is Float float gas_value;// the value is getting stored in gas_value and its datatype is Float int sensor_value=0;// initialize sensor_value to '0' int Flame;// the value is getting stored in Flame and its datatype is int void setup() { // Open serial communications and wait for port to open: Serial.begin(9600);// Initialize Serial communication at 9600 baudrate // start the Ethernet connection and the server: Ethernet.begin(mac, ip); server.begin(); Serial.print("server is at ");// Displays 'server is at' Serial.println(Ethernet.localIP());// Displays server IP address pinMode(3, INPUT);//configure pin 3 of arduino as input pinMode (2,INPUT);//configure pin 3 of arduino as input pinMode(sensor,INPUT);//configure analog pin A0 as input } void loop() { // listen for incoming clients sensor_value = digitalRead(2);// store the PIR value in sensor_value Flame = digitalRead(3);//store the value of flame sensor in Flame gas_value=analogRead(sensor);// store the value of Gas sensor in gas_value //delay(500); EthernetClient client = server.available();//Assign incoming client to 'client' if (client) {// Checks if 'client' is true Serial.println("new client");// Prints 'new client' on Serial Monitor // an http request ends with a blank line boolean currentLineIsBlank = true;// Set 'currentLineIsBlank' as true while (client.connected()) {// Checks if the 'client' is connected if (client.available()) {// Checks if the 'client' is available char c = client.read();// Stores a character from the incoming client data // prints 'c' on the Serial Monitor Serial.write(c); // if you've gotten to the end of the line (received a newline // character) and the line is blank, the http request has ended, // so you can send a reply if (c == '\n' && currentLineIsBlank) { //Everything written in the 'client.println();' will be considered as HTML code // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html");//Defines the content type as text/html client.println("Connection: close"); // the connection will be closed after completion of the response client.println("Refresh: 3"); // refresh the page automatically every 5 sec client.println(); client.println(""); client.println(""); // output the value of each analog input pin check(client); client.println(""); break; } if (c == '\n') {// Checks if the incoming character is a newline // you're starting a new line currentLineIsBlank = true;// Sets the 'currentLineIsBlank' as true } else if (c != '\r') {// Checks if 'c' is not 'carriage return' // you've gotten a character on the current line currentLineIsBlank = false;// Sets 'currentLineIsBlank' as false } } } // give the web browser time to receive the data delay(1);//provides delay '1' milli second // close the connection: client.stop();//stops and disconnects the client Serial.println("client disconnected");// Display 'client is disconnected' } } void check(EthernetClient client ){//function to check whether client is available or not if (sensor_value==1)//if Sensor_value is equal to 1(it will show 1 when motion is detected) { client.println("Unknown Person Detected
");// Prints 'unknown person detected' on Serial Monitor // client.print(""); //Serial.println(sensor_value); // Serial.println(digitalRead(2)); //delay(100); } else if(sensor_value==0)//else if Sensor_value is equal to 0(it will show 0 when motion is not detected) { client.println("No detection
");// Prints 'No detection' on Serial Monitor client.print(""); // Serial.println(sensor_value); //Serial.println(digitalRead(2)); //delay(100); } if (Flame)//if Flame is their { client.println("fire detected
");// Prints 'fire detected' on Serial Monitor //delay(100); } else// else no fire { client.println("No fire
");// Prints 'No Fire' on Serial Monitor //delay(100); } if(gas_value<=450 )// if gas_value is less then equal to 450 { client.println("No gas leakage");// Prints 'No gas leakage' on Serial Monitor //Serial.println(gas_value); //delay(100); } else if(gas_value>500)//if gas_value is greater then 500 { client.println("Gas leakage");// Prints 'Gas leakage' on Serial Monitor //Serial.println(gas_value); //delay(100); }}