/* Created by Rui Santos Visit: http://randomnerdtutorials.com for more arduino projects Arduino with Ethernet Shield Modified 19 December 2016 by diytransistor http://www.instructables.com/member/diytransistor/ */ #include #include byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address byte ip[] = { 192, 168, 0, 178 }; // ip in lan (that's what you need to use in your browser. ("192.168.0.178") byte gateway[] = { 192, 168, 0, 1 }; // internet access via router byte subnet[] = { 255, 255, 255, 0 }; //subnet mask EthernetServer server(80); //server port String readString; int relay1 = 2; //relay1 on pin 2 void setup() { // Open serial communications Serial.begin(9600); pinMode(relay1, OUTPUT); // start the Ethernet connection and the server: Ethernet.begin(mac, ip, gateway, subnet); server.begin(); Serial.print("server is at "); Serial.println(Ethernet.localIP()); } void loop() { // Create a client connection EthernetClient client = server.available(); if (client) { while (client.connected()) { if (client.available()) { char c = client.read(); //read char by char HTTP request if (readString.length() < 100) { //store characters to string readString += c; //Serial.print(c); } //if HTTP request has ended if (c == '\n') { Serial.println(readString); //print to serial monitor for debuging client.println("HTTP/1.1 200 OK"); //send new page client.println("Content-Type: text/html"); client.println(); client.println(""); client.println(""); client.println(""); client.println(""); client.println(""); client.println("SMART Home Control"); client.println(""); client.println(""); client.println("

SMART Home Control

"); client.println("
"); client.println("
"); client.println("

Arduino Home Automation

"); client.println("
"); client.println("Turn On Lamp 1"); client.println("Turn Off Lamp 1
"); client.println("
"); client.println(""); client.println(""); delay(1); //stopping client client.stop(); //controls the Arduino if you press the buttons if (readString.indexOf("?lamp1on") >0){ digitalWrite(relay1, HIGH); } if (readString.indexOf("?lamp1off") >0){ digitalWrite(relay1, LOW); } //clearing string for next read readString=""; } } } } }