---
title: "Arduino Web Server with Webpage Stored on SD Card"
url: "https://maker.wiznet.io/teju/projects/Arduino-Web-Server-with-Webpage-Stored-on-SD-Card/"
markdown_url: "https://maker.wiznet.io/teju/projects/Arduino-Web-Server-with-Webpage-Stored-on-SD-Card/md"
type: "UCC: User Created Content"
author: "teju"
author_url: "https://maker.wiznet.io/teju/"
original_author: "teju"
original_url: "https://akuzechie.blogspot.com/2021/09/arduino-web-server-with-webpage-stored.html"
published: "2022-02-26"
language: "en"
hardware: ["Arduino Ethernet Shield", "Arduino UNO"]
likes: 0
views: 243
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# Arduino Web Server with Webpage Stored on SD Card

> Arduino Web Server with Webpage Stored on SD Card

Original author: teju (source: https://akuzechie.blogspot.com/2021/09/arduino-web-server-with-webpage-stored.html)

## Components

- **Arduino Ethernet Shield** x 1 ([docs](https://docs.arduino.cc/retired/shields/arduino-ethernet-shield-without-poe-module))
- **Arduino UNO** x 1 ([docs](https://www.farnell.com/datasheets/1682209.pdf))

## Article

**C++ sketch:**

//------------------------------------------------

//Arduino Web Server via Ethernet Shield & SD Card

//------------------------------------------------

#include &lt;SPI.h>

#include &lt;Ethernet.h>

#include &lt;SD.h>

//------------------------------------------------

byte mac[] = {0x90, 0xA2, 0xDA, 0x00, 0x4A, 0xE0};

EthernetServer server(80);

//------------------------------------------------

File HMTL_file;

//=================================================================

void setup()

{

? Serial.begin(9600);

? //---------------------------------------------------------

? Serial.println("Initializing SD card...");

? if(!SD.begin(4))

? {

? ? Serial.println("SD card initialization failed!");

? ? return;

? }

? Serial.println("SD card initialized.");

? //---------------------------------------------------------

? if(!SD.exists("webpage.htm"))

? {

? ? Serial.println("webpage.htm file not found!");

? ? return;

? }

? Serial.println("webpage.htm file found");

? //---------------------------------------------------------

? Ethernet.begin(mac);

? server.begin();

? Serial.print("Server Started...nLocal IP: ");

? Serial.println(Ethernet.localIP());

}

//=================================================================

void loop()

{

? EthernetClient client = server.available();

? if(client)

? {

? ? boolean currentLineIsBlank = true;

? ? while(client.connected())

? ? {

? ? ? if(client.available())

? ? ? {

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

? ? ? ? if(c == 'n' && currentLineIsBlank)

? ? ? ? {

? ? ? ? ? //send HTTP response header to client

? ? ? ? ? client.println("HTTP/1.1 200 OKnrContent-Type: text/htmlnrnr");

? ? ? ? ? //-------------------------------------------------------------------

? ? ? ? ? //send HTTP file to client

? ? ? ? ? HMTL_file = SD.open("webpage.htm");

? ? ? ? ? if(HMTL_file)

? ? ? ? ? {

? ? ? ? ? ? while(HMTL_file.available()) client.write(HMTL_file.read());

? ? ? ? ? ? HMTL_file.close();

? ? ? ? ? }

? ? ? ? ? break;

? ? ? ? }

? ? ? ? //---------------------------------------------------------------------

? ? ? ? if (c == 'n') currentLineIsBlank = true;

? ? ? ? else if(c != 'r') currentLineIsBlank = false;

? ? ? }

? ? }

? ? delay(10);

? ? client.stop();

? }

}

**HTML code stored in file "webpage.htm":**

&lt;!DOCTYPE html>

&lt;html>

&lt;head>

? &lt;title>Arduino Web Server&lt;/title>

&lt;/head>

&lt;style>

? body {font-family: "Calibri"; background-color: yellow}

? h1? ?{color: blue; text-align:center; font-size: 80px}

? h2? ?{color: black; font-size: 40px}

? h3? ?{color: red; text-align:center; font-size: 20px}

&lt;/style>

&lt;body>

? &lt;h1>

? ? Arduino Web Server&lt;br>

? ? via Ethernet Shield & SD Card&lt;br>

? &lt;/h1>

? &lt;h2>

? ? &lt;a href="https://www.arduino.cc/en/Main/ArduinoEthernetShieldV1">Arduino Ethernet Shield:&lt;/a>&lt;br>

? ? &lt;ul>

? ? ? &lt;li>Requires an Arduino board (not included)&lt;br>&lt;/li>

? ? ? &lt;li>Operating voltage 5V (supplied from the Arduino Board)&lt;br>&lt;/li>

? ? ? &lt;li>Ethernet Controller: W5100 with internal 16K buffer&lt;br>&lt;/li>

? ? ? &lt;li>Connection speed: 10/100Mb&lt;br>&lt;/li>

? ? ? &lt;li>Connection with Arduino on SPI port&lt;br>&lt;/li>

? ? &lt;/ul>

? ? &lt;center>

? ? ? Ethernet Shield Arduino Uno Connection&lt;br>&lt;br>

? ? ? &lt;img src="https://alselectro.files.wordpress.com/2016/02/ethernet1.jpg">&lt;br>

? ? &lt;/center>

? &lt;/h2>

? &lt;h3>

? ? &lt;p>Anas Kuzechie, Sept 2021&lt;/p>

? &lt;/h3>

&lt;/body>

&lt;/html>

Youtube Video :?<https://www.youtube.com/watch?v=Nn6HuLtUSEU>

---

Source: https://maker.wiznet.io/teju/projects/Arduino-Web-Server-with-Webpage-Stored-on-SD-Card/
