How to use the W5100 Ethernet Shield with Arduino

How to use the Ethernet Shield with Arduino

Ethernet Shield for Arduino

 

INTRODUCTION

The Ethernet Shield allows the Arduino board with the internet and sends data to a webserver online. The Arduino shield we use is compatible with all Arduino boards and is based on the Wiznet W5100 Ethernet chip. There is a slot available for an SD card on Ethernet Shield which can be used to store files from the network.

APPLICATIONS

  • Monitor data online: Ethernet Shield allow you to monitor the data of your peripherals connected with Arduino over the network.
  • Control Equipment’s Online: Ethernet shield allow one to control the peripherals connected with Arduino. One can switch on and off the electric motors in a room while being away.
  • Connect System to the Internet: In today’s era, the technology is moving toward the Internet of Things (IoT). It is necessary to build a connection between the internet and the peripherals we are using.
  • Use in the automation industry: Ethernet shield plays a vital role in the automation industry. We can monitor and control the equipment and our motors from the our smartphones anywhere.

WIRING DIAGRAM

(Courtesy: https://alselectro.wordpress.com/tag/ethernet-shield/)

Ethernet Shield Arduino Connection

 

Ethernet Shield Arduino Connection

The required pins are already connected when you insert the Ethernet shield on top of your Arduino-compatible UNO board.

 

CODE

 

#include <SPI.h> 
#include <Ethernet.h> 
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(169, 254, 237, 252);
EthernetServer server(80); 

void setup() {
 
Serial.begin(9600); while (!Serial) {
;
}
Serial.println("Ethernet WebServer Example"); 
Ethernet.begin(mac, ip);
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); 
while (true) {
delay(1);
}
}
if (Ethernet.linkStatus() == LinkOFF) 
{ 
  Serial.println("Ethernet cable is not connected.");
}
server.begin(); 
Serial.print("server is at "); 
Serial.println(Ethernet.localIP());
}

void loop() {
// listen for incoming clients EthernetClient client = server.available(); 
if (client) {
Serial.println("new client");
// an http request ends with a blank line bool currentLineIsBlank = true;
while (client.connected()) 
{ 
if (client.available()) 
{
client.println("<!DOCTYPE html>"); 
client.println("<html>"); 
client.println("<body>"); 
client.println("<h1>Hello World!!!!</h1>");
client.println("<h2>ETHERNET SHIELD is Connected</h2>"); 
client.println("</body>");
client.println("</html>"); 
break;
client.stop();
}}}}