HC-SR04

For general Flowcode discussion that does not belong in the other sections.
medelec35
Matrix Staff
Posts: 1964
http://meble-kuchenne.info.pl
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 629 times
Been thanked: 659 times

HC-SR04

Post by medelec35 »

Hopefully, the changes I have made to the HC-SR04 will allow it to work at any clock speed on the 8bit pic devices and all other target devices.
I will post the FC9 and 10 components on two separate posts to avoid confusion
Martin

medelec35
Matrix Staff
Posts: 1964
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 629 times
Been thanked: 659 times

Flowcode v9 Re: HC-SR04

Post by medelec35 »

Browse to this location using file explorer , it's hidden by default so just paste the link into your address bar.

Code: Select all

C:\ProgramData\MatrixTSL\FlowcodeV9\Components
Place the attached component.
If Flowcode is already open, then you will need to reload your project for the new component to work
If you run any component updates, then the component you added will be overwritten, so it will stop working again.
Attachments
HC_SR04_Ultrasonic.fcpx
(40.69 KiB) Downloaded 583 times
Martin

medelec35
Matrix Staff
Posts: 1964
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 629 times
Been thanked: 659 times

Flowcode v10 Re: HC-SR04

Post by medelec35 »

Browse to this location using file explorer , it's hidden by default so just paste the link into your address bar.

Code: Select all

C:\ProgramData\MatrixTSL\FlowcodeV10\Components
Place the attached component.
If Flowcode is already open, then you will need to reload your project for the new component to work
If you run any component updates, then the component you added will be overwritten, so it will stop working again.
Attachments
HC_SR04_Ultrasonic.fcpx
(4.46 KiB) Downloaded 548 times
Martin

jgu1
Posts: 797
Joined: Thu Dec 03, 2020 8:25 pm
Location: Denmark
Has thanked: 686 times
Been thanked: 177 times

Re: HC-SR04

Post by jgu1 »

Hi Martin!

See that you not get any answer, I Will make a test later this evening, at least you deserve a reply for your work :D

You hear.

Jorgen

jgu1
Posts: 797
Joined: Thu Dec 03, 2020 8:25 pm
Location: Denmark
Has thanked: 686 times
Been thanked: 177 times

Re: HC-SR04

Post by jgu1 »

Hi Martin!

Sorry for delay, but yesterday evening I was figthing with this viewtopic.php?f=5&t=2427 :(

I have made some test with the HS SR04:

Arduino, Not Waterproff type working fine and the accuracy was very fine
The Waterproff (black, requere 20uS trig) not working.

Pic 16f876 not working with none of the type not waterproff and waterproff. Maybe cause I don´t know how the setting for Timer, prescaler and postscaler, I try some various, no luck?

Honest I prefer the old component for the HS SR04, They work and it is possible to choose between the two sensors. Concerning the accuracy the user could add an calculation box and: Distance= Distance + - the missing :)

Br Jorgen
Attachments
HC-SR04_Distance_Sensor_Mega_Not_Waterprof.fcfx
(11.74 KiB) Downloaded 630 times
HC-SR04_Distance_Pic16f876Not_Waterprof.fcfx
(11.3 KiB) Downloaded 493 times

medelec35
Matrix Staff
Posts: 1964
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 629 times
Been thanked: 659 times

Flowcode v10 Re: HC-SR04

Post by medelec35 »

Hi Jorgen.
Many thanks for your testing of the component.
Sorry, I did not spot the selection for the two versions are missing.
I have added it back in.
I have also changed the component, so you have a choice if to use the timer option or not.
If you do then the values should be as low as possible e.g. 1:1 for both prescaler and post scaler if available.
For PIC due the XC8 compiler, the distances will be inaccurate if not using the timer.
If using the Arduino, the timer option is not required.
Can you let me know if you are happier with the attached component, please.
Attachments
HC_SR04_Ultrasonic.fcpx
(4.67 KiB) Downloaded 602 times
Martin

jgu1
Posts: 797
Joined: Thu Dec 03, 2020 8:25 pm
Location: Denmark
Has thanked: 686 times
Been thanked: 177 times

Re: HC-SR04

Post by jgu1 »

Hi Martin!

Yes, of course if can I will always help, also in my interrest :D

Wow Martin, I have now perform various tests With an Arduino Mega and a Pic16f876 and both kind of sensors, playing around with Timer settings. For me it work perfect, and all is very accurate. (In room temperature measured by an AHT10 22gr Cel.) My expeince with the 8bit it is most stable by using the Timer interrupt, and the lower setting are, the better accuracy, as you say.
Thank you for your great job, and push it to the update, please+ Fc9 :lol:

Jorgen
Attachments
HC-SR04_Distance_Sensor__Arduino_WORKING.fcfx
(13.16 KiB) Downloaded 588 times
HC-SR04_Distance_Pic16f876Working.fcfx
(12.24 KiB) Downloaded 680 times

medelec35
Matrix Staff
Posts: 1964
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 629 times
Been thanked: 659 times

Re: HC-SR04

Post by medelec35 »

Hi Jorgen.
Thank you.
Hopefully the FC9 and FC10 updates will be pushed ASAP.
I'm glad you are finding HC range of ultrasonic sensors more accurate with PIC8 microcontrollers as that was the intention.
Thanks again for the testing you have done. :)
Martin

theopieleke
Posts: 3
Joined: Mon Jan 11, 2021 10:42 am

Re: HC-SR04

Post by theopieleke »

Sorry for the late respons.
I now downloaded the file for version 9 and will test it this week. Hopefully tomorrow.
Many thanks for the effort.
Theo

chipfryer27
Valued Contributor
Posts: 1575
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 357 times
Been thanked: 561 times

Re: HC-SR04

Post by chipfryer27 »

Hi

This is a follow up to some other posts regarding this sensor, and also to some assistance I was providing.

It was wondered if this sensor could be used to measure the volume of tanks (water not Challenger) and I saw in principle that it should be able to do so with certain caveats.

I had a bit of time in the Evil Lab today and decided to do some empirical tests, nothing exact just to prove the concept.

I had an 80 Litre dustbin with an internal height of 58cm and diameter of 44.5cm. It should be noted that this is the diameter at the top and the bin tapers down.

In previous tests / posts I found the sensor and Martin's component to be quite accurate to over 2 Metres in a free standing location.

Now this sensor spreads at a 45 degree angle meaning that if in an enclosed space such as my "cyclinder" (dustbin), depending on dimensions of the cylinder, the sound could hit the walls and reflect before reaching the bottom / target. This has the potential to cause misreadings. I also wanted to see what, if any difference putting a lid on top would make.

Calculations suggested that the "beam" would reach a diameter of 44.6cm after travelling 53.72cm, so in theory I should be able to measure this far down into my very high tech cyclinder. Anything further would be a bonus as I couldn't say for certain what would happen after this depth due to reflections from walls.

Modifying my sensor rig to sit as close to the centre of the cylinder as possible It measured 46cm when empty and the same with a lid on top.

Hi Tech Testing.JPG
Hi Tech Testing.JPG (87.93 KiB) Viewed 5988 times
Empty Tank.JPG
Empty Tank.JPG (90.85 KiB) Viewed 5988 times

This wasn't quite as hoped for as I "should" have been able to reach ~54 before worrying about unwanted reflections. However my High Tech test cyclinder does taper so that would help explain the discrepancy.

I then filled the tank to a depth of 46cm with water. No change in readings were observed as the tank filled and again the lid made no difference.

Depth ~46cm.JPG
Depth ~46cm.JPG (88.32 KiB) Viewed 5988 times

I continued filling the tank to a depth of approx 40cm and the reading then showed 41cm which given the very rough test set up (despite my High Tech cyclinder) was close enough to say it was working.

Depth = ~40cm.JPG
Depth = ~40cm.JPG (69.5 KiB) Viewed 5988 times
Distance = 41cm.JPG
Distance = 41cm.JPG (91.54 KiB) Viewed 5988 times

Again the lid made no difference.

Filling the tank further, reducing the depth to ~30cm (from sensor) gave a similar reading as did all further tests. The lid made no difference in any reading.

Depth = ~30cm.JPG
Depth = ~30cm.JPG (79.88 KiB) Viewed 5988 times

So, it would seem that you can use this sensor to measure the volume of water in a cylindrical tank, down to the depth (from sensor) where the beam divergence meets the walls of the container.

This was just a very quick and rough test only using the example file, and I hope it is of use.

Regards

Post Reply