In this lecture, you have to use the agency as 04 ultrasonic distance, since the sensor provides an
easy way to measure the distance between itself and a usually flat, reflective object in front of it,
like this container that I'm using here as a sample target.
The principle of operation for this sensor is that you've got two modules.
One emits an ultrasound which bounces off the object in front of it and goes back into the receiver.
And the amount of time that it takes for the signal to travel between the emitter and the receiver provides
information so that the distance can be calculated.
Now, in this case, I needed to find a easy to use and reliable driver for the census so that I didn't
have to code the functionality myself.
And to do that, I was able to go to the market.
Python listing of such drivers, search for distance since ultrasonic or something like that.
And it's I was able to find this driver right here, click on it, and it will take you to the GitHub
repository where you've got some information on how to use it.
And of course, you've got access to the driver itself, the python drive itself, so you can click
on the raw button just to get a clear text of the code of the driver.
Copy that and then create a new page in phony paste the code in and save it on your device using this
name here, HTC.
And this call is scheduled for in lowercase because this is the name that I use to import this code
into my example script.
So I've already done that, of course.
So I'm not going to repeat the process here to save a bit of time.
This is the example script that are prepared.
As you can see, it's very simple.
I've got some information on how to connect the sensor to your ESP three to using the regular ground
and three point three four panes for power.
And then the echo pin, which is the second from the right, which is this pin right here via a couple
of jumper wires, goes to Tip-offs 15 right there.
And then the trigger pin, which is this pin right here, goes to be able to OK, those embedded with
the connections, nothing fancy.
I've got information about the driver so you can download the driver and install it or save it on your
HP 32.
And as far as the script itself is concerned, I'm importing the necessary modules and I'm creating
the sensor object as per the instructions from the driver module.
I'm calling the CSR constructor, passing the trigger and expense.
And there's also Eneko Timeout is a pretty large number in microseconds.
I'm using a hardware timer here like I've done in previous lectures, and I'm taking reading every one
second, one third milliseconds periodically.
And every time that the timer expires, it will call the interrupted service routine, which is this
one here.
I'm simply getting a distance measurement in centimeters and I'm rounding this number to two decimal
points and printing it out.
And because I've got just a simple number here, I can also use the pleura, which gives me a nice visual
representation.
So actually it really works.
So I'm going to move the target, make it a bit closer.
You can see that the.
Numbers change as well as a plot of that number back a little.
This just increases.
You can take more frequent measurements, for example, I've gone down to 250 milliseconds, depending
on the distance that you want to measure, you need to be mindful of how frequently you can take measurements.
If you want to take measurements that are, say, beyond 10 or 20 centimeters, then you need to take
into account the amount of time that is needed for the ultrasound to travel back and forth.
And it seems that about half a second to a second is a good number for such measurements.
Right.
So that's about it with the want system since the.