Library for HC_SR04 Ultrasonic Rangefinder
#1
Posted 06 January 2012 - 03:23 AM
- Antonio Florencio, Jason Stevenson, Dmitry Mikhaylov and 1 other like this
#2
Posted 01 February 2012 - 10:33 PM
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.
I did!
Thanks for sharing!
#3
Posted 17 February 2012 - 03:14 PM
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.
This is awesome!! thanks so much, out of curiosity, what was the altitude and climate you calibrated to,I'm located in Massachusets.
#4
Posted 02 April 2012 - 08:22 PM
#5
Posted 03 April 2012 - 12:55 AM
Western Colorado. Altitude about 4600' Climate: very dry.This is awesome!! thanks so much, out of curiosity, what was the altitude and climate you calibrated to,I'm located in Massachusets.
Would be interested in seeing how different your calibration numbers are.
#6
Posted 03 April 2012 - 12:58 AM
Hi,
I received a HC-SR04 sensor today and tried it with this code, but I don't seem to be getting any interrupts from the echo pin on the sensor. I connected 5V to the vcc pin and ground to ground.
pin D6 is connected to echo and pin D7 is connected to trig, just as the demo code does. Do I need to plug the netduino into a standalone power supply instead of usb for this to work or is my sensor dead on arrival?
Hopefully someone can help me?
Thanks in advance!
Hmmm... I had it working either way. What are you using to reflect the sound?
#7
Posted 03 April 2012 - 05:32 AM
Hmmm... I had it working either way. What are you using to reflect the sound?
I tried my hand, a cardboard box, a piece of wood, nothing seems to put the echo pin high...
I tried to use pin D0 and D1 (+change the code of course), but that didn't help either.
Is there a way to check if this module is working, except for connecting it to the netduino?
#8
Posted 04 April 2012 - 03:08 AM
I tried my hand, a cardboard box, a piece of wood, nothing seems to put the echo pin high...
I tried to use pin D0 and D1 (+change the code of course), but that didn't help either.
Is there a way to check if this module is working, except for connecting it to the netduino?
Please forgive me. The problem is all mine. I modified the documentation and never tested it after the modification (I should know better than that).
Anyway, I had the pin documentation reversed for the constructor. Please download the updated code with the corrections. The first parameter is the pin connected to Trig. The second parameter is the pin connected to Echo. The names of the parameters are renamed to pinTrig and pinEcho (and I hope that will end all confusion).
Anyway, let me know if that does not fix your problem.
- Jason Stevenson likes this
#9
Posted 04 April 2012 - 05:10 AM
Please forgive me. The problem is all mine. I modified the documentation and never tested it after the modification (I should know better than that).
Anyway, I had the pin documentation reversed for the constructor. Please download the updated code with the corrections. The first parameter is the pin connected to Trig. The second parameter is the pin connected to Echo. The names of the parameters are renamed to pinTrig and pinEcho (and I hope that will end all confusion).
Anyway, let me know if that does not fix your problem.
Hi. That would be great news. Will try it this evening... Never thought about trying that, actually...
Thanks! I'll let you know what the result is today or tomorrow!
#10
Posted 04 April 2012 - 05:26 AM
#11
Posted 14 January 2013 - 03:02 PM
Could you elaborate a bit on how to calibrate the InchConversionFactor and LatencyTicks? I'm using using it with a Netduino Go and I'm having no luck at all.
thank you.
#12
Posted 18 January 2013 - 02:21 AM
Thanks for the code. Had it up and running in just a few minutes. I'm planning to use this to surprise my cats when they get on my countertop!
#13
Posted 18 January 2013 - 02:40 AM
Thanks for the code. Had it up and running in just a few minutes. I'm planning to use this to surprise my cats when they get on my countertop!
HAH, now that would be a great Netduino video to post
Twiiter: https://twitter.com/Gutworks
#14
Posted 21 January 2013 - 02:03 PM
[font="arial, helvetica, sans-serif;font-size:14px;color:rgb(0,0,0);"]@[/font][color=#000000;]ccfoo242[/color] were you using the Netduino Plus or the Netduino Go? The more I experiment with this the more I think I have a bad
[color=#000000;][font="arial, helvetica, sans-serif;"]HC_SR04.[/color][/font]#15
Posted 21 January 2013 - 05:27 PM
HAH, now that would be a great Netduino video to post
Yes, that's exactly what the internet needs, more cat videos.
#16
Posted 28 February 2013 - 09:55 PM
Sir.. thank you!
#17
Posted 13 March 2013 - 03:08 AM
I have problem with NGO and SB, it gives me values between 93 and 120
#18
Posted 13 March 2013 - 11:42 AM
PS: It works well with arduino
#19
Posted 22 March 2013 - 02:22 PM
Thank you for the driver, works very well with Netuino 1. I made myself a rear distance sensor for my auto
#20
Posted 26 March 2013 - 08:21 AM
sir can I use this code with FEZ Spider what are things need to be change to work this code with FEZ Spider using Extender module
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users