Distance to multiple objects

Hello, this is my first message in the forum.
I've never worked with Arduino before and I'm working on an idea that has many requirements and I don't even know if it's feasible.
The basic idea is the detection of the distance to multiple objects in a maximum distance of 1.5m with an error margin of 1cm.
The objects would be cylinders around the diameter of a AAA battery.
The objects would be stationary, I don't need to detect movement.
Quite a specific scenario...

I've been investigating and the best option for now seems to be HC-SR04 ultrasonic sensors modified to read the raw echo pin.
I was considering the option of using multiple sensors to triangulate the distance to the objects and improve the resolution.

The main problem is that all this is theory and I don't know if it is any near to the reality.
I don't know if an ultrasonic sensor is even able to detect an object of that size and shape to that distance (or to any distance in general).
If it can, I don't know if the 1cm margin is feasible even with multiple sensors working together. A bigger error would render all useless.
Maybe there is any other sensor that can perform this function and I'm pointing in the wrong direction.

I'm pretty lost on all this and I would appreciate any orientation.
Thanks in advance.

explain how you reached that conclusion?

image analysis sounds more suitable probably or a lidar (very directional)

One possibility: VL5130X TOF type sensor mounted on a servo to scan the area.

It's doable. Some years ago I have seen a blogpost where the onboard processor was replaced by a attiny. Output was basicly the intensity of the reflected ultrasonic wave over time so multiple onbjects could be detected - just like sonar or echolot. When you search the net you'l most likly find it.

Is this item in free space, or on a shelf or similar. What is around it? How is it supported? This may affect sound wave reflections.

What sort of finish does it have, that may affect light reflection.

along the same lines of questions : could an item be hidden behind another item (obstructed line of sight) ?

if you have only one sensor or not looking at the scene from "above'' then you might miss some items

I just found one way to get multiple object detection as described on this link Ultrasonic Radar Can Detect Multiple Objects at Each Ping - Hackster.io
It implies the use of ultrasonic sensors.
I didn't find a similar approach for other sensors like ToF or similar.

What I mean with "the best option for now" is that I've been unable to identify an alternative but not really that it is properly the best option (or even a good one :slight_smile: ).
I discarded image analysis because it's far over my capacity right now, too complex for me, so I prefer to be realistic and don't get into those waters.
I've been unable to find information on how to use a lidar sensor and its capabilities to detect multiple targets. When you say "very directional", you mean that the FOV of lidar is very reduced? I assume the need of a stepping motor for the sensor so being directional may be even an advantage. Can I get that 1cm level of precision with this?

Thanks for the link. I see that due to the use of light (laser in this case) the sensor capacity is very dependable on the colour of the target and the level of ambient light.
The range and precision drops drastically for dark targets outdoors, that's a very likeable scenario in my case.
I was considering the option of using an array of ToF sensors over servos as you suggest. The point would be if they would be able to detext a black AAA battery over a flat white surface at a 100cm distance with good accuracy. The targets are stationary so maybe the use of an array of sensors with the use of some maths can improve the accuracy of a single sensor in the same situation, but if they are not even able to identify that kind of target it would not work.

Thanks for the answer.
Part of the question is also about the capabilities of cheap sensors like HC-SR04 to identify the kind of target described with the parameters listed:

  • Cilinders of less than 1cm of radius
  • Stationary
  • Multiple colours (normally mate colours, not metallic or reflective)
  • Accuracy of 1cm

It is very specific and I've been unable to find any reference for this set of characteristics online.
People normally uses big target for their experiments so I don't know if those sensors can even detect that profile of targets.

Yes - ultrasounds are basically sent in a pretty large cone of waves and the further away you go the greater the area covered where you’ll get a hit… you might know that there is ar least one object somewhere there at 1.5m but it’s on a pretty large radius so you don’t know where the object is and it there is only one.

Now you turn your sensor 5° and scan again and you see also something there at about the same distance. Now you don’t know if it’s the same object(s) you hit the previous time or new ones.

With a very narrow field of view - think a laser dot which can have a diameter say of 2mm at 2m then you are more likely to hit only one object and the angle you are pointing to is much likely to be the right azimuth for this target.

The issue with very narrow laser like rays is that you need to have pretty small steps during the scan process and the geometry of the object can throw the bounce off and you miss it.

The most standard scenario would be this. Imagine a wood table outdoor, covered with a white paper tablecloth. I put the sensor in a corner of the table and then I place a set of multiple colour AAA batteries standing over their bottoms.
The batteries are standard ones, you know, aluminium painted of any colour.
The view is unobstructed but being outdoor may be another challenge.

Cylindrical batteries will be a challenge as their surface do not reflect incoming waves straight back at the sender

You would do better with batteries with a flat side like the 9V batteries and making sure their flat side is facing the sensor

That's totally correct. I'm always considering the need of multiple sensors in a kind of array to ensure that I have unobstructed view from at least one of them in any point of the plane.
But, as I'm struggling with how to make it work at all, I just avoid thinking on corner cases like that for now :slight_smile:.
If I ever manage to find a way to make this work, I think that working with 3 or 4 sensors forming a grid would solve the shadowing problem.

Unfortunately that's not negociable for me. :neutral_face:
The AAA batteries are just a simple lookalike of the real objects I want to detect. I thought they would be something universal and provide a very good representation.
I know it's going to be problematic because, regarless the radius of the object, the part of the object perpendicular to the sensor will be a think line on the cylinder. This is part of my doubts, if this kind of shape is detectable by standard sensors. You mentioned the use of cameras before, I considered that option initially precisely because of the shape of the object but I know I will not be able to complete a project like that, so I discarded that way of action.

Why not use a 3d camera? And OpenCV or YOLO for detection?

well you could get going with a simple set up

  • mount a narrow FoV sensor on a stepper motor with micro stepping capabilities
  • install that at the corner of your table
  • rotate from 0 to 90° by 1° or less and take a reading of the distance

as you spin your laser hit will be the various obstacles


and your output distance ranging scan will look something like this

so you can code a small state machine waiting for target acquisition, going over the target and then loosing the target and count that at one object.

Now if you are unlucky, objects might obfuscate each other partly. if they are not at the same distance you might be able to pick the discontinuity in the signal. For example if you have such a setting

it can probably be evaluated as two objects at different distances and overlapping

but if they are at the same distance and overlapping you will only see a longer signal than usual (assuming all objects are the same) but won't be able to say how many are there, or if aligned with the same azimuth then you won't see the far object.

so it's not fool proof, but would be a start.


PS: is that a school project?

Looks like it's this time of year again ...

What kind of comment is that? Did you read the thread?

Looks like a promising approach.
Fortunately, in the target scenario the elements to detect will be incremental. First none, then one will be set in scope, then a second one and so on. That makes the maths for detection much easier as you can apply the differential between readings to identify the location of the new object (and they don't move ever again, that's another advantage).
My doubts now lies on which materials are recommended for this experiment.
Basically, what step motor and what sensor could be right.
Do you have any experience on this matter? Any advice?

Regarding the school project... I guess I look much younger when I write in English, when I was in high school TNG was premiering on TV :grinning:. It is just curiosity, I always found arduino an interesting topic and I'm just using this idea I have in my head as a vehicule to learn about it, you are never too old to learn.

Thanks so much for your help!

I considered that option for like 10 minutes before realizing that I'm not smart enough to do it that way. :grinning:
I don't even know what YOLO is... I'll check it, I'm curious now!.