Senin, 30 Oktober 2017

Arduino Ethernet

KONTROL LED BERBASIS WEBSITE DENGAN ARDUINO + ETHERNET ENC28J60

https://boardinnovation.wordpress.com/2016/05/15/kontrol-led-berbasis-website-dengan-arduino-ethernet-enc28j60/
Hi Sobat BI,
Kehadiran IoT (Internet of Things) menuntut semua perangkat (devices) untuk bisa terkonek ke internet. Terdapat beberapa pilihan agar kita bisa terkonek ke internet jika dipandang dari Layer 1 OSI physical layer, yaitu wired dan wireless. Pada kesempatan ini, kami akan memberikan tutorial agar devices kita (Arduino) bisa terkonek ke jaringan secara wired atau kabel.

ALAT DAN KOMPONEN

  1. Arduino (dalam tutorial ini Mega)
  2. Ethernet Board ENC28J60
  3. Kabel Jumper
  4. Kabel RJ45

SKEMATIK

Skema Arduino + ENC28J60

ANTARMUKA

ENC28J60 Arduino UnoArduino Mega
VCC +5 Volt+5 Volt
GND GNDGND
SCK Pin 13Pin 52
SO (MISO) Pin 12Pin 50
SI (MOSI) Pin 11Pin 51
CS Pin 8Pin 53
Library

SOURCE CODE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <UIPEthernet.h>
EthernetServer server = EthernetServer(80);
 
//inisialisasi variable
int led = 13;
String readString;
boolean ledStatus = false;
 
void setup() {
  // put your setup code here, to run once:
  pinMode(led, OUTPUT);
  Serial.begin(9600);
 
  uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};
  IPAddress myIP(192,168,3,1);
 
  Ethernet.begin(mac,myIP);
 
  server.begin();
   
}
 
void loop() {
  if(ledStatus == true){
    digitalWrite(led, HIGH);
  }
  else{
     digitalWrite(led, LOW);
  }
   
  // 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("<HTML>");
           client.println("<HEAD>");
           client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
           client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
           client.println("<link rel='stylesheet' type='text/css' href='http://randomnerdtutorials.com/ethernetcss.css' />");
           client.println("<TITLE>BOARD INNOVATION</TITLE>");
           client.println("</HEAD>");
           client.println("<BODY>");
           client.println("<H1>BOARD INNOVATION LED Controller</H1>");
           client.println("<H2>LED STATUS</H2>");
           if(ledStatus==true){
            client.println("<H3>IT IS ON</H3>");
           }
           else{
            client.println("<H3>IT IS OFF</H3>");
           }
                               
           client.println("<br />");
           client.println("<br />");
           client.println("<H2>PANEL CONTROL</H2>");
           client.println("<a href=\"/?LEDon\"\">Turn On LED</a>");
           client.println("<a href=\"/?LEDoff\"\">Turn Off LED</a><br />");  
            
           client.println("<br />");
           client.println("<br />");
           client.println("<p>Modified by FARIZ ALEMUDA</p>"); 
           client.println("<br />");
           client.println("</BODY>");
           client.println("</HTML>");
      
           delay(1);
           //stopping client
           client.stop();
           //controls the Arduino if you press the buttons
           if (readString.indexOf("?LEDon") >0){
               ledStatus = true;
           }
           if (readString.indexOf("?LEDoff") >0){
               ledStatus = false;
           }
                           
            //clearing string for next read
            readString=""; 
            
         }
       }
    }
}
}

VIDEO TUTORIAL

Iklan