It's been 3 hours, still trying to figure out what is wrong
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 but no luck.
I wonder whether HC-SR04 is not compatible with Ethernet shield or is there something wrong with my ethernet shield's digital pins. I need help
P.S. My ethernet shield works fine while running a web server or web client script.
SurferTim:
Post a link to the ethernet shield you are using.
edit: This code has a problem. The variables distance and duration are both integers. No fractions on integers.
distance = duration / 29.1;
Nope no problem with the code, same code works for arduino digital pins itself but not for ethernet shield. There is nothing wrong with dividing integers to doubles, it will just truncate the fraction part. Btw, I added the my ethernet shield's link to the original post.
Then the ethernet shield should not affect the sensor, but I have an Arduino ethernet shield, not your model. Nothing on my shield that would affect that code.
Yes exactly, there should be no effect at all. Still same I get 0 as output, I have tried different extensions on top of arduino uno and my code works well with them.
If you are ok with experimenting, you can try bending the ethernet shield pins you are using for the sensor (D6 and D7) a little so they do not connect to the Uno, then connect the sensor to those pins (D6 and D7) on the Uno. Does it work then?
It could be a power problem. Do you have a SD card in the shield's slot?
I have no SD card in the slot. Actually I don't want to bend the pins but here is what I'll do to test D6, D7 and the other slots; I'll just try those pins with other components such as temperature sensor and a simple LED and see if they work well with them. Will be posting test results.