Laser vs Ultrasonic - TOF10120 vs. HC-SR04

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today in the workshop we'll compare the performance of ultrasonic versus laser distance sensors will match the HC s r0 for ultrasonic sensor against a tof one zero one two zero laser time' flight sensor and we'll see who's best we're going the distance today so welcome to the workshop hello and welcome to the workshop and today we've got a bit of a competition going here in the workshop we're going to be testing two different distance sensors and comparing their accuracy and for that we've got this wonderful testbed sitting here on the workbench which shall explain in a few moments now the two sensors we are going to be checking I'll have two different technologies one is the old faithful eh CSR 0-4 and that uses ultrasonic sound but we're also going to be testing another sensor that we haven't worked with before it's a tof one zero one two zero and this uses a laser beam in order to do its sensing and so it should be a bit more accurate than the ultrasonic one or so we think let's see what happens here on the testbed so what we're going to do today is we're going to look at the two different sensors I'm going to show you some quick sketches that we can use to test the distance with the sensors because that's all we want to do and then I'm going to put them on the test bed over here and test them in a bunch of preset distances to see which one really is the most accurate so let's take a look at those sensors right now now let's go the to distance sensors we'll be using today DHCS are 0-4 is an ultrasonic distance sensor the tof 1 0 1 2 0 is a laser distance sensor or time-of-flight sensor both of these devices work on principles of signal reflection and signal delay period DHCS are 0-4 has a rated range of two centimeters to 400 centimeters it has a working voltage of 5 volts DC and a working current of 15 milli amperes the dimensions of the FCS are zero for our 45 by 20 by 15 millimeters the device uses a series of 40 kilohertz ultrasonic sound pulses it employs two ultrasonic transducers the pin out of the HC sr0 for is as follows the VCC is the five volt DC input the trig is the trigger input the echo is the echo output and the ground is the ground pin the tof 1 0 1 2 0 has a rated range of 10 centimeters to 180 centimeters it's working voltages 3 to 5 volts DC and it's working current is 35 milli amperes the tof 1 0 1 to 0 has dimensions of 20 by 13 by 5 millimeters it uses 940 nanometer wavelength light pulses the device employs VCSELs vertical cavity surface emitting lasers the tof 1 0 1 2 0 comes with a cable that is color-coded the black wire is the ground wire the red wire is the power supply of 3 to 5 volts DC the yellow wire is the serial received line the gray wire is the serial transmitted line the blue wire is the i2c data line or SDA connection and the green wire is the i2c clock or SCL line DHCS are 0-4 has a lower cost than a teal f-101 to 0 the tof 1 0 1 to 0 is sealed and can be used in a number of different environments that the HC sr 0 4 cannot be used in the HC s are 0 4 has a 1 pin or 2 pin digital i/o connection the tof 1 0 1 to 0 has either a serial connection or an i2c bus connection the tof 1 0 1 to 0 is much smaller than the HC sr 0 for the tof 1 0 1 to 0 also has a much quicker response time than the ultrasonic unit the HC SR 0 4 has a much wider field of view than tof 1 0 1 to 0 so now let's meet the contestants in today's match okay these are the two distance sensors that we're going to be pitting against each other today and I'm sure you're very familiar with this one this is the HC SR 0 4 it's the ultrasonic transducer and it uses an ultrasonic transmitter and an ultrasonic receiver it's got 4 pins on it VCC ground and then one labeled trigger and one labeled echo and you can actually tie the trigger and echo together over here and just use it in what they call three wire mode if you wish these are really inexpensive you can get them pretty well anywhere your local electronics store will have them so does Amazon and eBay and pretty well all the regular places you buy parts 11 HC SR 0 for now this is starting to become more common it comes in this nice little plastic case over here this is the tof 1 0 1 2 0 and this is our laser sensor now in the case to give you a bunch of these wires which are basically connected to a little connector for the sensor and then it's got a bunch of female do pops on the other end and so that's going to be very handy and they give you the sensor itself and also a couple of mounting screws now this is the sensor now look at the size of that compared to the HC SR 0 4 isn't that amazing that is tiny and I don't know how well you can see this but this sensor is pretty well all self encased over here there's no moisture or anything dirt that's going to get inside there all you have to do is keep this lens over here clean and it's got a tiny connector on the back that makes with the one over here and this is much more expensive than the HC SR 0 4 but it's starting to become more and more common I've seen these it pretty well all of their major vendors including Amazon and eBay of course and so they're not that hard to get as well and so there are our two contestants in our little challenge today ok so now that we've taken a look at both of the sensors it's time to actually start using them so I want to hook them both up and write some code for them and that's exactly what we're going to do now on the topic of the code for the two sensors it's a bit different for both of them takeo f1 0 1 2 0 is something I found very difficult to find documentation on and I'd say that's one of its biggest flaws right now is there's very few notes about using it there are diagrams for hooking it up and there's one piece of code that's floating out there that a fellow has up on his website claims he got it from a Chinese website but doesn't actually call what website it was and so that's basically the only code that's out there however it is enough code to read the distance off of the sensor and you could incorporate the functions in that code into your own so I'm going to be hooking up that sensor and showing you that code for the HC SR 0 4 we're going to use some code that we've seen before we're going to use code from the episode that I did on the HC sr0 4 and we're also adding another component to that 1 we're going to add a DHT 22 temperature and humidity sensor because since that sensor uses sound waves the speed of sound can be affected by the temperature and humidity so we're going to factor that into our equation just to give the HC SR 0 for every chance it can to compare against our laser sensor so let's go and take a look at the hookup and the code for both of these devices now and then we'll run them through some quick tests for our ultrasonic distance measurement experiment will require an Arduino Uno an HC SR 0 for ultrasonic distance sensor and a dht22 temperature and humidity sensor we'll begin by connecting the 5 volt out of the arduino to pin 1 or VCC of the DHD 22 we'll also connect the five volts to the VCC of the HC sr 0 for ultrasonic distance sensor we'll connect the ground from the Arduino to the ground of the dht22 which is pin 4 we'll also connect the ground to the ground of the ultrasonic sensor next we'll connect pin 10 of the Arduino to the trig input on the ultrasonic sensor we'll connect pin 13 of the Arduino to the echo output of the sensor finally we'll connect pin 7 of the Arduino to the data pin on the dht22 and this completes our wiring now here's a blast from the past this is from the drone bot workshop back in 2017 and it was early 2017 because it was still HTTP and not HTTP so this was something I use in a video that I did much earlier on the HC sr 0 4 and if you'd like to learn more about the sensor or learn more about this sketch and some other sketches like it in detail I would urge you to watch that video but I'll go over some of the key components of this sketch now basically all the sketch is doing is it's pulling back the distance from the HC SR 0 4 we're using it in what's called 4 wire mode so we're got the trigger pin and the echo pin going to separate pins on the Arduino rather than tying them together and just tying them to one Arduino pin and we're gonna be using a library called new ping now when I first talked about this sketch a couple of years ago I gave a source on bitbucket I believe to download new ping what if you could still do but you can also now get the new ping library in the Arduino library manager and so that's something to keep in mind that you don't have to download a separate file for it you can just grab it up in your library manager you can also grab this DHT library the Adafruit PHP library now this requires the Adafruit unified sensors library so that's very important you won't be able to run it will compile and give an error because it's looking for the Adafruit sensors unified library and again you get all of those up in your library manager now basically the sketch defines a number of constants what the sketch is doing is it's reading temperature and humidity from the dht22 and it's also reading the time duration off of the sensor and it makes use of the new ping library to get that duration it actually makes a couple of pings and it takes the average of them and so it's using that temperature humidity and duration value to calculate the distance because the speed of sound is affected by the temperature and humidity so the temperature sensors on pin 7 and is a type dht22 and these are the two pins were using for the HC s r0 for a ultrasonic sensor and we also define a maximum distance for the sensor of 400 centimeters which is four times the distance we need for today's tests and essentially we go through all the code on the other video so I'm not going to go through the line by line except to show you the key part over here is that we are calculating the speed of sound in meters per second using this equation over here with factors in the temperature and the humidity and then we convert that to centimeters per microsecond and then after getting that value so we know the value of time that it takes through the sound to travel we get the duration by calling the new pin library that's with the sonar object is and we call the library to get the actual duration of the pulse and then we have the half at of course because the pulse is going there and back and we can't use that to calculate the distance and so that's going to be the distance in centimeters of the of the pulse travel and so this is the sketch we're going to be using to demonstrate the HCS r0 for let's take a quick look at it in action and then after that we'll put the ball together and have our battle between the distance sensors and so this is our demonstration with the HC s r0 for ultrasonic sensor as well as dht22 temperature and humidity sensor and it's just a basic demo we're going to do right now to make sure work so we can watch the serial monitor and I'll place this tablet in front of the sensor and we have to give it some time to settle down it looks like it's done that now at sixteen point four four centimeters which is probably correct and I'll move my tablet back over here again you'll notice that the readings come about every two seconds and that's by design you have to let this sensor stabilize a bit now you could probably do it every one second but not much more than that and so this is stabilized about thirty five point one two centimeters and so this seems to be working fairly reliably and so this is the circuit that we're going to be using when we test the HC SR zero four for our next test we're going to require an arduino uno and the tof one zero one two zero time of flight laser sensor we'll connect the cable to the time of flight sensor and then connect the red wire to the arduino z' 5 volt output we'll connect the black wire to the Arduino ground we'll connect the blue wire to the a4 pin on the Arduino analog input this is also the SDA line of the i2c bus and we'll connect the green wire to the a5 pin which is also the SCL line and this completes the wiring so this is a sketch that we're going to be using with the tof one zero one two zero and it's a basic demonstration sketch that simply uses the serial monitor to display the distance that the sensor is reading in millimeters which is exactly what we want for our test now this sketch is not of my own doing I got this from someone called Serdar Tech who has this on both his website and on his youtube channel however he claims he got it from a Chinese website that he does not quote the actual link to so I can't give credit to the original author I'm afraid but there is a not a lot of documentation for this sensor so this was basically all I could really work with right now and it's enough to use in one of your own sketches now the sketch includes the wire library which is the Arduino in library for working with i2c so you don't need to install anything extra because that's already and your arduino ide and basically what the sketch does is this integer called x is going to call a function which is written below called read distance and that will pull back the distance from the sensor in millimeters and it's just going to display that onto the serial monitor which is what we want to do but if you look down here you'll see the read distance function at the bottom over here and it calls the sensor read function and if you go through this you can actually see what's happening it's basically using the wire library to transmit out to address number 82 which is where the sensor lives and it basically requests some data from the sensor it waits for the data to come back from the sensor and then it reads the data and data comes in multiple bytes and it puts those bytes into a buffer which is then read out by that read distance function and then you can call it from up here so you could use all of this code down here in your own sketch so it's a basic sketch and it'll do exactly what we want it to do so let's take a look at it in action now so here's our demonstration the tof one zero one two zero a laser sensor now I've got the sensor just lying on its side here right now it's connected to the Arduino using its little connector cable the connector cable comes out in female DuPont connection slightest views small jumper wires to connect it directly to the Arduino I'm only using four of the connections because I'm using the i2c connections the other two connections are for a serial connection to the sensor and they're not being used right now and as you can see we're getting a reading on the serial monitor now remember this readings in millimeters and not centimeters so you would have to add a decimal point between the last two digits to get it into centimeters so let's just try placing this right in tablet kind of in front of it and we're getting a reading of about a hundred and forty eight millimeters which would be 14 centimeters which looks about right I'll just move it back but over here and now their readings gone to about 300 millimeters which would be 30 centimeters and so it seems to work now one thing that you will notice is that this responds fairly quickly to movement we're getting readings back here pretty frequently and that's because it doesn't take very long to reset one of these sensors based upon a laser and using light as opposed to one using sound and so this is the setup we're going to use in our demonstration today all right well now it's time to get on with the actual competition and so I want to show you the testbed I'm going to be using the test our sensors out now this is the official drone bot workshop sensor testbed and it's made out of genuine scrap wood from around the workshop now what I've got over here is a long piece of wood and on it you can see I've got a number of other pieces of wood that are glued on and you might be able to see these numbers over here and these are marked off in positions of centimeters and what I have over here is I've got this two sided block now this side over here has a piece of plywood on it so it's a very smooth surface this side over here has a foam surface on it it's a bit absorbent to sound it also isn't a smooth surface to cast light on and it's been designed so that I can place these into here and right now for example I'd have the foamy side facing our sensor now the sensor is going to sit down over here this line here is actually the zero line but what we are going to do for every one of our tests we can move this both ways in each of the positions is we're going to set up at 25 centimeters over here now I'm going to use 25 centimeters as the reference so what I'm going to do is set this at 25 centimeters and then adjust the position of my sensor until I read exactly 25 centimeters so that'll be the reference point and then we will take it from there we'll move the partition back and forth and as you can see we move it all over here and we will take readings and so there's going to be there's five different readings we've got here ten twenty five fifty seventy-five excuse me and a hundred centimeters with is a meter and we have both sides of course of the reflectors so there's ten measurements we'll be taking for each sensor and we will see how accurate they are now this is as accurate as I could make it I used two rulers and a t-square for it so I think that's down to about a millimeter or so accuracy and on these blocks over here not sure if you can see that but I've got these little blocks put here and that stabilizes this thing so that it doesn't you know fall one way or the other it doesn't tilt and so I've tried to make it as accurate as possible obviously it's not a laboratory grade test but it's more of a real-world test so let's go and put our first sensor on the test bed and see how it works so we're now testing the T 0 F 1 0 1 2 0 laser sensor and I've got myself set up on the calibration point right now the 25 centimeter point and we're reading pretty well 25 you'll notice their readings bounce around a little bit a few millimeters I'm not entirely sure why that is because when I keep this perfectly still it does that as well so I just guess that's part of the whole business any rate this is pretty close to 25 now let's go into 10 now 10 centimeters is a hundred millimeters and that's the minimum range that this is rated for so right now it's actually a little low it's reading about 94 92 in that neighborhood and this of course is with the reflective side let's go to the 50 mark and see how it works it's pretty close it's it's yeah 49 50 49 50 it's quite close at the 50 mark it's relatively good over there move it back to the 75 mark and I would say that's off by quite a bit at 75 it's down around 70 71 so it's off by you know a good 4 centimeters about now they do mention on the application notes that the performance varies because of different light levels because of different reflective surfaces I did try putting a white piece of paper on this I've tried turning off the room lights it really didn't have any effect on the reading that I could tell and finally we'll go back to the 100 mark over here and it's well off over there it's it's reading about 88 sometimes 90 it's it's well off I don't think it's picking me up I'm gonna move as far away from it as I can this one has a fairly narrow field of view so it really doesn't pick up very good after 75 let's go back from the beginning with the foamy side and this reading is a bit higher and it's exactly what I was suspecting what's happening over here is that it's actually bouncing off the board at the back and not the front of the foam so the light is actually travelling right through the foam and ignoring it so if you have a big wall of foam it's not going to see it at 25 I think we'll see the same effect yes it's reading more like 26 a game because of the thickness of the foam and we're back at 50 right now it's like you very close in at 50 still tends to read a tad high I think it was reading a tad a little before and of course I think once we get back here to 75 the hour from here on in it pretty well is giving some pointless readings and so there you go that's the tof one zero one two zero laser sensor test so here we are with our contender the HC sr 0 4 along with its companion a dht22 temperature and humidity sensor and I've got it set up right now very very close to 25 centimeters and I've always been curious as to whether it was the front of the transducers itself or the very front of the sensor where that was measured from and it does seem to be just about the front of this answer from what I can see with my eyeball here right now and this limited test let's move down to 10 right now and see what we get and let it stabilize will that let to stabilize a couple of readings it's very close ten point one ten point zero three if you're looking for centimeter resolution it's very very close at ten that's very impressive and we'll move back up to 50 and I'll get a bit out of the way too in case I'm affecting it and that's not too bad forty-nine point five eight again once it stabilizes very close let's move it down over here and get you out of the way okay over here I don't seem to really be getting a reading I'm down seventy-five yet I'm reading the fifty I wonder if this guy is affecting him move you and I'm moving myself as far away from it too I think what's happening is once we get past here because of the wide field that this has it's starting to actually pick up on my workbench and so going anywhere beyond 50 seems to be rather pointless and that's borne out over here I suspect it as the wide field of this device is causing it let's go and use the foamy side now now this is on the 10 and let it settle down and yes as I sort of suspected this unit is picking up the reflection from the board not the foam in front of the board the sound is passing through the foam and being reflected back so it's as if the foam wasn't there that's an interesting thing to know if that's the type of a surface you're trying to sense and we'll go to the 25 where it should read 25 but it's probably going to be a bit high let it stabilize and there you go it is a bit higher than 25 so once again I'm pretty sure we're reading the foam I mean the board behind the foam excuse me here we are at the 50 mark and yet stabilizing at almost 51 again the thickness of the foam and it would be pointless to move back over here because even without a reflector here I'm still reading 52 so it's got to be something on my workbench it's picking it up but I would say otherwise in the range that we are able to measure this that our old friend the HC sr 0 4 really works very well now of course we are measuring temperature and humidity as you can see right now and yes the humidity is that low right now we are in the workshop I think it's because this whole unit is very close to a space heater and it is starting to get pretty dry out there to begin with and that's probably helping a bit because it's computing the correct speed of sound but this is an impressive device especially when you consider what it costs well I have to say I'm a bit surprised by the results of some of our tests I had assumed at the beginning of this that the laser sensor would just run circles around the ultrasonic sensor and at a certain range you could see that it definitely was a bit more accurate in the 25 to 50 centimeter range but otherwise the ultrasonic sensor did match up very good and not the longer ranges it was better than the laser sensor now the ultrasonic sensor I think wasn't peated at the very long ranges because it has a much wider cone of sensing than the laser one does which has a very narrow one and that's something to keep in mind in your design if you're trying to pinpoint something the ultrasonic sensor isn't as good as the laser sensor would be and the laser sensor had some other advantages as well obviously the data comes back much more rapidly and on a moving robot or a quadcopter that could be very important because waiting to refresh the ultrasonic sensor might not be a practical thing to do when you're moving fast speed so the laser sensor definitely has it's applications it's a small device it's sealed from the environment so it could be used in an area where there's water or something like that they both have applications but I was quite surprised to see how well the HCS are zero for factored in now when you want to compare the two keep in mind that I did add the dht22 to the ultrasonic sensor and if you add the cost of that to the cost of an HTS are 0-4 it comes close to the cost of the laser sensor so the price difference isn't that great when you factor the two of those in also there are a lot of other laser sensors out there I'm going to be picking a few of them up and so we'll be putting there a little test bed to use again one day soon now if you'd like some more information about the two sensors that I've worked with the day you can check out the article in the drone ball workshop comm website you will find a link to that article directly below this video if you haven't subscribed to the newsletter while you're on the website why don't you do that it's my way of keeping in touch with you and if you haven't subscribed to the YouTube channel well please hit that subscribe button I love to get new subscribers and if you want to talk about these tests or anything else electronic head over to the drone bot workshop forums or you'll find all sorts of intelligent people having all sorts of intelligent discussions about everything a robotic and electronic it's really a great place to be so until the next time please take care of yourselves I hope you enjoyed a little test and we'll see you again very soon here in the workshop good bye for now [Music]
Info
Channel: DroneBot Workshop
Views: 95,139
Rating: 4.9098592 out of 5
Keywords: hc-sr04 ultrasonic sensor, tof10120 arduino, distance sensor, laser distance sensor, ultrasonic sensor, time of flight, ultrasonic sensors
Id: xO5_3SjEhS4
Channel Id: undefined
Length: 31min 9sec (1869 seconds)
Published: Sun Nov 24 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.