fbpx

Interface Ethernet With Arduino Uno

Ethernet is a family of computer networking technologies for local area networks (LANs) and metropolitan area networks.

Systems communicating over Ethernet divide a stream of data into shorter pieces called frames. Each frame contains source and destination addresses and error-checking data so that damaged data can be detected and re-transmitted. .

Ethernet ENC28J60

Arduino provide library to access the internet using enc28j60 with arduino.Download the Ethercard library from https://github.com/jcw/ethercard/blob/master/README.md.

Pinout

Hardware Required

  • Ethernet Enc28j60.
  • Arduino uno.

Circuit

Control Led using Ethernet

Arduino led is controlled using ethernet,here arduino act as server html page is loaded in arduino we can access that html page using our local ip of ethernet,when we enter that ip in browser html page will load.

Code

 #include <UIPClient.h>
 #include <UIPEthernet.h>
 #include <UIPServer.h>
 int pos = 0;
 byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
 byte ip[] = { 192, 168, 0, 103 };
 EthernetServer server(80);
 String readString;
 
 void setup()
 {
 Serial.begin(9600);
 while (!Serial)
 {
 ; // wait for serial port to connect. Needed for Leonardo only
 }
 pinMode(8,OUTPUT);
 Ethernet.begin(mac, ip);
 server.begin();
 Serial.print("server is at ");
 Serial.println(Ethernet.localIP());
 }
 
 void loop()
 {
 EthernetClient client = server.available();
 if (client)
 {
 while (client.connected())
 {
 if (client.available())
 {
 char c = client.read();
 if (readString.length() < 100)
 {
 readString += c;
 }
 if (c == '\n')
 {
 Serial.println(readString);
 delay(1);
 client.println("HTTP/1.1 200 OK");
 client.println("Content-Type: text/html");
 client.println();
 client.println("");
 client.println("<HTML>");
 client.println("<HEAD>");
 client.println(" <TITLE>LED CONTROL</TITLE>");
 client.println("</HEAD>");
 client.println("<BODY>");
 client.println("<H1>GKG </H1>");
 client.println("<hr />");
 client.println("<br /> ");
 client.println("<H2>LED CONTROL</H2>");
 client.println("<br /> ");
 client.println("<p>LED 1</p>");
 client.println("<a href=\"/a\"\"> ON </a>");
 client.println("<a href=\"/a1\"\"> OFF</a><br /> ");
 client.println("<br />");
 client.println("<br />");
 client.println("</BODY>");
 client.println("</HTML>");
 client.stop();
 if (readString.indexOf("a") >0)
 {
 digitalWrite(2, HIGH);
 }
 if (readString.indexOf("a1") >0)
 {
 digitalWrite(2,  LOW);
 }
 readString="";
 }
 }
 }
 }
 } 

1 comment on “Interface Ethernet With Arduino Uno

Leave a Reply

Your email address will not be published. Required fields are marked *