Page 1 of 2
SR04 Ultrasonic Sensor
Posted: Sun May 05, 2024 1:52 pm
by chipfryer27
Hi
Did a couple of tests today.
Set up FC pretty much as the example file using a PIC18877 with trivial modifications to suit.
Set up a little test rig to measure distance from sensor to target. Rig holds the sensor at 90' to target, vertically, with very impressive results for such a module and my accuracy was greater than +/- 1% (bear in mind we count in cm).
These images show measured at 117 with reading of 118 (sorry, can't figure out yet how to rotate).

- 100_0224.JPG (92.13 KiB) Viewed 7387 times

- 100_0223.JPG (91.66 KiB) Viewed 7387 times
Reaching 140cm all was still good, reading showed nothing of concern.
Attached are reading and pulse trace.

- 100_0226.JPG (75.61 KiB) Viewed 7387 times

- 140cm.jpg (48.74 KiB) Viewed 7387 times
Now the fun begins. At anything above 140cm the readings start again at zero. At a measured 144cm the readings return 4cm. The pulse width suggests that not to be the case.

- 144cm.jpg (46.96 KiB) Viewed 7387 times
If I hold a clipboard underneath the sensor it returns the distance to target, but once above 140 it starts again from zero.
This pulse is at 190cm with reading showing 50cm

- 190cm.jpg (47.62 KiB) Viewed 7387 times
This is measured at approx 270cm. Reading shows 132 (if you add in 140 then it's still with +/- 1%)

- 270cm.jpg (50.32 KiB) Viewed 7387 times
I'm guessing some variable within FC has rolled over or the like.
Regrds
Re: SR04 Ultrasonic Sensor
Posted: Mon May 06, 2024 2:54 pm
by medelec35
Hi Iain
Many thanks, for report.
Out of curiosity, are the results the same for timer and non-timer versions?
Re: SR04 Ultrasonic Sensor
Posted: Mon May 06, 2024 3:24 pm
by chipfryer27
Hi Martin
Sorry, only tried timer didn't check non-timer . I will try next time I'm in the evil lab. I also tried just the example file but it too does the same (just in case I'd missassigned a variable or such).
Watching the analyser, the module even detects the angle being adjusted slightly. It's an impressive little gadget.
Regards
Re: SR04 Ultrasonic Sensor
Posted: Tue May 07, 2024 9:09 am
by medelec35
Hi Iaian.
I have just tried the sensor at greater distances.
Results for 277cm:

- SR04 Sensor1.png (13.95 KiB) Viewed 7353 times
I have noticed that reflections on nearby objects affects the reading the great the distance which is expected.
I.e. the further the object the wider the band.
What I would recommend is do what did, also have UART output that states the distance so both distance reading and pulse width can be matched together.
Re: SR04 Ultrasonic Sensor
Posted: Tue May 07, 2024 9:01 pm
by chipfryer27
Hi
Yes I did expect the pulses to diverge with distance but it did not appear to affect anything at all in my test set up, as it was not always in the same position relative to surrounding, but did always have fun above 140. Just to be clear at 140cm all good, at 141cm it reads 1cm and increases accordingly (144cm = 4cm) Nothing is suddenly that close to the sensor. Pretty sure I would see it
When I'm next at it I can do the UART, but you can perhaps see from the pulses I already sent that the pulse width is increasing with each test suggesting it has not caught something only a cm or so from the sensor (sensor increasing in height from floor).
Regards
Re: SR04 Ultrasonic Sensor
Posted: Tue May 07, 2024 9:30 pm
by medelec35
The reason, I suggested the UART as well is because I noticed the display changing from say 160cm to 50cm then back to 160etc.
As it happens the pulse was also showing it was 50 cm, so then can be ramdom changes dure to sound bouncing of objects that are not in the line of site.
Of course, if the UART just after the pulse does not agree, then I will see if I can get to the bottom of it.
Re: SR04 Ultrasonic Sensor
Posted: Tue May 07, 2024 10:37 pm
by chipfryer27
Hi
"Me" moving around the PC to "capture" may have been in the picture so to speak when triggering / grabbing a pulse trace, but when only reading the display I'm not really near it.
The sensor loops at one second intervals so I see when I or anything else is detected.
If me, at 140 / 144 (140 / 4 on display) I would need to have moved to within four centimeters of the sensor, and after adjusting it to different heights all the way up to the maximum I documented above, moved back to exactly the same position each time which is extemely unlikely. As I repeated the tests it is again extremely unlikely that I'm the cause.
In the traces above they document 8.xxxx / 11.xxxx / 15.xxxx mS which equates to roughly 1.4M to 2.7M, but at no time did the display ever show anything above 140cm before starting again at zero.
Probably Thursday before I can retest and will send more results then.
Regards
Re: SR04 Ultrasonic Sensor
Posted: Sun May 12, 2024 2:28 pm
by chipfryer27
Re: SR04 Ultrasonic Sensor
Posted: Sun May 12, 2024 4:13 pm
by mnfisher
That's one good looking lab. How goes the trs-80? And where did you hire the apprentice

Re: SR04 Ultrasonic Sensor
Posted: Sun May 12, 2024 4:46 pm
by chipfryer27
Hi
Lab is in a bit of a state just now, in the process of a good clean out, getting rid of the "might come in handy" pile amongst a LOT of acquired useless junk.
That's my "Ivory Tower" up in the clouds, i.e. the mezzanine floor I built to elevate my status
Scopes / analysers / soldering / test equipment / anti-static work areas and general benches all live up there with me whilst below I have CNC / milling / lathes / bandsaw / metal-bending and all other stuff you'd expect.
I do a lot of Proof-of-Concept and prototyping, but could also undertake small productiion runs if required.
I got the TRS-80 running but struggeled to find a use. I did think on building a generic interface that could plug into the expansion port but then thought "why" as even a modest PIC would outperform, so I'm still looking for a project to use it with.
My zombie used to be a minion but it displeased me so now it is undead. This came in handy as I needed help to test a sensor I was using as part of safety feature on a gun that would travel at speed. Before setting off it would check that nothing was present in the path and if anything did then appear it would come to a halt. I needed a human size target and also a "hand" to check it did come to a halt without endangering me
Regards