So this is our circuit. Now lets see how we can actually build this. So the first thing we are going to do is we are going to connect the vcc pin of our ultrasonic sensor to the 5v pin and the ground to the ground. Pin then, were going to connect the trick pin of our ultrasonic sensor to pin number 11 and the eco pin to pin number 10, and then we have to connect our buzzer. So here, in this case, we are going to connect the ground pin of our buzzer to ground and the positive pin to the pin number three and thats all we have to do so now lets go to our arduino ide and see how we can actually program This arduino, so now we are in our arduino ide. So here the first thing we have done is: we have included the library of our ultrasonic sensor, new ping.h, and we have defined the trick. Pin and eco pin the trick, pin and eco pin of our ultrasonic sensor and weve defined the max distance for that ultrasonic sensor. And then we have defined the and we have created a object called sonar so that we can actually control our ultrasonic sensor. And we have included the trick, pin eco pin and the max distance in that object, then we have defined the buzzer pin, which is the pin number three and in the void setup. What weve done is we have? Firstly, we have connected the serial monitor and then we have set the pin modes of our trick.

Pin then our echo pin and then the buzzer so except the echo pin, the others will all be set to output and the echo pin will be set to input mode and, in our main part, the void loop part. The first thing we are going to do is we are going to set a trick pin to low for 2 micro. Second and then we are going to set our trick, pin to high now for 10 microsecond, and then we will set our trig pin to again low. So the first two line is actually to control so that we know that the trick pin has actually been open or has actually been on for 10 microseconds. Not more than that, then we are going to set our eco pin to high. Now the eco pin will be on and it will receive the uh sound wave that has been transmitted from the trick, pin and then it will and then it will be received and then will be sent to this pulse in special function so that it can actually Calculate the length of that sound wave and then the length of the sound wave will be saved in this duration variable, which is an integer variable, as we dont want to difficult what to doing so. We will just stick with integer variable. Then we are going to come to the next line. Here we will be dividing the duration by 2, because the sound wave is actually traveling twice the same length, so we are going to divide it by 2, then we have got the actual distance and then well be dividing that by 29.

8. So this is the time that takes sound wave to travel, one centimeter in the air, so thats. How were going to get it get the distance in centimeter and that will be saved in this distance variable, which is also an integer variable. Then we are going to set a condition to turn on our buzzer or so here. What ive said is that if the distance is greater than 10, then the buzzer will be on low, so the buzzer will be off if something is less than 10 meter. Something is in less than 10 meter radius, then the buzzer will be turned on and it will start making noises to alert us so thats how this code will work so now lets go and see it working. So this is the circuit that we are going to create. So, as you can see, we have our ultrasonic sensor, our buzzer, and it is all connected to this arduino uno. So, as you can see the so the vcc pin here is the red one. The trick pin is the green one, eco is the blue one and the ground is the black one, so the blue and green. So this is the trick pin which is connected to pin number 11, and the blue one is the eco pin, which is connected to pin number 10. This red pin is the positive pin of the of our buzzer, which is connected to pin number three and the other red pin which is connected to the vcc of our ultrasonic sensor is connected to five volt pin of our arduino and the rest to the white And the black one are the ground pin of our buzzer and our ultrasonic sensor, which is connected to this ground, pin of our arduino, so thats.

All we have saw in our circuit so now lets connect this to our computer and see how this works. So now, if i put my hands in front of our ultrasonic sensor, as you can hear, the after the buzzer is on. If i move my hand, the buzzer is off so so the distance is here is also 10 centimeter. So if there is something in between 10 centimeter, the ultrasonic sensor will trigger the buzzer and it will produce the noise, and if something is out of 10 centimeter, then the buzzer owned trigger so thats how this works. So thanks everyone for watching the video.

https://www.youtube.com/watch?v=6s9Ua7Mz1nM