Page 3 of 4

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Wed May 01, 2013 7:53 pm
by medelec35
The Flowchart was designed using 19.6608MHz crystal. Since timer interrupt is used, accuracy will depend on oscillator speed.
If different speed from 19.6608MHz then the distances will not be correct.

Crystal will give better results than internal oscillator.

If using 8MHz then all the calculations will need altering before any reasonable accuracy can be seen.

If I get time, I may put together a 8MHz version, but no promises.

Martin

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Thu May 02, 2013 7:19 am
by Frank607
Hi Martin,

Thanks, but you don’t have to build one for 8MHz. I just bought a few 19.6608MHz crystal’s and when these arrive I will try this and let you know.

Regards,

Frank

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Tue May 07, 2013 4:09 pm
by Frank607
Hi Martin,

With the right crystal 20MHz all is working fine now. Thanks !

Frank

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Tue May 07, 2013 6:01 pm
by medelec35
Your welcome,
Just glad your now all sorted.
Thanks for the update. :)


Martin

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Fri Feb 28, 2014 4:50 am
by jnbruno
Hi,

I tried the code attached here but I cant get it to work.. Im using PIC16F877A and HC-SR04 sensor, I want my program to be like this video on youtube.. LED will turn on when obstacle is detected. My Echo is connect to PortD.4 , Trigger is connect to PortD.5, The output LED is on PortD.6.. I really need help..

http://www.youtube.com/watch?v=dRq0e9rwqHo

Please help me.. I need that for my project.. My professor require to use flowcode.. I really need help..

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Sat Mar 01, 2014 9:01 pm
by medelec35
If you post your Flowchart then I can see if I can help you out and let you know where you're going wrong.

Martin

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Sun Aug 27, 2017 11:01 pm
by kalmar79
Hello my friends, I want to know if is possible to use the ultrasonic sensor HC-SR04 with the pic 16F84A ??
I only want to use a led active in 10 cm, I don´t need to use a LCD in this moment.

Thanks

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Tue Aug 29, 2017 6:35 am
by kalmar79
I want to make this in flowcode V6, with 16F84A, without LCD only with Led diode. But I don't know how to star the flowchart.

Please teach me !!!

http://www.youtube.com/watch?v=dRq0e9rwqHo

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Tue Aug 29, 2017 1:01 pm
by Benj
Hello,
I want to know if is possible to use the ultrasonic sensor HC-SR04 with the pic 16F84A ??
Yes this should be possible if the echo from the module is digital, the 16F84A is now well outdated and doesn't have analogue input capability.

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Tue Aug 29, 2017 7:59 pm
by kalmar79
Thanks for response, well I saw a video in youtube with the 16F84A but ok I going to use a 16F88. I want to do it but I don't know how to star the flowxhart.

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Tue Aug 29, 2017 8:09 pm
by kalmar79
I don't need to use a LCD only a led.

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Tue Aug 29, 2017 9:41 pm
by medelec35
Hi kalmar79,
I have posted a very basic flowchart that should work with 16F84A and HC-SR04
Use a crystal as high frequency as possible.
The flowchart assumes a crystal of 19.660800MHz
Connections are:
Echo = B6
Trigger = B7
LED = A0

The LED with light when an object is within 10cm of Sensor.

Martin

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Tue Aug 29, 2017 10:28 pm
by kalmar79
My friend thank you very much. Well, I need to find a crystal in 19.66 Mhz, I only have 4 Mhz. :D

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Tue Aug 29, 2017 10:45 pm
by medelec35
This could work on 4MHz?

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Thu Aug 31, 2017 2:52 am
by kalmar79
Working good !!! :D :D :D :D

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Thu Aug 31, 2017 8:45 am
by medelec35
That's good.
Thanks for the update.
Benj wrote:the 16F84A is now well outdated and doesn't have analogue input capability.
I fully agree with Ben.
Analogue input capability makes it much easier to add a pot.
Then you can set the distance e.g. from 2cm to 3m you would like to LED to activate.
Of course than can be done with 16F84A but its more complex.
Thank goodness we have microcontrollers with analogue to digital converters.
If you want to make hardware smaller, as you will have a fair few pins left over and use less components then you could consider using 12F1840.
If you do you could use the internal oscillator which then would make crystal and two caps redundant.
The internal oscillator can run a different speeds up to 32MHz .

Martin

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Thu Aug 31, 2017 6:40 pm
by medelec35
Hi kalmar79,
I have merged topics related to ultrasonic sensor to keep forums tidy.
Any questions related to ultrasonic sensor ultrasonic sensor flowchart I posted, please post here rather than making a new topic.

Thank you

Martin

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Fri Sep 01, 2017 1:04 am
by kalmar79
Ok my friend, I am very grateful with your support.

Thanks.

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Tue Sep 19, 2017 5:20 am
by kalmar79
My friend Medelec, I want to change the distance a little bit. What I need to change??
Remember with pic 16F84A in 4Mhz crystal.
thanks

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Tue Sep 19, 2017 6:42 am
by medelec35
Hi kalmar79 ,
The number you see below are approx distance in cm + about 3:
Distance cm.png
(5.21 KiB) Downloaded 8794 times
so if you want to change to about 20cm
use

Code: Select all

 Count <= 22
&

Code: Select all

Count > 23
as a starting point.

Martin

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Wed Sep 20, 2017 1:11 am
by kalmar79
Thank you my friend I going to test.

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Wed Sep 20, 2017 2:42 am
by kalmar79
My friend your flowchart working good with the changes. But I am doing the same flowchart but in spanish, but don´t work.
sensor de distancia con 16F84A.fcfx
(5.37 KiB) Downloaded 506 times

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Wed Sep 20, 2017 8:52 am
by medelec35
I can't see why it won't work.
What about adding a delay of say 50ms at the start of the main loop?
You could also try changing Osc type from XT to HS although technically XT is not wrong.

Martin

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Thu Sep 21, 2017 2:46 am
by kalmar79
maybe my HC-SR04 don´t understand spanish :lol: :lol: :lol:

I going to make once again, but in english.

thanks my friend

Re: Ultrasonic Distance sensor using HC-SR04

Posted: Thu Sep 21, 2017 5:05 am
by kalmar79
ok I did again in another file and working good, in spanish and english. :lol: :lol:

I want to introduce a buzzer insted a led. do I need to modificate something?

Why you use '320' in (Echo = 0) || (count > 320) ??

thanks