Search code examples
arduinosensorsarduino-unoethernet

Arduino UNO + Ethernet Shield + Ultrasonic Sensor = Fail


With my Arduino Uno I measure the distance using HC-SR04 ultrasonic sensor with no problems at all using the wiring below. When I attach ethernet shield, my ultrasonic sensor does not measure distance any more, it constantly says 0cm no matter what. I have tried different digital pin pairs such as 5-7, 6-8, 5-9, 3-5, 2-8 but no luck.

I suspect that HC-SR04 is not compatible with my Ethernet shield but I haven't seen such warning anywhere on the net.

  • There are no components attached to arduino besides ethernet shield and the ultrasonic sensor itself.
  • There is no SD Card in SD Card slot.
  • My ethernet shield works fine while running a web server or web client script.
  • Digital pins of ethernet shield works fine with all other components such as temperature sensor, motion sensor etc.

Here is the ethernet shield I have; http://www.ezshopfun.com/product_info.php?products_id=169

Here is my actual circuit;

Here is my code;

#define trigPin 6
#define echoPin 7

void setup() {
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop() {
  int duration, distance;
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH) / 2;
  distance = duration / 29.1;
  Serial.print(distance);
  Serial.println(" cm");
  delay(500);
}

Circuit


Solution

  • Today I bought a multimeter and tested my circuit. Here are the results;

    When my circuit directly attached to Arduino itself;

    4.80V & 5.7mA

    When my circuit attached to ethernet shield;

    3.06V & 3.8mA

    I think the problem is that 3.06V is not enough for my HC-SR04 to operate.