 So this is an ultrasonic sensor. It uses sound to measure distance. I'm pretty sure it's actually modeled off of like bats and dolphins that use echolocation to see where they're going because they're pretty much blind. It looks kind of like two robot eyes in a face. One eye is the receiver and one eye is the transmitter. So it shoots out the sound waves, bounces off of a wall, an object, whatever it's in front of it and goes back into the other eye that then can tell you how long it's been in the air and using that number, if it's been 10 seconds or whatever, there's a little formula we can do to figure out that distance using sound. So we're pretty much able to measure something without actually sitting there with a measuring tape or a caliper and being like, oh, that's 10 centimeters, that's 12, whatever. Pretty cool stuff. Also, what's cool is you can measure undetected since we don't hear the sounds, we don't see them. There's no actual indicator that this would be working or not other than what we're getting through the computer. You can do things undetected. So you can set up a measuring device for example, every car has ultrasonic sensors like these all around it for bumpers. So when a car gets too close to a wall it starts beeping and freaking out but you're not seeing that from the outside, you're not looking around and seeing the laser beam or anything, it's just happening passively in the background. So when you're partaking, you're backing up and you're getting a little too close to that car behind you, it's gonna start beeping and beeping and beeping using a measurement from a device like this. Boards like this one even have holes all around it so that you can mount it onto something. These are pretty cool for DIY projects and this specific one can do, I think it's two centimeters to four full meters of range, distance, measurements, whatever you wanna call it. So this is what it looks like from up close. You can see the two little dishes in there that create the ultrasonic waves and then you have four pins at the bottom here. You have your VCC which is our power. We're gonna be connecting to five volt. We have our trig pin which we will be connecting to pin number three on our board, the digital pin. Echo will be going to number two and then ground will be going to ground on the board. So power three, sorry, power three, two and ground. Also if you're interested on the back is just a bunch of logic boards, figuring out all the math, doing all the important stuff and for us it's just a signal to that easy little pin. All right, so we're gonna need a couple of things. We're gonna need our sensor. We're going to need an Arduino, a couple cables. I'm gonna be using a breadboard just so that I can keep it up so you don't need one but I'll just be doing this, plugging it into my board and now it's standing up straight. I don't have to deal with it aiming around. No shaking, no vibrations. So let's start off with connecting our wires. We have our ultrasonic sensor plugged in here and as I said earlier, VCC will be going to five volt trig to three, echo to two and ground to ground. So I'm gonna plug in all my cables first ready for VCC. I'll be using purple for the trigger pin which is going to three. I got gray going to two and then ground is going to be black. So let's just plug it all into the board. We got our five volt, we got our ground. We got our two and then our three right there. I'll plug it into the computer and you should see things starting to light up. I don't think there's any lights on this ultrasonic sensor to keep it all stealthy. So we'll see if it's working by finishing up our code here and then we can start to see if it's printing out some stuff. All right, now open up your Arduino editor. That's what we'll be using. So in the Arduino editor at the top right here, you will see a void setup and a void loop function. Before we do anything in those, we first have to define all the pins that we're using. Do a little pound sign and write define echo to. Sorry, we should call it echo pin to be clear. Then under that, let's do one more define trig pin three. Down here, we're gonna want some variables. We're gonna want a long duration and an integer distance. So how long and then something to store the distance, which is what we're trying to figure out. How far, let's say is my hand from the sensor as I move it. We want to see that going from one centimeter, two centimeter, three centimeter on. We're gonna store that in distance. All right, now we can go to our setup. So setup function is everything that should happen before the Arduino starts running, all the things to set up for the loop. So we're gonna first go and declare a couple things. I'm gonna just copy paste this because we're gonna use it twice. So first we need our trig pin and that's going to be our output pin because we are triggering the sensor to put out some waves. Then on our second line here, we got our echo pin, which is going to be our input pin. We're going to be receiving those sound waves. Then we want to call our serial dot begin. This is what we did last time and we do every time. It's just so that we can print out our results and see them in real time. And that's everything right there for the setup function. So we have our trigger pin, which is an output pin, our echo pin, which is an input pin, and our console. Down here, we're gonna do a couple different things. First, we're going to digital. Then we're gonna go delay, micro seconds. Then we're gonna call a two. Now I'm gonna copy this and paste it again. So now what we're gonna do is we're going to send waves in our own pattern. So we're gonna turn it off, make sure it's off to start with. Then we're gonna turn it on. So we're gonna put high instead of low. We're gonna put a longer duration here. So let's say 10 milliseconds to try that. Or sorry, micro seconds. And then we're gonna turn it off again. We don't need a delay there. So we're gonna turn it on for 10 microseconds and then turn it off. In that little 10 microsecond window, we should be getting those waves out and in so that we can read them to figure out our distance. So now we can go down here and call our duration variable from earlier. And in there, we're going to be receiving the pulse from our echo pin, which we made an input pin earlier. So call our echo pin. Boom. I think I spelled something wrong. Yep. That's in capital. There we go, pulse in. So now we have our little setup here where we're sending a signal for 10 microseconds. Then we have right here capturing that through our echo pin. Or actually we're telling the echo pin to start receiving those waves. And then under that, we're gonna go and do something, a little big brain. And we're going to be making a little function here. You don't really, it doesn't really matter. I copied this myself too. It's just a function that it's going to get us the speed of the sound wave and we're gonna be dividing it by two. So we're gonna multiply it first by this and then we're gonna divide it by two. Once we figure out how long it takes the waves to reach the endpoint. So if we're shooting waves from the ultrasonic sensor into my hand and then it comes back, we don't need the time that it comes back because we'd be doubling our distance because the waves have to go all the way here and then all the way there. So if we're only 10 centimeters away, our result is going to be 20 centimeters because it has to go there and come back. So we're gonna divide it by two. So we're only capturing the one way. So we do that, let me just close it out here. And then under that we can start to print some stuff. So we got our, oops, serial dot print. The first thing we'll do is print out our distance. Then we will print out our distance variable that we just calculated. And then we're going to print out print line and we're going to print out centimeters. That should be in brackets. Okay, so let's go over this one more time. We are sending out our signal, we're receiving it, we're dividing it by two, how long it's been in the air, so the duration because we only want one way of the travel. Then we're gonna print out our distance variable with centimeters since we're using that setup. You could convert this into inches and whatever you want, but so I'm gonna go ahead and upload it right here. I'm not gonna save it, I'm just gonna upload it. We made a mistake here. Oops, spelled something wrong. All right, let's see if that works. All right, it's uploading. We'll see a flickering light on the board, which means something is happening. It says it's done uploading. Let's go ahead and open our serial monitor and make sure it's on the 9600. And look at that, it's freaking out. Now, I'm gonna move all my stuff over here and make sure everything's in the view of the camera. Set up the board right here. Let's grab the caliper and let's put the caliper at around 10 centimeters right there. Now let me find something, let's say my phone. Let me set it up right here at 10 centimeters and let's see what result we're getting. Look at that, between nine and 10 centimeters. I think if I move it out right here. Oh, I'm not measuring from the sensor point. How about now? Look at that. Now let's try something else. Let's take it out to 15. Look at that. And it's instant, all it does, all it has to do is send that sound signal to the phone and back and it's done. And that thing goes so fast, it's the speed of sound. So if I move it back here, five centimeters, 15, 10. You see how it's instantly there? We can also go and change it to be even more specific, but I'm happy with this. See how it goes from one all the way out to 30. And if I actually move my phone and move everything behind it, it should go to the wall off screen here. Look at that, almost a full meter. If I move this, look at that, 90. If I aim it up a bit, it should be 100 because it's just about a meter out from the wall. If I turn it out into open space like this, look how it goes to 2245. If I point it at the other wall right here, it's 30. And it doesn't seem to matter what surface you're pointing at. Like this phone case is pretty rough surface. So light shouldn't reflect very well off of it. For example, you can do it off the screen, which is extremely shiny. See that? Second, but extremely shiny screen, but it's working at 20 centimeters. Oh, look at that, there. If maybe if I bend it over like that, it just goes to the wall behind it. Something small should work as well as long as it's hitting it. See, so sometimes it's not hitting it, but if it is, it'll say 20 centimeters, 18 is what I got there. If I move it closer, look at that, worth seven, worth five, four, three, two, and then it freaks out because it doesn't know what the hell's going on. So this thing is pretty cool. I give it a 10 on 10 sensor for projects. You can set it up to have motion activated things. You can have different sort of patterns where you move things closer and farther. You can make a little sensor for your car. If your car doesn't have one, you just put it under your bumper and wire in a little speaker into the car and have it beep when the sensor is too close to something. You can do all sorts of things with these kind of sensors. They're really cool. They're super efficient. They don't make noise. There's nothing that says this is on right now. If I covered these lights right here, you would never know if this is working or not. So it's pretty cool, pretty stealthy. If you enjoyed, give the video a like, subscribe to the channel to see more, and I'll see you guys in the next one.