Go Down

Topic: Ethernet Shield Really basic beginner query (Read 1 time) previous topic - next topic


I am new to this and trying to test my cards connectivity i am using a basic sketch as below but Whenever i try to monitor it with the serial monitor it drops the ip connectivity is this normal or am i doing something wrong?

  Web client

This sketch connects to a website (http://www.google.com)
using an Arduino Wiznet Ethernet shield.

* Ethernet shield attached to pins 10, 11, 12, 13

created 18 Dec 2009
by David A. Mellis


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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  0x90, 0xA2, 0xDA, 0x00, 0x81, 0x30 };
byte ip[] = { 192,168,0,80 };
byte gateway[] = { 192,168,0,98 };
byte subnet[] = { 255, 255, 255, 0 };
IPAddress server(74, 125, 113, 99); // Google

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // start the serial library:
  // start the Ethernet connection:
  // give the Ethernet shield a second to initialize:

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    // Make a HTTP request:
    client.println("GET /search?q=arduino HTTP/1.0");
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");

void loop()
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();

  // if the server's disconnected, stop the client:
  if (!client.connected()) {

    // do nothing forevermore:


I did not evaluate all the code, but this will cause problems.
Code: [Select]
byte gateway[] = { 192,168,0,98 };

// start the Ethernet connection:

If you gateway is, then you will have no internet connection. You have the dns server set to the gateway, but if you do not pass the gateway parameter, the gateway by default will be
The parameters for Ethernet.begin are:

If you are not using dns, you can set the dns server to the gateway. This should work better.
Code: [Select]


Jul 05, 2012, 01:29 pm Last Edit: Jul 05, 2012, 01:31 pm by hyperactivestar Reason: 1
Our gateway is though so this is what i was passing as the gateway address. The board is pingable on the IP address set but when i upload the sketch and try to monitor the code running on the serial monitor the IP connectivity drops out


Our gateway is though so this is what i was passing as the gateway address

No, that was what you were passing as the dns server. That is the third parameter. The fourth parameter is the gateway.


Ah ok i unstand now you have to set a value for each parameter. Ok change that but still no connection I upload the sketch and i get responses from pings to the board. But when i put the serial monitor on the board looses IP connection so the programme fails to connect to the webserver


Have you tried dhcp?
Code: [Select]
 Serial.print("Starting ethernet..");
 if(!Ethernet.begin(mac)) Serial.println("failed");
 else Serial.println("ok");

Do you have a microSD card in the shield slot?
What version IDE are you using?

Go Up