Ultrasonic Distance sensor using HC-SR04
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Ultrasonic Distance sensor using HC-SR04
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
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
Martin
Re: Ultrasonic Distance sensor using HC-SR04
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
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
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Ultrasonic Distance sensor using HC-SR04
Your welcome,
Just glad your now all sorted.
Thanks for the update.
Martin
Just glad your now all sorted.
Thanks for the update.
Martin
Martin
Re: Ultrasonic Distance sensor using HC-SR04
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..
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..
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Ultrasonic Distance sensor using HC-SR04
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
Martin
Martin
Re: Ultrasonic Distance sensor using HC-SR04
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
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
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
Please teach me !!!
http://www.youtube.com/watch?v=dRq0e9rwqHo
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Ultrasonic Distance sensor using HC-SR04
Hello,
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.I want to know if is possible to use the ultrasonic sensor HC-SR04 with the pic 16F84A ??
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Ultrasonic Distance sensor using HC-SR04
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.
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Ultrasonic Distance sensor using HC-SR04
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
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
- Attachments
-
- Distance Sensor 16F84A LED_v6.fcfx
- (9.94 KiB) Downloaded 585 times
Martin
Re: Ultrasonic Distance sensor using HC-SR04
My friend thank you very much. Well, I need to find a crystal in 19.66 Mhz, I only have 4 Mhz.
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Ultrasonic Distance sensor using HC-SR04
This could work on 4MHz?
- Attachments
-
- Distance Sensor 16F84A LED 4MHz.fcfx
- (9.84 KiB) Downloaded 556 times
Martin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Ultrasonic Distance sensor using HC-SR04
That's good.
Thanks for the update.
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
Thanks for the update.
I fully agree with Ben.Benj wrote:the 16F84A is now well outdated and doesn't have analogue input capability.
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
Martin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Ultrasonic Distance sensor using HC-SR04
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
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
Martin
Re: Ultrasonic Distance sensor using HC-SR04
Ok my friend, I am very grateful with your support.
Thanks.
Thanks.
Re: Ultrasonic Distance sensor using HC-SR04
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
Remember with pic 16F84A in 4Mhz crystal.
thanks
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Ultrasonic Distance sensor using HC-SR04
Hi kalmar79 ,
The number you see below are approx distance in cm + about 3: so if you want to change to about 20cm
use & as a starting point.
Martin
The number you see below are approx distance in cm + about 3: so if you want to change to about 20cm
use
Code: Select all
Count <= 22
Code: Select all
Count > 23
Martin
Martin
Re: Ultrasonic Distance sensor using HC-SR04
My friend your flowchart working good with the changes. But I am doing the same flowchart but in spanish, but don´t work.
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Ultrasonic Distance sensor using HC-SR04
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
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
Martin
Re: Ultrasonic Distance sensor using HC-SR04
maybe my HC-SR04 don´t understand spanish
I going to make once again, but in english.
thanks my friend
I going to make once again, but in english.
thanks my friend
Re: Ultrasonic Distance sensor using HC-SR04
ok I did again in another file and working good, in spanish and english.
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
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