---
title: "이더넷쉴드2를 사용해 인터넷에 접속해 보자"
url: "https://maker.wiznet.io/WIZnet/projects/%EC%9D%B4%EB%8D%94%EB%84%B7%EC%89%B4%EB%93%9C2%EB%A5%BC-%EC%82%AC%EC%9A%A9%ED%95%B4-%EC%9D%B8%ED%84%B0%EB%84%B7%EC%97%90-%EC%A0%91%EC%86%8D%ED%95%B4-%EB%B3%B4%EC%9E%90/"
markdown_url: "https://maker.wiznet.io/WIZnet/projects/%EC%9D%B4%EB%8D%94%EB%84%B7%EC%89%B4%EB%93%9C2%EB%A5%BC-%EC%82%AC%EC%9A%A9%ED%95%B4-%EC%9D%B8%ED%84%B0%EB%84%B7%EC%97%90-%EC%A0%91%EC%86%8D%ED%95%B4-%EB%B3%B4%EC%9E%90/md"
type: "UCC: User Created Content"
author: "WIZnet"
original_url: "https://m.blog.naver.com/PostView.nhn?blogId=zeta0807&logNo=221204135710&proxyReferer=https:%2F%2Fwww.google.com%2F"
published: "2023-02-07"
language: "ko"
hardware: ["Arduino Ethernet Shield 2", "Arduino UNO", "Arduino Mega 2560"]
likes: 1
views: 415
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# 이더넷쉴드2를 사용해 인터넷에 접속해 보자

> 이더넷쉴드2를 사용해 인터넷에 접속해보자

Original source: https://m.blog.naver.com/PostView.nhn?blogId=zeta0807&logNo=221204135710&proxyReferer=https:%2F%2Fwww.google.com%2F

## Components

- **Arduino Ethernet Shield 2** x 1 ([docs](https://docs.arduino.cc/hardware/ethernet-shield-rev2))
- **Arduino UNO** x 1 ([docs](https://www.farnell.com/datasheets/1682209.pdf))
- **Arduino Mega 2560** x 1 ([docs](https://www.farnell.com/datasheets/1674878.pdf?_ga=2.12759806.871556650.1519619484-654667508.1508905608&_gac=1.209399078.1518779130.EAIaIQobChMI97my66Sq2QIV77ftCh01kgA_EAMYASAAEgKPyvD_BwE))
- Software: **Arduino IDE** ([docs](https://www.arduino.cc/en/software))

## Article

1. 준비물

아두이노 메가 2560 또는 아두이노 우노 R3

위즈넷 이더넷 실드2

네트워크 케이블

공유기

![](https://mblogthumb-phinf.pstatic.net/MjAxODAyMDhfNjgg/MDAxNTE4MDQ0ODA5OTAx.uKx49YQB1-LeM0bbevIBoGSBemB4y9pdNv2FCiG4xIwg.8SvP759zsr3gCrP6bi-3eaTlFRzXJ85y_YP5fNH_9uAg.JPEG.zeta0807/1518044699356.jpg?type=w800)

위즈넷에서 만든 실드 2

2. 하드웨어 연결

2.1 아두이노 메가 2560

쉘드 중간에 있는 SPI 6핀이 아두이노와 연결되면 제대로 연결한 것이다.

![](https://mblogthumb-phinf.pstatic.net/MjAxODAyMDhfMTM4/MDAxNTE4MDQ0ODEwNzEx.ZAIyghQxHSDhWJAyZauC1qGfBRDfDMED4XNJAJpCxjUg.cpuQNrqEq_M4nBbyvy0WGruBQwPKxOBI8oXsjfoyt7cg.JPEG.zeta0807/1518044751926.jpg?type=w800)

아두이노 메가에 장착

아래 사진에 잘 보이는지 모르겠지만 왼쪽 두 핀이 아두이노에 접촉되지 않고 남는다.

![](https://mblogthumb-phinf.pstatic.net/MjAxODAyMDhfMjQ5/MDAxNTE4MDQ0ODExNzYy.Q8a9yG73JalN5KrTOA037XiwAAccM4nU92F7c6Fu07Qg.C44PmHM-ML1af3fH64dTLj6uB0EPNkqWASwRREDYyQAg.JPEG.zeta0807/1518044773904.jpg?type=w800)

반대편도 마찬가지로 두 핀이 남는다.

![](https://mblogthumb-phinf.pstatic.net/MjAxODAyMDhfMjY2/MDAxNTE4MDQ0ODEyNzAy.MXF4b_WGzdhBBsk40tiW-w58epAQgcQeQZFjNeJrfcsg.9RQzIwUtHf5vRlJ-mym6-QkKgGXRWvF_GK2Dpv4ho_Eg.JPEG.zeta0807/1518044789778.jpg?type=w800)

아두이노 메가 2560 R3과 연결하면 핀이 남지 않을 것이다. 왜냐하면 R3는 아래, 위에 핀이 두 개씩 더 있기 때문이다.

​

아래 사진이 현재 정품 이더넷 실드 2이다. 역시 두 핀씩 많은 게 보인다. SCL, SDA, RESERVED, RESERVED 오로카에서 구매한 것은 SCL, SDA, IOREF, RESERVED 라서 한 핀이 다르다.

<https://store.arduino.cc/usa/arduino-ethernet-shield-2>

2.2 아두이노 우노 R3

쉘드 중간에 있는 SPI 6핀이 아두이노와 연결되면 제대로 연결한 것이다.

![](https://mblogthumb-phinf.pstatic.net/MjAyMDA2MjBfNDMg/MDAxNTkyNjMyNjcyNDIx.5GGupy6K_8xWZWo_O5JjOANylKBV4H-bBzlPlGHGZQIg.SQW69rXW_Wg_GPmFWvX2Fts2KdmEqc4trz3qnQGgziAg.JPEG.zeta0807/SE-da96ab89-054b-4c01-921c-e0675ad07df8.jpg?type=w800)

우노가 R3 버전이라 쉴드2 핀이 꼭 맞다.

![](https://mblogthumb-phinf.pstatic.net/MjAyMDA2MjBfMjI4/MDAxNTkyNjMyNjM1OTIx.3VGyYDcv5hgq183ae6skbeDO3SWGYQAALoItsq_L26kg.MWWAp0I65mYquV6_VeV9gw-p-Ebq1T4xhzkw8vsLI4Ag.JPEG.zeta0807/SE-879fe92c-bdd0-4261-bacf-fc009c42b7ab.jpg?type=w800)

우노가 R3 버전이라 쉴드2 핀이 꼭 맞다.

![](https://mblogthumb-phinf.pstatic.net/MjAyMDA2MjBfOTIg/MDAxNTkyNjMyNjk5OTQ1.ZuhTFQCsZGV9eApJryii3DJi5fcmrx1x-V7fhCMSBh0g.Jp9-Gk-72OlRW83Ym613t7dds8FEJHd-LOXShf3BXQEg.JPEG.zeta0807/SE-b9f7b62b-aa35-4939-8cd2-71a2cb9d4d2a.jpg?type=w800)

![](https://mblogthumb-phinf.pstatic.net/MjAyMDA2MjBfNjYg/MDAxNTkyNjMyNjE5MjI0.oR6PPISkUlqaZnFv-H1wZ9BM3Ze7K_-DVzzdz-v5p14g.UCWa7CJSehI0YNqa0EcZAttdZK1aZfXFTn1OiuCbLy8g.JPEG.zeta0807/SE-98846c05-48f7-48a5-b925-7443eb8fe0b9.jpg?type=w800)

3. 아두이노 코드

기존 Webserver 코드에서 아래만 변경했다.

#include &lt;Ethernet.h> –> #include &lt;Ethernet2.h>

* Static IP Web Server */ #include &lt;SPI.h> #include &lt;Ethernet2.h> //#include &lt;Ethernet.h> // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network: byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192, 168, 35, 100); // Initialize the Ethernet server library // with the IP address and port you want to use // (port 80 is default for HTTP): EthernetServer server(80); void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); Serial.println(“Static IP Web Server”); // start the Ethernet connection and the server: Ethernet.begin(mac, ip); 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 boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); Serial.write(c); // if you’ve gotten to the end of the line (received a newline // character) and the line is blank, the http request has ended, // so you can send a reply if (c == ‘n’ && currentLineIsBlank) { // send a standard http response header client.println(“HTTP/1.1 200 OK”); client.println(“Content-Type: text/html”); client.println(“Connection: close”); // the connection will be closed after completion of the response client.println(“Refresh: 5”); // refresh the page automatically every 5 sec client.println(); client.println(“&lt;!DOCTYPE HTML>”); client.println(“&lt;html>”); // output the value of each analog input pin for (int analogChannel = 0; analogChannel &lt; 6; analogChannel++) { int sensorReading = analogRead(analogChannel); client.print(“analog input “); client.print(analogChannel); client.print(” is “); client.print(sensorReading); client.println(“&lt;br />”); } client.println(“&lt;/html>”); break; } if (c == ‘n’) { // you’re starting a new line currentLineIsBlank = true; } else if (c != ‘r’) { // you’ve gotten a character on the current line currentLineIsBlank = false; } } } // give the web browser time to receive the data delay(1); // close the connection: client.stop(); Serial.println(“client disconnected”); } }

4. 실험결과

![](https://mblogthumb-phinf.pstatic.net/MjAxODAyMDdfMTA3/MDAxNTE4MDA4MTY1NjIx.RKUo3fd2nXzMd1Lg6G9yDGPHwb25HxiyEIQpaGWPcZwg.8qISho5kG87dA2rlV1yaEXOXEetq1RgiWlTPT-1j6g8g.PNG.zeta0807/ether2.serial.png?type=w800)

클라언트 접속 시 시리얼 모니터

![](https://mblogthumb-phinf.pstatic.net/MjAxODAyMDdfMjI1/MDAxNTE4MDA4MTc3MDAz.g1kYOzUet_whCcUobQASNghXO03eO35xRw35zA2iOiog.7znAtH60ClP31dhiVRkA8u8G-LjwjgX9pWFhoPX2l8kg.PNG.zeta0807/ether2.browser.png?type=w800)

웹 서버

아주 쉽게 동작해서 좋다.

---

Source: https://maker.wiznet.io/WIZnet/projects/%EC%9D%B4%EB%8D%94%EB%84%B7%EC%89%B4%EB%93%9C2%EB%A5%BC-%EC%82%AC%EC%9A%A9%ED%95%B4-%EC%9D%B8%ED%84%B0%EB%84%B7%EC%97%90-%EC%A0%91%EC%86%8D%ED%95%B4-%EB%B3%B4%EC%9E%90/
