Need help in finding the right range sensor

Hello community!

Hopefully this question won’t be too complex and complicated.
First off I am no engineer, just an aspiring one. I don’t have any education within the topic of robotics or electronics. I have on the other hand, an immense drive to learn and curiosity.
So if I seem like an absolute dummy, that’s because I am. I hope that won’t be too bothersome, and I highly appreciate the help you’ll give!

So let me explain. I am working on a project which requires me to measure the distance of a person walking towards a “box” I have placed along a walkway. It’s not literally on the ground, it can be placed anything from 1-3 meters high, whatever’s best. I have looked into a lot of different sensors like PIR, Ultrasonic, TOF, LIDAR etc. but I’ve yet to figure out what would be cheapest and best for the task. As I said, I’m not super knowledgeable about all of this.
The box isn’t powered by cable, so it’s limited to a 12v battery, with AH ranging from 20-100 (whatever’s needed) but also charged by a solar panel. It doesn’t have to measure distances constantly, as there aren’t people walking past the box all the time. Maybe 3-5 people every 20 min ish.
I have made a picture in paint (very professional ikr) which shows what I was thinking and how it would work etc.

Here is a gyazo link: https://i.gyazo.com/dd54b8439e2ebb40c3b0ba1ec50a568f.png (hopefully it doesn’t get deleted)

Basically, I think I would need 2 sensors. One for accurate measurements close by (5-8 meters) with a wider FOV, and then 8-20 meters with a more narrow FOV.

Again, thanks a lot for any reply and help!

Hi Polydorf,
I don’t have a complete answer for you but I have some observations and advice.
First, I don’t think you are going to find any sensor or sensors that fully meet your requirements. Certainly not inexpensive ones. There are several reasons I say that, but the biggest one is your insistence on accuracy rates. Real-world sensors simply don’t have the ability to “know” what they are measuring and whether it is “valid” (within YOUR criteria) or not. They just measure the distance to the closest object within their field of view without any knowledge of whether it is something you are interested in or not. Most of them also do not have any way of adjusting their “sensitivity” and even if they did it wouldn’t solve your problem. That’s because the environment changes so that under some conditions what appears uninteresting will become interesting under other conditions. But all is not lost – we have incredible amounts of compute power available at low cost now. I will come back to that.
Next, you give a lot of good information in your diagram but you left out some important parts.You don’t mention the angles of your field(s) of view or the width of the path so that they could be calculated. Also, in the diagram, you draw the angled areas you are interested in, but you don’t mention if the long range sensor should be able to measure something “close” at the far side of the path.If its field of view covers the full width of the path at max distance (20m) it will only cover 1/4 the width at 5m. You also don’t mention the max speed of approaching targets. You mention walking which usually means a max speed of something near two meters per second. But specifying it is important.
Third, in your writeup you mention the sensors should only measure when the object is certain distances away. But that’s backward. The sensor has no way of knowing how far away it is until it measures it. Perhaps what you meant was that the sensor should only report certain distances.
The general, but non-trivial, solution to most of your problems is to add “intelligence” to the sensors. In other words, attach some sort of computer that controls the sensor(s) and processes the data to determine if it is within your criteria and valid. The hardware is simple enough. The software will likely be quite complex to meet your requirements. You may want to revisit your requirements and see if you can get away with less stringent ones.
If I were building this I would most likely use ultrasonic sensors attached to an Arduino or two. It might take as many as five or six ultrasonic modules, but they are cheap. They have a fairly wide field of view that you will need and they are fairly robust, especially when backed with proper software. They are also immune to light changes (unlike optical sensors) and fairly immune to external sounds.

1 Like

Hey, and thanks for your reply!

I was expecting that, I think for one sensor it would indeed be a bit much to ask. A good combination would probably work best, and the pricing is not too important atm. But ok, I see. The accuracy rates might be a bit demanding as you say, and what you mention about sensors in general on how they function. I was thinking maybe a thermal camera could detect/calculate the amount of heat it reads, and then assume this is a human walking towards it. But I’m probably way off there. I’m starting to think I might need a camera with some software that can detect humans, and maybe designate zones in the “camera shot/picture” aka what it sees, as 20m, 15m, 10m etc. and have it trigger a command in the software when larger movement is detected in those zones. Or am I totally off?

And yes sorry, I should have included the FOV’s. The width off the path is no more than 2 meters wide, maybe 2.5m. And no, at 5 meters, the “green” sensor would detect whatever is in it’s FOV. The red sensor would at that point just return anything that close as a “negative”, if that were possible, by maybe reading off the amount of reflection of the surface or something. The max speed would be 80km/h, as I want it measuring cars as well, but for the first prototype it would be fine to just get it working on a walking path with max speeds of 12km/h (some person running).

Ah yes, well you are spot on there, I meant that it’s to report certain distances. I assume the sensor basically “looks” forward 20m, and then reports anything coming into it’s FOV. I was thinking a bit like a simple laser measures distances. You have one guy on the other end of it walk towards it, and as long as you hit him it will report back fairly accurate and quickly down to the cm in some cases. I tried this with one of those you use on construction sites to measure correct distances and that things are level.

But I do indeed like your approach by just adding intelligence to it. I’m no programmer but I’ve done some very simple coding and I think I could figure it out given time and some good guidelines. Like you say with setting less requirements, I think I would first build the device with the program to detect any movement, then fine-tune it from there.

I’m not sure if you are allowed to suggest any product, but if you could link any of the products from this website that would give me what I need to get started that would be great. And would it maybe work if I programmed 3 sensor to send a signal once someone crossed into it’s range?
So let’s say 1 sensor measures 10m (this one: https://www.robotshop.com/en/maxbotix-hrxl-maxsonar-wrlst-weather-resistant-ultrasonic-range-finder.html

Then I have this sensor measure anything in it’s 5m range: https://www.robotshop.com/en/maxbotix-hrusb-maxsonar-ez0-high-performance-sonar-module.html

And lastly, this sensor sends a signal at anything coming into it’s 3m range: https://www.robotshop.com/en/parallax-ping-ultrasonic-sensor.html

I guess it’s a bit simple, but it would be reliable and work wouldn’t it?

That alone is a significant project that still doesn’t give you distance. Consider how much work it is (when did it first become practical on a PC?) just to recognize a human in an image. To the computer it is image processing just like visual image processing. OpenCV would probably be useful. But consider what happens when the ambient or background temp is nearly the same as a human (don’t know where you live but that’s quite common here) or the human has part or all of their body shielded to heat (a jacket, etc. Something like a Kinect might be useful. But in any of those cases you are looking at a LOT of software.

Ultrasonic sensors would cover those angles pretty well. The better (more expensive ones) would also cover the longer ranges well. Most of them have a detection zone about 15 degrees wide and a bit less high. Your far zone is about 0.1 Radians or 6 degrees wide. Any type of optical sensor will need either a lot of sensors or a scanning mechanism to cover that width.

This is a problem. At 80 kh/h the object is moving at a little over 22 m/s. Your desired resolution is about 1m per your specs, which means that in 50 milliseconds it will move from one range to the next. In that amount of time you have to measure that particular spot. A general rule of thumb is that for decent measurements you need to be about ten times as fast (gives a best case ± 10% accuracy) which means you have to measure EVERY spot about every 5 milliseconds. that’s way too fast for ultrasonic (sound doesn’t move fast enough) and a scanner would have to scan REALLY fast. That leaves pretty much some type of array of sensors working in parallel. Cameras are array sensors. But as I mentioned they don’t give distance. Your brain approximates distance with TWO cameras and LOT of processing with other clues to help.

That is pretty much a necessity. In one form or another the “intelligence” will have to be added. Either as a microcontroller attached to each sensor that sends the processed information to a main computer, or a main computer that reads all the sensors and processes the data itself, or some analog or logic circuits that do the same thing (which is very complex and NOT recommended.)
One idea that comes to mind is a camera, a fairly powerful computer running OpenCV, and a laser distance sensor on a moveable head. The computer could use OpenCV to detect a human in the field of view, then moves the laser sensor to the center of the target to measure the distance and track it as it moves through the field.
I’m not really familiar enough with any of the commercial sensors to make a good recommdation. Perhaps one of the Robotshop employees can. Some of them are very familiar with most of the sensors. I believe some other members here have some good experience with them as well. If you can’t find anyone else to make a recommendation I will give it a go, but I would prefer you get better advice than I can give.
From everything you have said I do think the camera with OpenCV method would be a good one to pursue. But do keep in mind that various things like weather are going to play havoc with any kind of optical device. Does it snow where you are?

Yeah you are right, thermal might not work that well and require too much power as well.

Ultrasonic sensors does seem to be the way to go indeed, to cover those angles.

Well for cars it wouldn’t need to have 1m intervals, every 20m would do in that case, or just that it detects a car moving towards it, doesn’t matter how close or far. A simple laser pointed that way would be enough to get that to trigger I assume?

Well having one processor which processes all the information together would surely be best don’t you think? For the sake of complexity and price I mean. Or would it then require too high amounts of power to run from a battery?
The idea of a camera and laser seems a bit too mechanical but I like the approach. But what would “a fairly powerful computer” mean? I’m assuming a Raspberry pi 3 isn’t really “powerful” in any sense. I was thinking about the tech CCTV uses, and I saw someone using OpenCV to track pedestrians too, and that’s very close to what I would need.

I did poke around a bit and found some sensors, but it’s hopeless unless I know the limitations and complete possibilities. I’ll ask around, thanks :slight_smile:

Yes, a single laser rangefinder would probably work most of the time. But do consider the weather.

An Ardunio is a lot more powerful than most people realize. Consider that personal computers existed for about 15 years before they could match an ARduino speed-wise. Memory is a different story. If you use ultrasonics and maybe a laser rangefinder an Ardunio should be sufficient. A Rapberry PI will take about 10 watts of power. That’s a lot more than an Arduino (around 1/4 watt) but still not a huge amount. A 12V / 20 AH battery provides 240 Watt Hours so would run a PI for something around 24 hours with no help. It isn’t quite that simple, but that’s a decent approximation. But an Arduno can do an awful lot if programmed properly.

I was a bit vague intentionally. “Fairly powerful” will depend on a lot of things. A single camera with your requirements could probably be handled by most newer Raspberry Pi models. It depends mainly on what all you ask it to do. A moving pedestrian doesn’t move that fast so processing time isn’t that critical. A car, though, could easily be out of your field of interest before the computer realizes it’s there.

Personally, I recommend you keep it simple. An Arduino with a small number (maybe 3 or 4, whatever is required) of ultrasonic sensors. Try that first. It’s a low investment so if it doesn’t work out you haven’t spent much money and you can still use the parts for lots of interesting things. And if it works, great. If not, you will learn a lot about what you DO need. An old adage in programming is “build the first one to throw away.” The moral being that you seldom get it right the first time, so plan on learning from the first one and getting the second one right.