and 21 this is the ultrasonic sensor that we use for Arduino that travels from here to the wall
and coming back will take some time from the right ground is connected using black
wire to ground in this sense because it will give you a zero or incorrect reading
this course is based on sun founder three in one Arduino kit sold on Amazon everything that
you learn in this course is included in this kit the course comes with tons of components
and projects all with instruction and video for smart car and other projects that you
can use for school or home automation you can purchase it from sunfounder.com
the kit also comes with full documentation code download learning projects with full
explanation wiring diagram and the code that you can download a link to purchase the kit
and documentation is below the video in the description welcome to Arduino course by Robojax
this is the ultrasonic sensor that we use for Arduino this is one of the most famous component
that is used for measuring the distance and it's being used in cars to avoid obstacles as being
used in robotic arm these are two speaker type modules so this is a transmitter that acts as a
speaker and it transmits ultrasonic mean this is above the hearing frequency of human which
is above 25 kilohertz so this will be around 40 kilohertz so this transmits and this piece acts
like a receiver they put R here and it receives it let us have it operates I've drawn this diagram to
illustrate it this is the ultrasonic sensor and this is a transmitter usually shown with TX this
sense ultrasonic wave and when it goes and hits for example this object this is a wall it heads
and return dinosaur bounces back the signal that travels from here to the wall and coming back will
take some time and the phase of the signal at this point is compared with the phase at this point and
we will see what is the delay and by calculating the delay of the phase because we know the speed
of sound we can determine the distance so with Arduino you can get the distance of the object
from this device from this point and in one of the application would be that you may build a
smart car and install this at the front of the Smart car and program your Arduino that whenever
this approaches to an object for example when it reaches 30 centimeter you can stop the car
or when it reaches at a certain distance you can use the steering and turn the car left or right
to another Direction until it finds a clear path and then proceeds so this can be used in so many
ways the module has four pins this is the VCC will be connected to 5 volts this is ground and then we
have drag and Echo and the chip that are used here with conjunction to the calculation from Arduino
the proper width signal is thin here and the wave phase is measured and when it receives the signal
Compares it and from the delay it calculates and the value will be available within the Arduino
I've drawn this using Fritzing, and this is a free software. so from the right ground
is connected using black wire to ground and here I've used this black wire connected here to ground
then we have brown wire and red wire Echo is connected to 11 and Trigger is to 12.
and her red and brown are connected to 11 and 12. and then the orange the
last one is connected to 5 volts and the Orange is connected here
to 5 volts
in order to use this module you need extra set of codes that have been written specifically for
this device to work and it's called Library so we are going to download the library plus some
code that is within the Arduino IDE together they will do the calculation for us so let's first get
the library and then I'm going to explain the code for this first let's go to this address
that I will provide you hobojax.com and you will see this page and download the library
this is the official library that is there but this is a direct link
click and then save it somewhere let's say in download
then go to sketch include Library
and click add zip Library
from here pointed to your downloads and that is ultrasonic Library
once you click and open it will be included in your life
now let's open the example from the library click on file examples and scroll down until you see
New Ping
newPing and click here pink example and that's a code
this line we are including the library using include
and this line we are defining pin tools for trigger pin and 11 for echo pin and
the maximum distance because it will give you a 0 or incorrect reading we have to set the limit for
the amount of Maximum 200 that we want or lower that you need in this case let's put it to 200
that is centimeter and then we get the Library class and we create an object and we pass these
variables here the first one the second one and the third one to this object so the sensor is
initialized and then we initialize the serial monitor with 9600 because we are used to that
and then inside the loop we have 50 millisecond delay for the servo for the ultrasonic sensor
to read this is just printing the pink text actual reading is in here sonar pink centimeter
it will give you the distance and we print after that we print the centimeter after it
and here is a demonstration because of I have here a box I'm putting it in a certain distance
exactly by the end of this ruler and we have to make sure that this side or the wires does not
touch the metal so I'm gonna put it this way and read the distance as you can see
right now it's at seven centimeter 17 centimeter and we are reading 17. that's amazing
so, let's move it 20 centimeters it goes between 20 and 21.
26 centimeter as you can see it's very exact let me point it to the wall
and ceiling you see when it is 200 it's it gives zero, so
we have to I'm pointing it now to my computer monitor
and now this is this pointed down 14 centimeter and go down seven five two
so, after two centimeters it cannot read keep that in mind
40. so as you can see this works perfectly