Waterproof Ultrasonic Distance Sensors - JSN-SR04T & A02YYUW ๐Ÿ’งโ˜”

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today in the workshop we're working with waterproof ultrasonic distance sensors we'll see how these devices work and how to use them with an arduino we'll also test them outside and even underwater we're going the distance today so welcome to the workshop [Music] well hello and welcome to the workshop and today we are going to be working with a couple of ultrasonic distance sensors now of course we've used an ultrasonic distance sensor before in our robotics and other projects and we've used it many times and that's our good friend the hcsr04 the hdsr04 is a great little sensor it's relatively accurate it can sense over a reasonable distance it's very inexpensive and it's pretty easy to use however i have an application right now in which it is not suitable specifically a robot i'm building that is meant to operate outdoors and the hcsr04 is not exactly a great sensor to use outdoors there are a number of reasons for that but one of the principal reasons is that you can't get it wet so i'm evaluating a couple of ultrasonic sensors that you can use in a damp and outdoor environment and i want to show them to you both today so let's first of all take a quick look at how these sensors work and then i'll show you the sensors that we're going to be using instead of the hc sr04 ultrasonic sensors use 40 kilohertz sound pulses to measure distance these devices consist of a transmitter and receiver although those can be combined into one transducer the transmitter sends out pulses of ultrasonic sound if a surface reflects this signal we can use the time delay between the transmission and the reception to calculate the distance if the distance is shorter the time delay will be shorter conversely if it's longer the time delay will be longer the hcsr04 is a very popular ultrasonic distance sensor it works on five volts only however you can use an rcwl1601 or a us-100 if you want a 3.3 volt equivalent this sensor can run in a 2-wire or 1-wire mode it's reasonably accurate and it's very inexpensive but the hcsr04 isn't perfect it's not suitable for outdoor use it's quite fragile and susceptible to dirt and most importantly it is not water resistant however there are ultrasonic distance sensors that are waterproof and we'll be looking at two of them today the jsn sr04t and the yyuw let's take a quick look at how these sensors performance compares to the hcsr04 the a02 yyuw and the hcsr04 both have about the same range the jsn sr04t however has a longer maximum range but also a longer minimum range the accuracy of all of these sensors is quite good certainly suitable for robotics and intruder detection applications none of them however would be good enough for surveying the jsn sr04t and the a02yyuw can work with both 3.3 and 5 volt logic the hcsr04 however is just a 5 volt device both the jsn sr04t and the hcsr04 support raw data in other words they deliver back the length of the receive pulse and leave it to the microcontroller attached to calculate the distance the two sensors we are looking at today support serial data with serial data the distance is calculated by the sensor and is descent as a serial data packet in terms of cost however both of these sensors are much more expensive than the hcsr04 however they're not extremely expensive and if you need a sensor that is rugged and capable of working outdoors they're probably good choices so let's go take a closer look at these sensors now now i've got the sensors that we're going to be using in our experiments today over here i've also got an hcsr04 sensor just so you can sort of compare everything and the one over here is the a02yyuw sensor and as you can see it looks a lot like the hcsr04 in that it's got a separate transmit and receive transducer but it is substantially larger than that unit now over here in the middle these two pieces are actually one sensor this is the jsn sr04t and it comes as a separate sensor that plugs into a board over here and this board is what you um wire everything up to of course at the electronics and as you can see the board is similar in size to the hc sr04 a little bit taller than it and of course the sensor is completely different and it has a fairly long cable i think that's a couple of meters long so you can mount it away and keep your electronics nice and safe and dry and so these two are the units that we are going to be using today in our experiments so let's get going now the first sensor that we're going to check out is a jsn sr04t sensor this is the one that had a separate circuit board and sensor unit and another way that this one differs from the other ultrasonic sensors we've seen is that the sensor unit just uses one transducer it's using it as both the transmitter and the receiver and i believe that this is the reason why the minimum range of this sensor is down around 20 centimeters it just simply can't flip itself back and forth in time in order to resolve anything shorter than that but other than that the sensor does seem to get a bit of a bad reputation on the internet and i don't think it's very deserved quite frankly there's even a youtube video out there that specifically tells you not to buy it and i saw that video after i bought a couple and thought did i make a big mistake but what i've noticed about these videos is that they all use this sensor in an emulation mode where it emulates an hcsr04 sensor and there are two aspects about that first of all i have found by experimenting that if you change the timing on it slightly it will work fine and it's actually within specs of the hcsr04 another thing i've noticed is that everyone who tests it tested in this emulation mode whereas this sensor actually has six operating modes including modes in which it calculates the distance all on its own so i thought i'd give it a proper test by testing it in a couple of different modes so let's go and take a look at this sensor right now and then i'll show you some code that we can use to test it in a couple of different modes and see how it works the jsn sr04t is a separate sensor and printed circuit board the sensor is attached to a two meter cable which attaches to the board with the two pin connector the sensor itself is a single transducer design this transducer acts as both the transmitter and receiver the jsn sr04t has six different modes of operation in mode 0 which is the default mode this sensor will emulate an hcsr04 it has the same pin out and can be used in the same circuits as the hcsr0 mode 1 is activated by shorting the tube m1 pads in mode 1 the sensor calculates the distance itself and sends it back as serial data and it sends its data constantly mode 2 is activated by shorting the m2 pads in this mode you need to request the serial data by sending it the hexadecimal character 5 5. it will then return one block of data in this way you can just request a distance measurement rather than having it continually sent to you modes three through five are activated by placing a resistor across the mode pins the value of the resistor will determine what mode you are in in mode 3 which uses a 200k resistor the sensor is an automatic trigger mode this is like an hcsr04 without a trigger pin the trigger is fired every 200 milliseconds and you can read the results and then calculate the distance yourself mode 4 which is activated with a 360 k resistor across the mode pins is the low power automatic trigger mode it's the same as mode 3 except the sensor consumes very little power consuming only 70 micro amps on idle it does this by powering down certain sections like its internal watchdog timer in mode 5 which is activated by placing a 470k resistor across the mode pads it doesn't act as a sensor but acts as a 1.5 meter switch it will stay high as long as the distance is less than 1.5 meters otherwise it will go low this is used for things like automatic backup detector alarms the serial data from the jsn sr04t is sent at 9600 baud and consists of four bytes the first byte is the header and it is always hexadecimal ff the next two bytes are the actual sensor data with the high byte being first and the low byte being second this is the distance in millimeters that has been measured by the sensor the final byte is a check sum it is the addition of the previous three bytes note the checksum only holds the bottom eight bits of this calculation upon receiving the data you should perform the same mathematics and determine that the checksums match if they don't then the data has been scrambled so now that we know a little bit about it let's go and hook up our jsn sr04t now this is the jsn04t which as we've seen before is a sensor that comes in actually two parts there's a sensor unit itself that's on the cable and a circuit board over here now if we look at the head of the sensor itself you can see this is a completely sealed unit and it just has a transducer on the front over here there's a little opening beside the transducer but i believe it's sealed behind that as well and that's probably just to allow the sound to get in a bit better now let's take a look at the board that comes with this and if we take a good look at the board now this is the version 3 board and the big difference between version 3 and the previous versions is how you set the mode on version 3 up in the corner over here you'll see a couple of jumpers there's one that says m1 a one above it that says m2 and a couple below that same mode and the m1 and m2 ones can be sorted out to put the device into mode m1 or m2 respectively if you want to go for some of the other modes you actually need to put a small surface mount resistor across this one that says mode and the value of that resistor will determine what mode you have if you don't have anything on it as you see right now then this is defaulting to mode 0 which means it emulates an hcsr04 and you will notice the pin outs on the bottom over here have four pins in fact if i flip this around so you can see the writing on that if you can see that you'll see it says 5 volt trigger echo and ground and those are indeed the pins that you use in an hcsr04 so you can pop this in as a direct replacement for it if you wish of course the trigger and echo pins are also transmit and receive so they can be used for the other modes as well but otherwise it's a fairly easy unit to use it has a really long cable over here that you can use to separate the sensor from the board and so this would be ideal for an application you're using outdoors let's say in a vehicle or something where you have this mounted on the bumper to detect distance and you have the circuit board somewhere else within the vehicle so it's a very inexpensive and as you're going to see relatively easy to use sensor for our first experiment will require an arduino uno and a jsn sr04t ultrasonic distance sensor module we'll begin with this distance sensor module in its default mode of mode 0. we start by hooking the ground from the arduino to the ground pin on the jsn sr04t the 5 volt output of our arduino will be connected to the vcc pin on our ultrasonic sensor pin 11 of the arduino will be connected to the echo or tx pin on the jsn sr04t and pin 10 from the arduino will be connected to the remaining pin which is the trigger or rx pin and this completes our wiring now here's a sketch that we're going to use for the mode 0 demo for the jsn sr04t and if you've used the hcsr04 before you're going to recognize the sketch because it is virtually identical to the sketch that i first demonstrated the hcsr04 with in fact there's only one real difference and it has to do with timing and i'll show you that in a moment now we're going to start off the sketch by defining the connections that we made to the sensor and then we define a couple of floats one that represents the duration the amount of time it takes the signal to come back and one that we have to hold the actual distance that we're calculating and we're going to bring our distance back in millimeters and then we go into our setup we set up our serial monitor over here and we define our two pins as inputs and outputs respectively and go into the loop now the loop again is very simple this is how we manually use an hcsr04 and it's how we're going to use this sensor in mode 0 so we start off by setting the trigger pin low for 2 micro seconds and then we set it high and here is where i've changed the timing in the original sketch that i use for the hcsr04 i use 10 microsecond pulses and when you read the spec sheet on the hcsr04 this is the minimum amount that you can use but you can use a longer pulse and i found that with this sensor when i used a 10 microsecond pulse i occasionally got intermittent results and i think this may be the result of some people saying that this sensor doesn't work it's simply because i think they weren't giving it a long enough pulse so i increased it to 20 microseconds and everything seemed to work pretty fine so we're going to set it high for 20 microseconds and then bring it low and so this will have sent out our ultrasonic pulses now we're going to measure the width of the incoming pulse so we use a pulse in to measure the amount of time that the pulse goes high coming in and then we determine the distance by that width over here now we're using 343 meters per second as the speed of sound we're also dividing by a thousand as we want millimeters so this is what we're using over here and of course we have to take the duration by 2 because the signal is going out and being reflected back so we only want half of it and then finally we print our results to the serial monitor and add a delay before we repeat this gives everything time to settle and then we do it all over again so it's a very simple sketch let's load it up and take a look at it in action and so here we have our mode 0 demo and as you can see from the serial monitor it's reading out readings pretty well of 226 millimeters which of course are wrong but remember this sensor has a minimum range of 30 centimeters and that's about a foot that's about 300 millimeters and so when it gets below that it'll give a false reading and i notice with this particular one that i have that seems to be the false reading so if i lift the sensor up a little bit we should start getting some more accurate readings and this is the distance basically between me and the wall over here so if i get something in the way we should start seeing some readings over here and now we're approaching that 300 millimeters if i go back a little bit over here it goes up so the sensor does indeed seem to work although of course we're not really accurately measuring anything right now i don't know if my 381 millimeters over here is precise although it's probably in the ballpark and we will test this a little bit later for accuracy but at least we know that our circuit is working and that we are unable to measure distance with this ultrasonic sensor albeit distances over 30 centimeters here's the sketch that we're going to use for our sensor in mode 1 where it sends back data in a serial fashion now we're going to start off by including the software serial library because the arduino uno only has one serial port which is being used for the usb connection and then we define our connections to the sensor over here so the two pins that we've got it connected to and we create an array to store the incoming serial data now if you recall the data is in a format of four consecutive bytes so we're going to set up an array with four elements inside it and we also need an integer to represent our distance that's this over here and we also have a character value to represent our checksum to make certain that our data has integrity we'll set up an object to represent serial port called my serial and attach it to two different pins and then go into the setup in this setup all we do is set up our serial monitor and also set up our software serial port at 9600 baud which is the rate that the sensor gives data back at then we go into the loop we check first of all to see if we actually have data available if there is we add a small delay and then we check for the packet header and the packet header has hexadecimal ff in it so we look at every character coming in until we see that and we know we've got the packet header once we know we have the header we'll insert that into the first element of our array then the remaining three characters of data will be inserted into the next three consecutive elements of the array which as you recall only has four elements then we'll compute the checksum by adding up the data in the first three elements and seeing the results if that result equals what we have in the last element of the array then the checksum is correct and our data has integrity and then we'll get the actual distance and the distance is represented by the two bytes in the middle of our array numbers one and number two so we'll put those two together and print everything out to the serial monitor and then go back up and do it all over again so it's actually a pretty simple sketch let's load it up and see how it works with our sensor in mode 1. and so we're going to repeat the same test we did on mode 0 with our mode 1 sensor and once again you'll notice that in idle it is reading about 230 millimeters again the minimum range of this is 300 so you'll get false readings when it is at minimum range lift it up again so that we can actually get a reading back to my wall and i'll put this in front of it move it and it does indeed seem to be responding once again we aren't verifying the accuracy of these measurements just simply the fact that it does measure something and we will take it out later and give it a proper accuracy demonstration but it does seem to work in mode one where the sensor itself is doing all the calculations and just passing the data back to the microcontroller now the yyuw looks a little bit like the hcsr04 in that you can see that it has both a separate transmitter and receiver unlike the last sensor that we just looked at and it is completely encased in rubber it's a very nice little unit and i wanted to see if i could perhaps get better performance than i did from the previous sensor using this sensor now this sensor only operates in a serial mode it has no emulation mode for the hcs hcsr04 whatsoever and so we are going to be using it in that serial mode now one interesting thing about that serial mode is that it uses the exact same data format that our previous sensor used in mode one so we don't even need to write any new code this time we can just simply use the last sketch that we used with this sensor and see how it compares so let's take a look at the sensor and then we'll go and see how it works the a02yyuw is a fully waterproof ultrasonic distance sensor the sensor works on either 3.3 or 5 volts it operates on a temperature range of negative 15 to 60 degrees celsius this sensor outputs serial data at 9600 baud and the format of the data is identical to that of the serial mode of the jsn sr04t the sensor has four connections as follows pin 1 is the vcc which is the power of either 3.3 or 5 volts pin 2 is the ground pin 3 is the output selection if you pull it high or just leave it alone the data will come back every 300 milliseconds if you bring this pin low the data will come back every 100 milliseconds the 300 millisecond data is considered to be more stable so unless you need data at a rate of 100 milliseconds you should just leave this pin alone and finally pin 4 is the uart output which contains the serial data from the sensor so now let's go hook up the a02 yyuw sensor now here's just a quick look at the a02yyuw and there's not really that much to look at i've got the sensor over here and i've also got an adapter cable and i purchased this from df robot and it's under their part number sen0311 and they included this little adapter cable which adapts the jst connector on the sensor two four separate wires that you can use for experimenting purposes so that's going to be very handy so let's just take a quick look at the sensor itself again really not much to see it's a completely sealed unit you can see some resemblance to the acsr04 and that has got a separate transmit and receive transducer sealed away with two mounting holes on each end over here if i flip it over to the back over here you'll see it's also completely sealed it's got kind of a rubberized feel to it and it's got a bit of weight to it it feels like a very solid product and so i'd feel quite comfortable mounting this outdoors using it in my outdoor robot etc so let's go and hook it up and see what it can do the wiring for our next sensor is just as simple as the last one was a gain will require an arduino uno and an a02 yyuw ultrasonic sensor unit we'll begin by connecting the 5 volts from the arduino to the vcc of the ultrasonic sensor this is the red wire the arduino's ground will be connected to the sensor's ground which is the black wire we'll connect pin 11 of our arduino to the receive or blue wire on the sensor and the sensor's remaining green wire which is the transmit lead will be connected to arduino pin 10 and this completes our wiring now here i have my a02 yyuw sensor and once again i'm going to try to measure distances with it now you can come closer than 30 millimeters with this one so i can come in a little bit more 30 centimeters excuse me i can actually come in quite close right now and here i am down to about 50 millimeters and of course i can move it back and get a reading as we would expect and so this does seem to work just fine using the code that we used for the other sensor and once again we'll have to actually take it out and give it a proper test to see how accurate it is so we've seen how our sensors work but we haven't really given them a proper test here on my workbench i just simply don't have the space to check out their range and our first sensor wouldn't even work at anything underneath 22 centimeters and so what we need to do is bring these things outside and that's exactly what i'm going to do right now i'm going to take both sensors outside give them a test and see how they work and i'll also even test out their waterproof capabilities so let's go ahead and take a look at that so i took the experiment outside into my tiny backyard along with a computer and i set everything up so that i could read the reflection off of my wall i measured everything as best that i could but of course the accuracy of these measurements is going to be a little bit off just because of my measurement process i then went and took measurements for both sensors at a number of different distances i also tried wetting the sensors and was pleasantly surprised to see that it really had no effect on the reading by the way those of you who saw my video on comparing ir sensors in ultrasonic may notice that board in the background unfortunately it was unusable for these tests here are the results that i got and as you can see both sensors were pretty accurate 2460 millimeters was the furthest that i could measure in my tiny yard and as you can see at the one meter mark they're both very close on i would say that either of these sensors would work properly in your application although if you need distances under 300 millimeters you're probably best going with the a02yyuw as the jsn sr04t will not measure low distances accurately also another thing to note was that the ambient temperature was rather cool it was only 14 degrees celsius and of course that will affect the speed of sound i made no effort to compensate again wetting the sensors didn't change the readings so i don't have a separate set of readings for that but i was pleasantly surprised to see that because this means that these sensors will indeed work in an outdoor environment now i do most of the filming for the dronebot workshop channel here in my workshop but as you saw from the last scene i've also taken it occasionally outside we've occasionally run a robot on the floor outside the room but there's a lot of my house you haven't seen yet and there was one area of my house that i never thought i would be showing you yet i'm about to show it to you right now and that is my bathroom and the reason for that is i want to give these sensors a test and see if they will actually work under water and as i don't own a swimming pool the largest body of water that i have in my home is my bathtub now i am not expecting accurate results i'm not even sure if i'm expecting any results from these because of course the speed of sound in water is different than the speed of sound and air but i would like to see if they are actually waterproof and if they will work underwater so let's go and take a look and see if they will so i took the experiment up to the bathtub and very carefully immersed the sensors under water i had to be particularly careful with the a02yyuw because it has a very short cord and i didn't want to drag my arduino into the tub the results however were very disappointing i got basically the same reading from both of the sensors at least each sensor gave a consistent reading it wasn't the same reading between the two of them and so they were completely useless inside the tub however one thing i did note is when i pulled them out of the bathtub they continued to work just fine so immersing them completely in water didn't affect them a bit they worked properly when they were out of the water so they're indeed waterproof but you can't use them in a bathtub well that wraps up our look at outdoor ultrasonic sensors and i hope that you found it useful i know that i found it useful because i think i can determine which sensor i'm going to use for my outdoor robot project a project that i will be showing you very soon by the way here on the dronebot workshop youtube channel so if you're not a channel subscriber please do that all you need to do is click on the little subscribe button and if you also click on the bell notification you will get notified every time that i make a new video and that of course is assuming that you've got notifications enabled on your youtube account now if you need the code that i used today or if you want a bit more information about the two sensors we looked at head over to the dronebotworkshop.com website where you will find an article that accompanies this video and there's a link to that article right below the video and if you'd like to discuss this well the best place of course is the dronebot workshop forums we've got a lot of great people on the forum who can help you out with your projects or you could perhaps help them out as well it's free to join so head over to the forum where you will find a thread that discusses this video specifically and finally if you want more information about what's going on in the workshop or more info about that outdoor robot please consider subscribing to my newsletter again it's absolutely free it's not a sales letter just my way of occasionally keeping in touch with you to let you know what's going on here in the workshop so until we meet the next time please take good care of yourself please stay safe out there and we will see you again very soon here in the dronebot workshop goodbye for now [Music] you
Info
Channel: DroneBot Workshop
Views: 10,435
Rating: 5 out of 5
Keywords: jsn-sr04t, hc-sr04, a02yyuw, waterproof sensor, ultrasonic distance sensor
Id: h6321UBATps
Channel Id: undefined
Length: 32min 11sec (1931 seconds)
Published: Tue Oct 05 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.