Go Down

Topic: SD card website controlling output pins (Read 936 times) previous topic - next topic


Hello guys, I am trying to put an index.htm onto an SD card for the Arduino to run from but within the index.htm document i want it to be able to turn pins on and off. So far I have got it to work without the SD card, please see below for code. I am wanting to take the website page coding out of the arduino code and put it onto an SD card. can someone help with this?

Code: [Select]
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 0, 100 };
byte gateway[] = { 192, 168, 0, 1 };
byte subnet[] = { 255, 255, 255, 0 };
EthernetServer server(84);

String readString;

void setup(){

 pinMode(7, OUTPUT);
 Ethernet.begin(mac, ip, gateway, subnet);

void loop(){
 EthernetClient client = server.available();
 if (client) {
   while (client.connected()) {
     if (client.available()) {
       char c = client.read();
       if (readString.length() < 100) {
         readString += c;

       if (c == '\n') {


           if(readString.indexOf('?') >=0) {
            else {
         client.println("HTTP/1.1 200 OK");
         client.println("Content-Type: text/html");

         client.println("<TITLE>Arduino Game Setup Menu</TITLE>");
         client.println("<style type=\"text/css\"/>");
         client.println("body {");
         client.println("background-color: #CCC;");

         client.println("<H1>Arduino Game Setup Menu</H1>");
         client.println("<a href=\"/?on\" target=\"inlineframe\">ON</a>");
         client.println("<a href=\"/?off\" target=\"inlineframe\">OFF</a>");

         client.println("<IFRAME name=inlineframe style=\"display:none\" >");          



         if(readString.indexOf("on") >0)
           digitalWrite(7, HIGH);
           Serial.println("Led On");
         if(readString.indexOf("off") >0)
           digitalWrite(7, LOW);
           Serial.println("Led Off");


The index.htm code would look like this

Code: [Select]
<TITLE>Arduino Game Setup Menu</TITLE>
<style type="text/css"/>
body {
background-color: #CCC;
<H1>Arduino Game Setup Menu</H1>
<a href="/?on" target="inlineframe">ON</a>
<a href="/?off" target="inlineframe">OFF</a>
<IFRAME name=inlineframe style="display:none" >

I am just trying to keep it simple for now using hyperlinks rather than scripts on the websites like previously found on youtube videos. can someone please help me convert my arduino code into something which would work via the SD card.


I am wanting to take the website page coding out of the arduino code

Good idea.

and put it onto an SD card.

Also a good idea.

can someone help with this?

Send me the SD card, and I'll create the index.htm file on it.

Now, really, what is it you need help with? The Arduino sill has to detect that the GET request is a request for index.htm. If it is, then the Arduino has to open the file on the SD card, read it's contents (using a buffer) and send the data to the client that made the request. When the end of the file is reached, you need to close the file.
The art of getting good answers lies in asking good questions.

Go Up