NEED HELP with ethernet sheild

I just picked a ethernet shield for my uno and was trying to use a simple example code to learn about how the shield works. The code is one I found online, Only thing I changed was the ip address which I found by pinging different ip’s on my network until I found one that didn’t respond. Then I assigned the uno that address.

Code upload went fine, but when I type in my ip and then /$1 in the address bar it just says couldn’t open page because server stopped responding. I even turned the firewall off on my laptop but still no response. Here is the code:

Web Server Demo
thrown together by Randy Sarafan

Allows you to turn on and off an LED by entering different urls.

To turn it on:

To turn it off:


  • Ethernet shield attached to pins 10, 11, 12, 13
  • Connect an LED to pin D2 and put it in series with a 220 ohm resistor to ground

Based almost entirely upon Web Server by Tom Igoe and David Mellis

Edit history:
created 18 Dec 2009
by David A. Mellis
modified 4 Sep 2010
by Tom Igoe


#include <SPI.h>
#include <Ethernet.h>

boolean incoming = 0;

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac = { 0x00, 0xAA, 0xBB, 0xCC, 0xDA, 0x02 };
IPAddress ip(192,168,1,3); //<<< ENTER YOUR IP ADDRESS HERE!!!

// 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()
pinMode(2, OUTPUT);

// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);

void loop()
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char 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

//reads URL string from to first blank space if(incoming && c == ' '){ incoming = 0; } if(c == ''){
incoming = 1;

//Checks for the URL string $1 or $2
if(incoming == 1){

if(c == ‘1’){
digitalWrite(2, HIGH);
if(c == ‘2’){
digitalWrite(2, LOW);


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
// close the connection:

I have a netgear router, at this point I don’t know where the problem lies, I am new to this and really confused. If anyone can point me in the right direction that would great. THANKS

Don't use the dollar sign. That is an illegal character in a URL. To comply with convention, you should use a page name and a question mark. No blank spaces allowed in a URL either. It will be a terminating zero.

        //reads URL string from $ to first blank space
        if(incoming && c == ' '){ 
          incoming = 0;
        if(c == '

edit: You can try my server code. Add code that uses one of the variables in that sketch to control your hardware.

With my code, I would try something like this as a test.

// find this part of the code...
if(strncmp(pch,"t=",2) == 0) {
  t = atoi(pch+2);

  // ...and add this. If t equals 1, turn it on, else turn it off
  if(t == 1) digitalWrite(2, HIGH);
  else digitalWrite(2, LOW);

         incoming = 1;

edit: You can try my server code. Add code that uses one of the variables in that sketch to control your hardware.

With my code, I would try something like this as a test.


Wonderful. Thanks I will try it now. :slight_smile:

Just tried your code with adding my ip. Still getting can not connect to server error message. I'm starting to feel that the problem is in network settings rather than code. I'm not sure, Do I need to enable port forwarding or anything?

Can you ping the Arduino ip? Try on the Arduino localnet first to insure it works.

How do you have these set?

// change to your network settings
IPAddress ip( 192,168,2,2 );
IPAddress gateway( 192,168,2,1 );
IPAddress subnet( 255,255,255,0 );


Do I need to enable port forwarding or anything?

You must enable port forwarding if your Arduino is on a private ip subnet and you want to access it from a public ip (internet).