Categories
Arduino Platform Projects

Arduino Ethernet Shield and Webclient

When you first get an Ethernet Shield for your Arduino (I'm using a Duemilanove), the natural thing to do is upload the example sketches to test it out. Everything was working perfectly until I hit the WebClient sketch—it just wouldn't connect.

The Problem

The WebClient example sketch that comes with the Arduino Ethernet library is designed to connect to a web server and fetch a page. The default example tries to connect to Google, but it kept failing on my setup. The frustrating part was that the WebServer sketch worked flawlessly, so I knew the shield itself was fine.

Troubleshooting Steps I Tried

I went through every troubleshooting step I could think of:

  • Reset the Arduino
  • Reset the Ethernet Shield
  • Changed the Ethernet Cat5 cable to a shorter one
  • Modified router settings
  • Changed the MAC address in the program
  • Changed the last 2 octets of IP from 192.168.6.xxx to 192.168.1.xxx
  • Finally, searched Google for the issue

Since the WebServer sketch worked perfectly, I was confident the hardware was good. This had to be a software or configuration issue.

The Discovery

After searching the Arduino forums, I found this thread where someone mentioned: "Don't try to connect to Google."

Bingo! The problem wasn't my setup—it was Google itself.

Why Google Doesn't Work

The issue is that Google.com automatically redirects HTTP requests to HTTPS. The Arduino Ethernet Shield only supports plain HTTP connections—it doesn't have the processing power or memory to handle SSL/HTTPS encryption.

When the WebClient tries to connect to Google on port 80, Google responds with a redirect to HTTPS, which the Arduino can't follow or process. The connection fails, and you're left wondering what went wrong.

The Solution: Use a Different Server

The fix is simple: use a web server that supports plain HTTP without redirecting to HTTPS. Here's a working example using a different test server:

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

// Enter a MAC address for your controller below
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 177);
IPAddress server(93, 184, 216, 34); // example.com

EthernetClient client;

void setup() {
  Serial.begin(9600);

  // Start the Ethernet connection
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // Try to configure using IP address instead of DHCP
    Ethernet.begin(mac, ip);
  }

  delay(1000);
  Serial.println("Connecting...");

  if (client.connect(server, 80)) {
    Serial.println("Connected");
    client.println("GET / HTTP/1.0");
    client.println();
  } else {
    Serial.println("Connection failed");
  }
}

void loop() {
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("Disconnecting.");
    client.stop();
    while(true);
  }
}

Alternative Servers That Work

Here are some servers that work well with the Arduino Ethernet Shield:

  • example.com (93.184.216.34) – Simple test page, perfect for examples
  • Your own web server – If you have a server that serves plain HTTP
  • Local network servers – Any device on your network running a simple HTTP server
  • Weather APIs – Many weather services offer HTTP-only endpoints

Key Takeaway

If your Arduino Ethernet Shield WebClient examples fail when trying to connect to Google or other major websites, remember: the shield only supports plain HTTP (port 80), not HTTPS. Modern websites like Google default to HTTPS for security, which the Arduino can't handle.

Stick with HTTP-only servers for your Arduino projects, or set up your own simple web server that doesn't redirect to HTTPS.

By Shishir Sharma

Shishir Sharma is a Software Engineering Leader, husband, and father based in Ottawa, Canada. A hacker and biker at heart, and has built a career as a visionary mentor and relentless problem solver.

With a leadership pedigree that includes LinkedIn, Shopify, and Zoom, Shishir excels at scaling high-impact teams and systems. He possesses a native-level mastery of JavaScript, Ruby, Python, PHP, and C/C++, moving seamlessly between modern web stacks and low-level architecture.

A dedicated member of the tech community, he serves as a moderator at LUG-Jaipur. When he’s not leading engineering teams or exploring new technologies, you’ll find him on the open road on his bike, catching an action movie, or immersed in high-stakes FPS games.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.