I would like to do a project using a HC-SR04 for distance measurement. Anybody who has done a similar project who would like to share a program example for this?

BR
Tomas
Moderator: Benj
That's a nice site, indeedBenj wrote:
That looks like a great little module. May have to get one myself and have a play
Not done anything with these but looking at the sample PICaxe code it looks quite straightforward.
Looks nice - I must try to "translate" this into FlowcodeBenj wrote:Here is some simple psudocode I came across for driving the device.
symbol trig = 3 ‘ Define output pin for Trigger pulse
symbol echo = 6 ‘ Define input pin for Echo pulse
symbol range = w1 ‘ 16 bit word variable for range
main:
pulsout trig,2 ‘ produce 20uS trigger pulse (must be minimum of 10uS)
pulsin echo,1,range ‘ measures the range in 10uS steps
pause 10 ‘ recharge period after ranging completes
‘ now convert range to cm (divide by 5.or inches (divide by 14.
‘ as picaxe cannot use 5.8, multiply by 10 then divide by 58 instead
let range = range * 10 / 58 ‘ multiply by 10 then divide by 58
debug range ‘ display range via debug command
goto main ‘ and around forever
You could output the start pulse and then use say a timer interrupt to time the period for the pulse to return.
Thanks. I'll do thatBenj wrote:Give it a go and post up your Flowcode program if you get stuck and we should be able to help you get this device up and running.
Wow that sounds like a bargain!TomasS wrote: The module has now been bought - $3.41 including shipping
Hi Martinmedelec35 wrote:Wow that sounds like a bargain!TomasS wrote: The module has now been bought - $3.41 including shipping
hope it's all going to work for you.
With all the experts on here, (and me of course) I'm sure we would be able to get a working project for you.
I have already started working on ultrasonic range finder. Not sure on the distance it will work up to yet.
If successful I can post the flowchart.
Martin
Hi Ben. I have started working on my own ultrasonic detector, but was a bit puzzled about range of 10us and the distance.Benj wrote:
pulsin echo,1,range ‘ measures the range in 10uS steps
pause 10 ‘ recharge period after ranging completes
‘ now convert range to cm (divide by 5.8) or inches (divide by 14.8)
Hi JohnJohnCrow wrote:Ive played with the SRF05 (which is the same pin out as the SRF04) ranger using the projects in Bert van Dams Flowcode book which work well.
These were done in FC3 but certainly worked fine in FC4 (Not tried them in FC5 but should work).
Im currently trying an SRF10 which is a lot smaller than the SRF05 and uses I2C bus, but so far ive not been able to get it to work properly. :(Need to have another look at this project soon)
I wasn't including myself in the expert listTomasS wrote:
I'm pleased ´to find all you experts on here - for sure!
Sure, as you can see from my post above, I have already started, and querying the calculations.TomasS wrote:
Sounds great - maybe we can compare solutions, when I receive my version?
If you go to this website:TomasS wrote:I actually have this book on my shelf, but I did not see that it had a project with the ultrasound sensor - I will look into that!![]()
medelec35 wrote:I wasn't including myself in the expert listTomasS wrote:
I'm pleased ´to find all you experts on here - for sure!![]()
Sounds great! I'll look forward to itmedelec35 wrote:Sure, as you can see from my post above, I have already started, and querying the calculations.TomasS wrote:
Sounds great - maybe we can compare solutions, when I receive my version?
Has to be right![]()
If I can get it working OK,will post flowchart in the tips section.
I will also post on here a link to it.
I have a busy weekend, but I will try to complete as much as I can.
Done!medelec35 wrote:If you go to this website:TomasS wrote:I actually have this book on my shelf, but I did not see that it had a project with the ultrasound sensor - I will look into that!![]()
http://www.elektor.com/extra/microcontr ... 1368.lynkx
You can download the flowchart (by Download the complete package).
Flowchart can be found in Chapter5, section 5-3
Martin