Go Down

Topic: IP for ethernetshield (Read 930 times) previous topic - next topic

Wouter van


I have a new arduino controller and this is really fun working with, but I have a problem with setting op an ethernetconnection. I tried many times but it doesn't work.

This is my code. I have two led's. One that says everything is good and the otherone says there is a problem. The only led that is given light is the one with the error

Code: [Select]

#include <Ethernet.h>

byte mac[] = { 0x00, 0x1C, 0xF0, 0xFB, 0x6B, 0x8A };
byte ip[] = { 192, 168, 0, 2 };                      // this is the ip within my lan
byte gateway[] = { 192, 168, 0, 1 };                  // neccessary to get access to the internet via your router
byte subnet[] = { 255, 255, 255, 0 };
byte server[] = { 216, 239, 59, 104 };               // Google.nl

int gledPin =  13;    // LED connected to digital pin 13 yellow one
int fledPin =  12;    // LED connected to digital pin 12 red one

Client client(server, 80);

void setup()
  pinMode(gledPin, OUTPUT);  
pinMode(fledPin, OUTPUT);  
 Ethernet.begin(mac, ip, gateway, subnet);


 if (client.connect()) {
      digitalWrite(gledPin, HIGH);   // set the LED on
 } else {
   Serial.println("connection failed");
       digitalWrite(fledPin, HIGH);   // set the LED on

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

 if (!client.connected()) {

This i a copy of my d-link router
Connection Type : DHCP Client .
QoS Engine : Active .
Cable Status : Connected .
DNS Status : Online .
Network Status : Established .
Connection Up Time : 0 Day 9 Hour 19 Min 40 Sec .
MAC Address : 00:1C:F0:FB:6B:8B .
Authentication & Security :   .
IP Address : .
Subnet Mask : .
Default Gateway : .
Primary DNS Server : .
Secondary DNS Server : .
MAC Address : 00:1C:F0:FB:6B:8A .
IP Address : .
Subnet Mask : .
DHCP Server : Enabled .


you have your lan ip as 192,168,1,1 yet in you sketch you have your adapter ip as 192,168,0,2 maybe this should be 192,168,1,2
for instance my gateway is 192,168,2,1 so my ethernet shield ip is set to 192,168,2.15   15 because other family members use laptops within the house so theres no chance of bumping into one of them. it's confusing but maybe this will help


Apr 05, 2010, 12:02 am Last Edit: Apr 05, 2010, 12:03 am by zyruz Reason: 1
Try chaning the ip on the board from to somthing other, as it wil make a conflict if both your computer and the arduino have the same ip. But keep within the same subnet ( 192.168.0.x)


Wouter van

Thank you for the aswers, but they didn't work out.

I worked it out that the lan port one my router went on, but when i loged in i my router there was no sighn he was connected. I tried multi codes, but alle with no succes.

But how can I set an IP that is not giving a way by the router. The router is the one who wille give all the IP's adresses, right. But for the code I need to set it before I connected to the router.

Or do I need to connect the route by lan and the usb to the computer at the same time and than I can see witch Ip he will set.

Thank you for your reply. My English is not really good so I hove you can understand it.



Apr 06, 2010, 10:18 am Last Edit: Apr 06, 2010, 10:49 am by Grumpy_Mike Reason: 1
But how can I set an IP that is not giving a way by the router.

You need to turn off the DHCP system at your router and assign the IP addresses manually.

Edit. yes I did  :)


But how can I set an IP that is not giving a way by the router.

You need to turn off the DNS system at your router and assign the IP addresses manually.

You probably mean DHCP...

You may have to dig out the manual for your router.  MOST routers will have a mechanism for allowing some hosts to have "static" IP addresses, rather than ones assigned by the router.  As long as these are on the same network as the assigned addresses, routing and etc will work fine.

For example, on my Linksys router, the DHCP configuration tab has a spot for "starting IP address" and "maximum number of clients", which I have set like and 50.  That means that the router will automatically assign addresses from to  All the other addresses on 192.168.1.x can be used by devices that do not use DHCP for configuration  (the router itself is, there's a wireless Access Point at, etc...)

Wouter van

Thanks it works. I update my router and than i switch the DHCP Server off.

The last question i have is a php issue. I wrote the next code, and the php script really worked, so there is a communication.

How can I read the php answer in the board.

This is the code and this is the script

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

byte mac[] = { 0x00, 0x1c, 0xf0, 0x90, 0xd7, 0x23 };
byte ip[] = { 192, 168, 1, 109 };
byte server[] = { 79, 170, 43, 15 }; //lollie
byte gw[] = { 192, 168, 1, 1 };   //your router's IP address
byte subnet[] = { 255, 255, 255, 0 };    //subnet mask of the network
int entrada = 0;
int data = 0;
int tempPin = 2;  // I det her tilfælde sendes temperaturen fra pin 2 til en sql server
Client client(server, 80);

void setup()
Ethernet.begin(mac, ip, gw, subnet);
pinMode(tempPin, INPUT);
Serial.println("Starten van programma");
void loop()

void senddata()
data = analogRead(tempPin);           //Laeser analog værdi
Serial.println("Verbinding van start.............");
delay(1000);                                    //Forhindrer forbindelsen i at hænge

if (client.connect()) {
Serial.println("Is verbonden: Verturen van de data");
client.print("GET http://www.lollie-webdesign.nl/test.php?go=temp&temp=");
client.println(" HTTP/1.1");
client.println("Host: www.lollie-webdesign.nl");
Serial.println("data is verstuurd");

Serial.println("Niet verbonden dus een fout");
//stop client
while(client.status() != 0)

This is the PHP code
Code: [Select]
mysql_connect('localhost', 'xxxxxxxx', 'xxxxxx') or die(mysql_error());
mysql_select_db('xxxxxxxxx') or die(mysql_error());

if ($_GET['go']=="temp") {

 $query = "INSERT INTO temp (temp, date) VALUES ('$temp',CURDATE())";
$result = mysql_query($query) or die(mysql_error());
echo "The data has been added";

I my communication with serialmonitor I see al the Print, but not the one of client.read(); There is no line "The data has been added"

I tried every code but it doesn't work


You do not read the page that are beeing sent back to you.
The only thing I see you are doing is: client.read();
But this alone wont do annything.
See http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1238640832/0 for example on how to read a response.


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131