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
HC-SR04
-
- Matrix Staff
- Posts: 1964
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 629 times
- Been thanked: 659 times
Re: HC-SR04
Browse to this location using file explorer , it's hidden by default so just paste the link into your address bar.
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.
Code: Select all
C:\ProgramData\MatrixTSL\FlowcodeV9\Components
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
-
- Matrix Staff
- Posts: 1964
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 629 times
- Been thanked: 659 times
Re: HC-SR04
Browse to this location using file explorer , it's hidden by default so just paste the link into your address bar.
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.
Code: Select all
C:\ProgramData\MatrixTSL\FlowcodeV10\Components
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
-
- Posts: 797
- Joined: Thu Dec 03, 2020 8:25 pm
- Location: Denmark
- Has thanked: 686 times
- Been thanked: 177 times
Re: HC-SR04
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
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
-
- Matrix Staff
- Posts: 1964
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 629 times
- Been thanked: 659 times
Re: HC-SR04
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.
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
-
- Posts: 797
- Joined: Thu Dec 03, 2020 8:25 pm
- Location: Denmark
- Has thanked: 686 times
- Been thanked: 177 times
Re: HC-SR04
Hi Martin!
Yes, of course if can I will always help, also in my interrest
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
Jorgen
Yes, of course if can I will always help, also in my interrest

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

Jorgen
- Attachments
-
- HC-SR04_Distance_Sensor__Arduino_WORKING.fcfx
- (13.16 KiB) Downloaded 587 times
-
- HC-SR04_Distance_Pic16f876Working.fcfx
- (12.24 KiB) Downloaded 680 times
-
- Matrix Staff
- Posts: 1964
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 629 times
- Been thanked: 659 times
Re: HC-SR04
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.
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
-
- Posts: 3
- Joined: Mon Jan 11, 2021 10:42 am
Re: HC-SR04
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
I now downloaded the file for version 9 and will test it this week. Hopefully tomorrow.
Many thanks for the effort.
Theo
-
- Valued Contributor
- Posts: 1575
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 357 times
- Been thanked: 561 times
Re: HC-SR04
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.
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.
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.
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.
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
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.
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.
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.
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.
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