/* * Written By : Usman Ali Butt * Date : 12/23/2018 * Property off : www.microcontroller-project.com */ #include //Libraries required to communicate with the arduino ethernet shield #include int fan = 4; //Fan connected to pin#4 of arduino int pos = 0; byte mac[] = { 0xDE, 0xAD, 0xBE, 0x3F, 0xFE, 0xED }; //physical mac address byte ip[] = { 192,168,56,100 }; //ip in lan (that's what you need to use in your browser. ("192.168.56.100") //byte gateway[] = { 192, 168, 1, 1 }; // internet access via router //byte subnet[] = { 255, 255, 255, 0 }; //subnet mask EthernetServer server(80); //Server port String readString; //HTTP request read void setup() { // Open serial monitor and wait for port to open Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } pinMode(fan, OUTPUT); // Fan pin declared output // start the Ethernet connection and the server: Ethernet.begin(mac, ip); //Begin Ethernet shield server.begin(); //Start Server Serial.print("server is at "); Serial.println(Ethernet.localIP()); //Locate the IP assigned to arduino } void loop() { // Check for client request EthernetClient client = server.available(); if (client) { //If client request arrived read the request while (client.connected()) { if (client.available()) { char c = client.read(); if (readString.length() < 100) { readString += c; } // Server WEB PAGE if requested by user if (c == '\n') { Serial.println(readString); //html file client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(); client.println(""); client.println(""); client.println(""); client.println(""); client.println("Arduino Fan control switch"); client.println(""); client.println(""); client.println("

FAN Control

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

Fan control with arduino Ethenet shield

"); client.println("
"); //BUTTON FOR FIRST LED client.println("Turn On FAN"); client.println("Turn Off FAN
"); //SPACES client.println("
"); client.println("
"); client.println("
"); client.println(""); client.println(""); delay(1); //stopping client client.stop(); //Translate the user request and check to switch on or off the fan if (readString.indexOf("?button1on") >0){ digitalWrite(fan, HIGH); } if (readString.indexOf("?button1off") >0){ digitalWrite(fan, LOW); } //clearing string for next read readString=""; } } } } }