hcsr04 3x

77 views
Skip to first unread message

Hans van Veldhuizen

unread,
Feb 9, 2025, 11:04:43 AMFeb 9
to jallib
Hello, I have tried the hc sr04 and now have something in hand that needs three such sensors at the same time. Has anyone made something like this before?
greetings
Hans

Rob CJ

unread,
Feb 9, 2025, 11:35:23 AMFeb 9
to jallib
Hi Hans,

I did not make something like this but if you use the JAL library for the HC-SR04 you need to mutiplex the output of the device and connect the multiplexed signal to the interrupt pin of the PIC.

Next to that you need also need to multiplex the trigger signal that goes to each HC-SR04 module.

Kind regards,

Rob





Van: jal...@googlegroups.com <jal...@googlegroups.com> namens Hans van Veldhuizen <hanz...@zeelandnet.nl>
Verzonden: zondag 9 februari 2025 17:04
Aan: jallib <jal...@googlegroups.com>
Onderwerp: [jallib] hcsr04 3x
 
Hello, I have tried the hc sr04 and now have something in hand that needs three such sensors at the same time. Has anyone made something like this before?
greetings
Hans

--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/jallib/fe0e62b2-1bbb-43db-a9d8-50e84a814178n%40googlegroups.com.

rob...@hotmail.com

unread,
Apr 5, 2025, 11:22:13 AMApr 5
to jallib
Hi Hans,

I made a self driving Robot Wagon, just for fun, using three HC-SR04 modules. I am using the JAL HC-SR04 library for measuring the distance but since the library is made to support only one module, I am using an Analog Multiplexer IC (74HC4052) to multiplex the three sensors.


I also posted the project on Instructables: https://www.instructables.com/Self-Driving-Robot-Wagon/

Kind regard,

Rob


Op zondag 9 februari 2025 om 16:35:23 UTC schreef rob...@hotmail.com:

vsurducan

unread,
Apr 5, 2025, 12:30:30 PMApr 5
to jal...@googlegroups.com
👍👍
Hi Rob, that's reminds me a  car which does not fall from the table where ever it goes. It had no electronics whatsoever except a bistable relay and two front and two rear contacts. Much more elaborated is yours... Great.

Rob CJ

unread,
Apr 5, 2025, 1:12:36 PMApr 5
to jal...@googlegroups.com
Hi Vasile,

I remember that car. I had it as a toy. It worked completely mechanical. When it reached the end of the table it turned.

Could also buld it in this car 🙂.

Kind regards,

Rob


Van: jal...@googlegroups.com <jal...@googlegroups.com> namens vsurducan <vsur...@gmail.com>
Verzonden: zaterdag 5 april 2025 18:34
Aan: jal...@googlegroups.com <jal...@googlegroups.com>
Onderwerp: Re: [jallib] hcsr04 3x
 

Hans van Veldhuizen

unread,
Apr 5, 2025, 1:19:18 PMApr 5
to jallib
Hi Rob,
That looks impressive. The one I made has a camera on board so I can look under the furniture to see if there is dust. The speed is therefore much lower and I could do everything with one 16F648a. I did use a ready-made motor driver set.
This is of course much more professional. Very good.
greetings Hans

Op zaterdag 5 april 2025 om 19:12:36 UTC+2 schreef Rob CJ:

Hans van Veldhuizen

unread,
Apr 5, 2025, 1:28:25 PMApr 5
to jallib
20250209_205634[1].jpg

Op zaterdag 5 april 2025 om 19:19:18 UTC+2 schreef Hans van Veldhuizen:

vsurducan

unread,
Apr 7, 2025, 8:20:09 AMApr 7
to jal...@googlegroups.com
Hans, I have two cats for that purpose. More convenient.😏

zet.weeh

unread,
Apr 7, 2025, 10:10:11 AMApr 7
to jal...@googlegroups.com

Hi Rob

Fantastic that car.

I have not such a car and no cats but a vacuum cleaner.

Peter

image001.png
image002.jpg
Message has been deleted

Hans van Veldhuizen

unread,
Apr 10, 2025, 7:28:15 AMApr 10
to jallib
A while ago I made this radar toy. In my old way. I would like to adapt it now with the HCRS04 lib. I use the 16F877a and I tried to convert the sample for this. Of course I can't do that again.
Is it too much to ask to adapt the sample of 16F1827 for the 16F877a?
Greetings
Hans
https://youtu.be/kBK_Qo-Y4js

Op maandag 7 april 2025 om 16:10:11 UTC+2 schreef zet.weeh:

Rob CJ

unread,
Apr 10, 2025, 12:46:33 PMApr 10
to jal...@googlegroups.com
Hi Hans,

That should not be a problem. Why are you saying that you cannot do that?

Kind regards,

Rob


Verzonden: donderdag 10 april 2025 13:28
Aan: jallib <jal...@googlegroups.com>

Rob CJ

unread,
Apr 10, 2025, 12:46:38 PMApr 10
to jal...@googlegroups.com
Thanks Peter,

I also have a Robot Vacuum Cleaner but it does not work with Ultrasonic Distance Sensors.

I will also make a video about this project for more awareness (I hope).

Kind regards,

Rob


Van: jal...@googlegroups.com <jal...@googlegroups.com> namens zet.weeh <zet....@gmail.com>
Verzonden: maandag 7 april 2025 16:10
Aan: jal...@googlegroups.com <jal...@googlegroups.com>
Onderwerp: RE: [jallib] hcsr04 3x
 

vsurducan

unread,
Apr 10, 2025, 1:06:34 PMApr 10
to jal...@googlegroups.com
Rob, Peter, a vacuum cleaner does not tells you if you have dust or not under your bed. The cat mustache, it does.

Hans van Veldhuizen

unread,
Apr 10, 2025, 2:56:41 PMApr 10
to jallib
Rob,
When you get older it's not just the legs that get more difficult, the eyes that don't notice all the details anymore, but also more lumps appear in the gray stuff from above.
greetings Hans

Op donderdag 10 april 2025 om 19:06:34 UTC+2 schreef vsurducan:

Rob CJ

unread,
Apr 10, 2025, 3:48:01 PMApr 10
to jal...@googlegroups.com
Hi Hans,

You can send me your original file and I will see if I can change it for the HC-SR04.

Kind regards,

Rob


Verzonden: donderdag 10 april 2025 20:56
Aan: jallib <jal...@googlegroups.com>

Hans van Veldhuizen

unread,
Apr 10, 2025, 4:33:27 PMApr 10
to jallib
Hi Rob,
Here it is .
regards
Hans

Op donderdag 10 april 2025 om 21:48:01 UTC+2 schreef Rob CJ:
16F877a_RADAR_2.jal

Rob CJ

unread,
Apr 11, 2025, 1:45:36 AMApr 11
to jallib
Hi Hans,

Attached the version using the HC-SR04. Your original version gave compiler warnings but I kept those. They are not releated to this change.

Give it a try to see how it works. The distance is measured in mm.

Kind regards,

Rob


Verzonden: donderdag 10 april 2025 22:33
16F877a_HC-SR04.jal

Rob CJ

unread,
Apr 11, 2025, 1:51:52 AMApr 11
to jallib
Hi Hans,

Forgot to mention. The echo pin must be connected to pin_b0, the INT pin of th 16F877a.

The trigger pin is the same.

And there was a type so attached with the fix.

Kind regards,

Rob


Van: jal...@googlegroups.com <jal...@googlegroups.com> namens Rob CJ <rob...@hotmail.com>
Verzonden: vrijdag 11 april 2025 07:44
16F877a_HC-SR04.jal

Hans van Veldhuizen

unread,
Apr 11, 2025, 5:36:52 AMApr 11
to jallib
Rob,
Cannot use this , pin_B0 is attached  to the display.

 Have tried to convert your sample. Loaded in another set. I got a lot of strange characters,.


Op vrijdag 11 april 2025 om 07:51:52 UTC+2 schreef Rob CJ:
16F877a_hcsr04_serial.jal

Rob CJ

unread,
Apr 11, 2025, 7:11:53 AMApr 11
to jallib
Hi Hans,

The library also supports the use of an interrupt on change pins and in your case that would be pin_B6. But I saw that the PIC you are using uses IOC differently so I think that will not work.

You are currently using pin_B0 as chip select. Can't you change that to any other pin so that B0 can be used as interrupt?

BTW: I posted the Self Driving Robot Wagon as a project on Youtube for anybody who want to build it and to promote JAL: https://www.youtube.com/watch?v=EaIO6-hiUwA

Kind regards,

Rob


Verzonden: vrijdag 11 april 2025 11:36

Hans van Veldhuizen

unread,
Apr 11, 2025, 1:15:52 PMApr 11
to jallib
Hi Rob,
I'll stick with my old approach. It's well within the range of the sensors themselves. Thanks again for the effort you've made for me.
 Good luck with your car.
goeten
Hans

Op vrijdag 11 april 2025 om 13:11:53 UTC+2 schreef Rob CJ:
Message has been deleted
Message has been deleted

Hans van Veldhuizen

unread,
Apr 13, 2025, 3:22:13 PMApr 13
to jallib

Hello Everyone,
"Why make it difficult when it can be easy!!" my wife often says to me.
This way I now measure a distance of 1 meter. Theoretically that is 5847 uS and I measure 5813!!
No problem to put this three times in one IC!!!!!
---------------------------------------------------------------------------------
const STOPWATCH_MIN_VALUE = STOPWATCH_US -- (STOPWATCH_NS is default if not defined)
const STOPWATCH_USE_TIMER = 1 -- (1 is default if not defined)
include stopwatch
stopwatch_init()

procedure is DISTANCE_2
distance_L = 0
TRG_L=high
delay_10uS(3)
TRG_L=low
 while ECH_L == low loop end loop
 stopwatch_start()
 while ECH_L == high loop end loop
 stopwatch_stop()

 afstand_L = (stopwatch *171)/1000 ---in mm
end procedure

She was right again!!
Greetings
Hans


Op vrijdag 11 april 2025 om 19:15:52 UTC+2 schreef Hans van Veldhuizen:
Reply all
Reply to author
Forward
0 new messages