Someone might find this code useful. I found these HC SR04 ultrasonic rangefinders on amazon for $15 but they had no code. I found some Arduino code, but was pretty useless for Netduino because it used blocking for the timing. So I wrote my own that uses interrupts for the timing. We used this successfully on a mobile robot for detecting obstacles. Accurate to sub-inch against hard surfaces. It is calibrated for my altitude and climate, you may need to adjust the InchConversionFactor and LatencyTicks for your environment. If you want it to read centimeters, just add your own TicksToCentimeters function. Enjoy and feel free to improve it. 2012/04/03 - Corrected pin documentation on constructor
Thank you sir for sharing this,
But your code seem to be not working when 4 sonar sensors are connected together, When I try it using 3 sonars it works fine, But for 4 sonar sensors I gives false value in a one sonar. Does anyone have any idea why?