🔌 Working with the Internet on the example of Arduino Ethernet shield W5100

Ethernet Shield makes it easy to connect your Arduino board to a local network or the Internet. It provides the ability of the Arduino to send and receive data from anywhere in the world using an Internet connection. For example, you can implement remote control of your actuators connected to the relay through a website or create a device that will notify you of a new e-mail with a sound signal.
29-1a

In this experiment, we will show how our Arduino board can access the Internet using the Ethernet shield module W5100.

Required components:
• Arduino UNO or MEGA;
• Breadboard;
• Ethernet shield W5100 module;
• LED – 2 pcs .;
• 220 Ohm resistor – 2 pcs .;
• wires.

Ethernet Shield makes it easy to connect your Arduino board to a local network or the Internet. It provides the ability of the Arduino to send and receive data from anywhere in the world using an Internet connection. For example, you can implement remote control of your actuators connected to the relay through a website or create a device that will notify you of a new e-mail with a sound signal.
In the first part of the experiment, we will consider using an Arduino board with an Ethernet Shield connected as a server, issuing a web page to the client (browser) and allowing the browser to change the states of the LED connected to the Arduino.
We connect to the Arduino Ethernet shield and to the terminals D7, D8 – LEDs through a 220 Ohm resistor

When writing a sketch, use the Ethernet library built into the Arduino IDE.

#include 
#include 
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,7);
EthernetServer server(80);
int pins[] = { 7, 8};
int pinState[] = {0, 0}; 
String getData="";
boolean startGet=false;
void setup()
{
Serial.begin(9600);
for(int i=0;i<2;i++)
{
pinMode(pins[i],OUTPUT); 
digitalWrite(i,LOW);
}
Ethernet.begin(mac, ip);
server.begin();
}
void loop()
{
EthernetClient client = server.available();
if (client)
{
boolean currentLineIsBlank = true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
if(startGet==true) 
getData+=c;
if(c == '?') 
startGet=true;
if (c == 'n' && currentLineIsBlank) 
{
if(getData.length()<1)
{
pinState[0]=0;
pinState[1]=0;
}
else
{
pinState[0]=int(getData[5])-48;
pinState[1]=int(getData[12])-48;
}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
client.println("");
client.println("");
client.println("

Ethernet shield + LEDS

"
); client.println(""); client.print("
"); client.print("led1 off<input type='radio' name='led1' value=0 onclick='document.getElementById("submit").click();' "); if (pinState[0] == 0) client.print("checked"); client.println(">"); client.print("<input type='radio' name='led1' value=1 onclick='document.getElementById("submit").click();' "); if (pinState[0] == 1) client.print("checked"); client.println("> on"); client.println("
"
); client.print("
"); client.print("led2 off<input type='radio' name='led2' value=0 onclick='document.getElementById("submit").click();' "); if (pinState[1] == 0) client.print("checked"); client.println(">"); client.print("<input type='radio' name='led2' value=1 onclick='document.getElementById("submit").click();' "); if (pinState[1] == 1) client.print("checked"); client.println("> on"); client.println("
"
); client.println(""); client.println(""); client.println(""); break; } if (c == 'n') {currentLineIsBlank = true;} else if (c != 'r') {currentLineIsBlank = false;} } } } delay(1); client.stop(); for(int i=0;i<2;i++) {digitalWrite(pins[i],pinState[i]);} startGet=false; getData=""; }

Connection order:
1. Connect the Ethernet shield to the Arduino board, connect the Ethernet shield to the network using an RJ45 cable.
2. We connect LEDs according to the scheme
3. We load a sketch into the Arduino board.
4. Open the browser on any computer of this network and in the address bar type http://192.168.0.214 (the address that you assign to Arduino in the sketch).
5. On the page (fig. 29.2), changing the status of the input radio elements, we see the change in the status of the LEDs connected to the Arduino board.

To run the shield on the W5500, you will need to install the Ethernet2 library (https://www.arduino.cc/en/Reference/Ethernet).

Share on facebook
Facebook
Share on google
Google+
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on pinterest
Pinterest