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;
- http://s7.postimg.org/vyi2z36qz/20140826_001130.jpg
- http://s7.postimg.org/6eb7ewvzf/20140826_001150.jpg
- http://s7.postimg.org/6psnrocff/20140826_001156.jpg
- http://s7.postimg.org/y6ro2ooh7/20140826_001229.jpg
- http://s7.postimg.org/71a44fsvf/20140826_001247.jpg
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);
}