Translate

ARDUINO ETHERNET WEBSERVER TCP-IP MODULE ENC28J60 MONITORING ADC DAN KENDALI LED VIA BROWSER

ARDUINO ETHERNET WEBSERVER TCP-IP MODULE ENC28J60 MONITORING ADC DAN KENDALI LED VIA BROWSER


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa memonitoring ADC dan kendali LED dengan menggunakan browser via kabel LAN / modul tcp-ip ENC28J60. alat ini menggunakan arduino mega dan komunikasi dari arduino ke modul ENC28j60 menggunakan SPI (MOSI MISO SCK). untuk lebih jelasnya berikut adalah program dan daftar komponennya.




a. Arduino Mega




b. Modul ENC28J60






c. Program Arduino IDE

#include <SPI.h>
#include <UIPEthernet.h>

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,99);

EthernetServer server(80);

String readString;

void setup() {

  pinMode(13, OUTPUT);
  Serial.begin(9600);

   while (!Serial) {
  }

  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}

void loop() {
  int sumbux = analogRead(0);
  int sumbuy = analogRead(1);
  int sumbuz = analogRead(2);

  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
     if (readString.length() < 100) {

          //store characters to string
          readString += c;
          //Serial.print(c);
        }
        if (c == '\n' && currentLineIsBlank) {
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println("Refresh: 1");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println(" ");
          client.println("<title> Monitor Kemiringan </title> ");    
          client.println("<body bgcolor = #000000>");    
          client.println("<center>");
            client.println("<font color = yellow><center><h1>MONITOR KEMIRINGAN DATARAN<br>BY YANUAR MUKHAMMAD</h1></center><br></font>");
            client.println("<font color = #FFFFFF>");
            client.println("<h2>");
            client.println("Sumbu X = ");
            client.print(sumbux);
            client.println("<br />");
            client.println("Sumbu Y = ");
            client.print(sumbuy);
            client.println("<br />");
            client.println("Sumbu Z = ");
            client.print(sumbuz);
            client.println("</h2>");     
          client.println("</font>");
           client.println("<a href = \"/?lighton\"\"><input type = 'button' value = 'ON' ></a>");
          client.println("<a href = \"/?lightoff\"\"><input type = 'button' value = 'OFF' ></a> ");
          client.println("</center>");
          client.println("</body>");
          client.println("</html>");
           
          break;      
        }   
        if (c == '\n') {
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }
    }
    delay(1);
    client.stop();
    Serial.println("client disonnected");
  }
          if(readString.indexOf("?lighton") >0)
          {

            digitalWrite(13, HIGH);   
          }
          else{
          if(readString.indexOf("?lightoff") >0)
          {

                digitalWrite(13, LOW);
          }
          }
         readString="";



}




d. VIDEO HASILNYA









No comments:

Post a Comment