1
00:00:01,140 --> 00:00:09,660
In this lecture, you have to use the agency as 04 ultrasonic distance, since the sensor provides an

2
00:00:09,660 --> 00:00:16,950
easy way to measure the distance between itself and a usually flat, reflective object in front of it,

3
00:00:17,220 --> 00:00:21,160
like this container that I'm using here as a sample target.

4
00:00:21,660 --> 00:00:25,680
The principle of operation for this sensor is that you've got two modules.

5
00:00:25,680 --> 00:00:32,790
One emits an ultrasound which bounces off the object in front of it and goes back into the receiver.

6
00:00:33,030 --> 00:00:39,690
And the amount of time that it takes for the signal to travel between the emitter and the receiver provides

7
00:00:39,690 --> 00:00:43,680
information so that the distance can be calculated.

8
00:00:45,170 --> 00:00:54,020
Now, in this case, I needed to find a easy to use and reliable driver for the census so that I didn't

9
00:00:54,020 --> 00:00:56,330
have to code the functionality myself.

10
00:00:56,750 --> 00:01:00,630
And to do that, I was able to go to the market.

11
00:01:00,680 --> 00:01:09,590
Python listing of such drivers, search for distance since ultrasonic or something like that.

12
00:01:09,920 --> 00:01:18,920
And it's I was able to find this driver right here, click on it, and it will take you to the GitHub

13
00:01:18,920 --> 00:01:22,760
repository where you've got some information on how to use it.

14
00:01:24,170 --> 00:01:31,790
And of course, you've got access to the driver itself, the python drive itself, so you can click

15
00:01:31,790 --> 00:01:37,940
on the raw button just to get a clear text of the code of the driver.

16
00:01:38,180 --> 00:01:48,560
Copy that and then create a new page in phony paste the code in and save it on your device using this

17
00:01:48,560 --> 00:01:50,210
name here, HTC.

18
00:01:50,210 --> 00:01:55,940
And this call is scheduled for in lowercase because this is the name that I use to import this code

19
00:01:55,940 --> 00:01:58,390
into my example script.

20
00:01:59,300 --> 00:02:01,000
So I've already done that, of course.

21
00:02:01,010 --> 00:02:03,950
So I'm not going to repeat the process here to save a bit of time.

22
00:02:04,700 --> 00:02:07,700
This is the example script that are prepared.

23
00:02:07,970 --> 00:02:09,390
As you can see, it's very simple.

24
00:02:09,410 --> 00:02:15,950
I've got some information on how to connect the sensor to your ESP three to using the regular ground

25
00:02:15,950 --> 00:02:18,260
and three point three four panes for power.

26
00:02:18,530 --> 00:02:26,810
And then the echo pin, which is the second from the right, which is this pin right here via a couple

27
00:02:26,810 --> 00:02:31,760
of jumper wires, goes to Tip-offs 15 right there.

28
00:02:32,240 --> 00:02:42,620
And then the trigger pin, which is this pin right here, goes to be able to OK, those embedded with

29
00:02:42,620 --> 00:02:44,210
the connections, nothing fancy.

30
00:02:44,670 --> 00:02:50,750
I've got information about the driver so you can download the driver and install it or save it on your

31
00:02:50,780 --> 00:02:51,550
HP 32.

32
00:02:51,980 --> 00:02:58,760
And as far as the script itself is concerned, I'm importing the necessary modules and I'm creating

33
00:02:58,760 --> 00:03:03,050
the sensor object as per the instructions from the driver module.

34
00:03:03,350 --> 00:03:09,260
I'm calling the CSR constructor, passing the trigger and expense.

35
00:03:09,530 --> 00:03:13,610
And there's also Eneko Timeout is a pretty large number in microseconds.

36
00:03:14,600 --> 00:03:23,330
I'm using a hardware timer here like I've done in previous lectures, and I'm taking reading every one

37
00:03:23,330 --> 00:03:25,790
second, one third milliseconds periodically.

38
00:03:26,090 --> 00:03:32,860
And every time that the timer expires, it will call the interrupted service routine, which is this

39
00:03:32,870 --> 00:03:33,470
one here.

40
00:03:34,280 --> 00:03:40,850
I'm simply getting a distance measurement in centimeters and I'm rounding this number to two decimal

41
00:03:40,850 --> 00:03:42,470
points and printing it out.

42
00:03:42,950 --> 00:03:48,470
And because I've got just a simple number here, I can also use the pleura, which gives me a nice visual

43
00:03:48,470 --> 00:03:49,480
representation.

44
00:03:49,910 --> 00:03:51,780
So actually it really works.

45
00:03:51,780 --> 00:03:56,050
So I'm going to move the target, make it a bit closer.

46
00:03:58,160 --> 00:03:59,270
You can see that the.

47
00:04:00,350 --> 00:04:05,030
Numbers change as well as a plot of that number back a little.

48
00:04:07,180 --> 00:04:08,500
This just increases.

49
00:04:12,550 --> 00:04:17,950
You can take more frequent measurements, for example, I've gone down to 250 milliseconds, depending

50
00:04:17,950 --> 00:04:24,160
on the distance that you want to measure, you need to be mindful of how frequently you can take measurements.

51
00:04:24,760 --> 00:04:30,460
If you want to take measurements that are, say, beyond 10 or 20 centimeters, then you need to take

52
00:04:30,460 --> 00:04:34,930
into account the amount of time that is needed for the ultrasound to travel back and forth.

53
00:04:36,160 --> 00:04:42,490
And it seems that about half a second to a second is a good number for such measurements.

54
00:04:46,390 --> 00:04:46,670
Right.

55
00:04:46,690 --> 00:04:49,690
So that's about it with the want system since the.
