Please help Etherneth Shield not working ???

Hi All,

I am working on a project kind of Product counter system, iam using arduino uno and ethernet shield and using IR Sharp sensor GP2Y0A02YK0F 20-150 cm when i try code using only arduino it works however when i try to add etherenet shield code there is no communication and can’t figure out what is the problem, can you please help

this is my code for arduino :

Web Server UMS Application Software and hardware communication

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

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
IPAddress ip(192, 168, 0, 160);

int sensorCounter=0; // holds the number of products counted
int iSenseMin=420; // sensor minimum value for count function reset (calibrate in a testing enviroment then set as default values)
int iSenseMax=450; // sensor maximum value to indicate a valid count (calibrate in a testing enviroment then set as default values)
bool bCountFlag=0; // a flag indicating the specific count current state

//char server = “”;

// 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() {
// Open serial communications and wait for port to open:
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only

// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
Serial.print("server is at ");

void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
//Serial.println(“new client”);
// an http request ends with a blank line
//boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {

if (SensorRead()>iSenseMax)
if(!bCountFlag) // if the count state flag is not set a new count will be carried out
sensorCounter++; // add count
//Counting(); // display new count value
Serial.print("Number of finished products: ");
Serial.println(sensorCounter); // debugging

client.print(“GET /capteur/bdd-connet.php?”); // This
client.print(“chaineid=”); // This
client.print(sensorCounter); // And this is what we want to do when the sensor count new produc - send the count to the be written in our Database
client.println(" HTTP/1.1 200 OK"); // Part of the GET request
client.println(“Host:”); // IP Address
client.println(“Connection: close”); // Part of the GET request telling the server that we are over transmitting the message
client.println(); // Empty line
client.println(); // Empty line
client.stop(); // Closing connection to server

bCountFlag=1; // sets the count flag to true indicating that no further counts can be made until flag is set to false
while(bCountFlag) // a hold to wait for the sensor to go below the minimum value
if(SensorRead()<iSenseMin) bCountFlag=0; // break the loop
delay(10); // function settle

//char c =;
// Serial.write(c);


// give the web browser time to receive the data


// close the connection:
Serial.println(“client disconnected”);

int sensorValue = analogRead(A0); // sensor voltage output connected to Arduino analog pin A0
return sensorValue;

i was hoping if anyone can help please.

    while (client.connected()) {
      if (client.available()) {

        if (SensorRead()>iSenseMax)

You’re only reading the sensor when there’s a client connecting to your Arduino.

Is that really what you want?

If not you should explain what exactly this is supposed to do.