---
title: "Connecting Arduino to the Internet with the W5100 Ethernet module"
url: "https://maker.wiznet.io/teju/projects/connecting-arduino-to-the-internet-with-the-w5100-ethernet-module/"
markdown_url: "https://maker.wiznet.io/teju/projects/connecting-arduino-to-the-internet-with-the-w5100-ethernet-module/md"
type: "UCC: User Created Content"
author: "Mohammad Rahimi"
author_url: "https://irenx.ir/arduino/connect-arduino-internet-w5100-ethernet-module/"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "Mohammad Rahimi"
original_url: "https://irenx.ir/arduino/connect-arduino-internet-w5100-ethernet-module/"
published: "2022-10-31"
language: "en"
hardware: ["WIZnet W5100"]
likes: 3
views: 960
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# Connecting Arduino to the Internet with the W5100 Ethernet module

> IoT devices are connected to the Internet using Wi-Fi. Although a Wi-Fi connection enables remote access to the Internet, it has its own l

Original author: Mohammad Rahimi (source: https://irenx.ir/arduino/connect-arduino-internet-w5100-ethernet-module/)

## Components

- **WIZnet W5100** x 1 ([docs](https://docs.wiznet.io/Product/Chip/Ethernet/W5100))

## Article

the Internet, it has its own limitations. For example, in most industrial applications for a fixed device, Ethernet is usually chosen over Wi-Fi, because it is more reliable and secure. Also, since Ethernet is a wired connection, it offers better speed and lower latency. If you are working with an Arduino UNO or Nano board and want to connect your Arduino to the Internet, you have two popular options. One option is to use ESP8266 with Arduino and the second option is to connect [Ethernet module with Arduino](https://irenx.ir/arduino/arduino-ethernet/) .

In this project, we want to use the second option to control an LED with Arduino and W5100 Ethernet Module. The Ethernet module is used to communicate between the computer and the Arduino in a LAN or Wired network.

Video display

[Embedded media](https://irenx.ir/wp-content/uploads/2021/07/%D8%A7%D8%AA%D8%B5%D8%A7%D9%84-%D8%A2%D8%B1%D8%AF%D9%88%DB%8C%D9%86%D9%88-%D8%A8%D9%87-%D8%A7%DB%8C%D9%86%D8%AA%D8%B1%D9%86%D8%AA-%D8%A8%D8%A7-%D9%85%D8%A7%DA%98%D9%88%D9%84-%D8%A7%D8%AA%D8%B1%D9%86%D8%AA-W5100.mp4?_=1)

00:27

00:39

## Ethernet module W5100

We use W5100 Ethernet module. Simply put, this module enables the Arduino board to connect to the Internet. Using this module, we can complete the Internet connection without the support of an operating system. It also supports Hardwired TCP/IP protocols such as TCP, PPPoE, Ethernet, UDP, ICMP, IPv4, etc. It supports duplex and half-duplex operation modes. Supports ADSL connections and up to four simultaneous socket connections.

![Ethernet module W5100](https://irenx.ir/wp-content/uploads/2021/07/W5100-Ethernet-Module.jpg)

[**Arduino training** course](https://irenx.ir/arduino-course/)[**STM32 training** course](https://irenx.ir/stm32-course/)

[**AVR training** course](https://irenx.ir/avr-course/)[**Raspberry Pi training** course](https://irenx.ir/raspberry-pi-course/)

[**Altium Designer training** course](https://irenx.ir/altium-designer-course/)[**Proteus training** course](https://irenx.ir/proteus-course/)

[**Electronic training** course](https://irenx.ir/electronic-course/)[**Internet of Things training** course](https://irenx.ir/iot-course/)

The Ethernet module uses the Arduino Ethernet library to write codes that connect to the Internet using this module. Compatible with all Arduino versions such as UNO, NANO, mega 1280, mega 2560 and other versions. The functionality and performance of the W5100 Ethernet module is very similar to the Arduino Ethernet Shield, and its price is much lower.

![Connecting the cable to the W5100 Ethernet module](https://irenx.ir/wp-content/uploads/2021/07/Arduino-Ethernet-Shield.jpg)

## Arduino connection circuit schematic to W5100 Ethernet module

![Arduino connection circuit schematic to W5100 Ethernet module](https://irenx.ir/wp-content/uploads/2021/07/%D8%B4%D9%85%D8%A7%D8%AA%DB%8C%DA%A9-%D9%85%D8%AF%D8%A7%D8%B1-%D8%A7%D8%AA%D8%B5%D8%A7%D9%84-%D8%A2%D8%B1%D8%AF%D9%88%DB%8C%D9%86%D9%88-%D8%A8%D9%87-%D9%85%D8%A7%DA%98%D9%88%D9%84-%D8%A7%D8%AA%D8%B1%D9%86%D8%AA-W5100.jpg)
This circuit consists of [Arduino Nano](https://irenx.ir/arduino/arduino-nano/) and Ethernet Module W5100 (this project is also possible with Ethernet Arduino Shield and Arduino UNO). The connection between the Arduino module and Ethernet is very simple as shown in the circuit diagram.

Connect the Arduino Nano's 5V and GND pins to +5 and G of the Ethernet module, respectively (these connections provide power to the Ethernet module).
Connect Arduino pins 9, 10, 11,12 and 13 to R, SS, MO, MI, CK respectively of the Ethernet module (this establishes communication between Arduino and Ethernet via [SPI](https://irenx.ir/electronic/spi-communication/) ).

Suggested article: [**Arduino and Raspberry Pi radio communication training with nRF24L01**](https://irenx.ir/arduino/wireless-rf-communication-arduino-raspberry-pi/)

## Arduino Code to receive data from W5100 Ethernet Module

The complete code of the project is placed at the end of the page in the downloadable file. Here we review the important parts of the code. First, we call the SPI library, which is used to communicate SPI with the Ethernet module.

```
#include <SPI.h>
```

The Ethernet library has functions that simplify the interaction with the Ethernet module.

```
#include <Ethernet.h>
```

We set the physical Mac address of the Ethernet module.

```
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
```

The number 192.168.0.12 is the IP address. To check the IP address, just type ipconfig in CMD.

![Get IP with ipconfig](https://irenx.ir/wp-content/uploads/2021/07/W5100-Ethernet-Module-Code.jpg)

The code creates a local server on port 80 that can later be accessed by clients.

```
EthernetServer server(80);
```

It reads the user response when the user accesses the web server.

If you have any questions about this article, ask in the comments section

```
String readString;
```

In the setup, we set the LED pin as the output and configure the Ethernet module with the desired parameters (Mac address, IP address, gateway, subnet mask) and finally the "server.begin()" function of the server starts.

```
int ledPin = 2;
void setup(){
                        pinMode(ledPin, OUTPUT);
                        Ethernet.begin(mac, ip, gateway, subnet);
            server.begin();
}
```

In the void loop, we create a client connection and check if someone is trying to access the assigned IP address through a browser.

```
void loop(){
    EthernetClient client = server.available();
              if (client) {
                   while (client. connected()) {
                       if (client.available()) {
```

In case of connection, checking whether the client sends a message to the server or not.

```
char c = client.read();
```

Then we request the HTTP response character by character and store the characters in the readString variable defined by the user.

```
if (readString.length() < 100) {
                    readString += c;
                }
```

After receiving the confirmation response, we start displaying the web page and the HTML code is below.

```
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<TITLE> ARDUINO ETHERNET</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<hr>");
client.println("<H1 style=\"color:green;text-align:center\">ARDUINO ETHERNET LED CONTROL</H1>");
client.println("<hr>");
client.println("<br>");
```

When the user clicks on the TURN ON LED link, he is redirected to \?LEDON, which turns on the LED.

```
client.println("<H2 style=\"text-align:center\"><a href=\"/?LEDON\"\">Turn On LED</a><br></H2>");
```

Similar to the above code, the following code directs the user to the TURN OFF LED address.

```
client.println("<H2 style=\"text-align:center\"><a href=\"/?LEDOFF\"\">Turn Off LED</a><br></H2>");
```

Depending on the address the user is directed to, control the Arduino pin to turn the LED on and off.

```
                    if(readString.indexOf("?LEDON") > -1)
                    {
                        digitalWrite(ledPin, HIGH);
                    }
                    else{
                        if(readString.indexOf("?LEDOFF") > -1)
                        {
                            digitalWrite(ledPin, LOW);
                        }
                    }
```

Clear string for next read:

```
                    readString="";
                }
            }
        }
    }
}
```

## Connect Arduino to computer or Ethernet port

To connect these two (PC and Arduino) to each other, if the Ethernet port of the computer does not have auto-direction sensing, we need a suitable cable (CAT-6 crossover cable). If your PC supports auto-direction sensing, just connect a regular cable that comes with the router.

![Connect Arduino to computer or Ethernet port](https://irenx.ir/wp-content/uploads/2021/07/CAT-6-Crossover-Cable.jpg)

If your computer does not have an Ethernet port, you can use the following method to connect.

![Connecting an Ethernet module without an Ethernet port](https://irenx.ir/wp-content/uploads/2021/07/Connect-the-Ethernet-Module-to-Router-LAN-Network-Port.jpg)

## LED flashing over the Internet using an Ethernet module

After making the above connections, connect to the router using your PC or mobile phone. Then open the web browser and enter the IP address. Now you can control the LED through the web page. When the user clicks on “TURN ON LED” on the web page, the LED in the circuit turns on. When “LED TURN OFF” is clicked, the LED in the circuit will turn off. The web page is as follows:

Suggested article: [**download black theme for Arduino software (dark skin)**](https://irenx.ir/arduino/black-theme-for-arduino/)

![LED flashing over the Internet using an Ethernet module](https://irenx.ir/wp-content/uploads/2021/07/Arduino-Ethernet-LED-Control.jpg)

I hope you enjoyed this project and learned how to use the W5100 Ethernet module with Arduino to send and receive data over the Interne

---

Source: https://maker.wiznet.io/teju/projects/connecting-arduino-to-the-internet-with-the-w5100-ethernet-module/
