Activa JavaScript para disfrutar de los vídeos de la Mediateca.
Arduino: distance sensor - Contenido educativo
Ajuste de pantallaEl ajuste de pantalla se aprecia al ver el vídeo en pantalla completa. Elige la presentación que más te guste:
Hello! In this exercise we are going to learn how to use a distance sensor.
00:00:00
You will be able to find it in the basic library, it's somewhere here, okay here,
00:00:08
Sensor de Distancia en Español. Just click and drag and connect it to the Arduino board this way.
00:00:13
There is, I'm going to zoom in a little bit, there is a ground connection connected to the ground of
00:00:19
of the Arduino board, a 5V connection connected to the 5V of the Arduino board here, 5A ground,
00:00:27
and there is also a control wire, a control connector, that we are going to connect it
00:00:35
to 13, for instance.
00:00:42
So this is the way we have connected our distance sensor.
00:00:44
How can we program it?
00:00:48
Really easy.
00:00:50
If we open the code, let's focus on the first block.
00:00:51
It's here.
00:00:59
Well, first of all, we are going to use a variable that is called distance,
00:01:00
and we are going to use the block defineer.
00:01:04
This is the way we take a value and we store it inside the variable.
00:01:06
And the interesting one is the purple block.
00:01:12
The purple block that is a little sensor, the distance ultrasonic.
00:01:14
I'm going to zoom a little bit.
00:01:17
Leer el sensor de distancia ultrasonico en el pasador del desencadenador.
00:01:19
Too much pieces of vocabulary to say that the sensor is going to be connected to 13.
00:01:25
This is where we connect the sensor, igual que el desencadenador, forget about it, just
00:01:35
be sure this is the way you have it, and we are going to measure the distance in centimeters.
00:01:43
we use this purple block to read a number and store it inside this
00:01:49
variable. And with this second block, you already know it, we are going to send the
00:01:55
value to the serial monitor, ok? Let's have a look at the simulation, but I'm
00:01:59
sure you already understand how it would work. We will read a distance and we will
00:02:05
send it to the Arduino board and we will be able to see it using the serial
00:02:10
monitor okay so let's start the simulation okay I'm going to close it
00:02:16
make it easier to understand I'm going to zoom out a little bit and nothing
00:02:21
happens apparently but if I click here let's have a look this one
00:02:26
appears the ball is simulating a kind of object in the in the close to the sensor
00:02:34
And if I open the serial monitor, you will be able to see that here the distance is 303 centimeters, and we are reading 303 centimeters.
00:02:41
If I move the ball closer, the distance is 192 centimeters, and here, for instance, 63 centimeters, we are reading 63.
00:02:56
It means that the simulation works.
00:03:08
Fine, perfect. Really easy.
00:03:10
but I agree that this is not really really really easy to understand how it
00:03:12
works in real life so I'm going to to show you a real distance sensor measuring
00:03:22
in the real life in real life I mean you have it here I have created this code
00:03:31
and I have uploaded it to Arduino board and the Arduino board now it's already
00:03:38
working. I'm going to use this book as an object and what the object is far away
00:03:43
there's a green light. Can you see the green light? If the object moves
00:03:50
closer we have a yellow light and if the object is even
00:03:55
closer there is a red light. So we are measuring distances and the
00:04:04
Arduino board is behaving according to the distance. Can you see it?
00:04:10
So this is the exercise you will have to program using
00:04:14
the simulation, of course, because you don't have the real Arduino board, okay?
00:04:17
Can you see that it works? Okay, fine, perfect. So let's
00:04:22
go back to our simulation. Here, you have
00:04:26
everything you need. You have the sensor. When you are simulating, you
00:04:30
can click on it, remember? And if you are simulating, you can click on it
00:04:34
and you will have a virtual object to move it.
00:04:38
You have these pieces of code,
00:04:42
reading using the purple block and storing it inside a variable,
00:04:45
and you will use this variable to check the conditions.
00:04:49
If the distance is, for instance, I don't know.
00:04:54
Let's have a look with the...
00:04:58
Oh, I'm sorry.
00:04:59
I made a mistake.
00:05:00
Now it will work.
00:05:03
If the distance, for instance, is higher than, I don't know, for instance, 200 centimeters, a green LED will be shining.
00:05:04
If the distance is between 200 and 100, for instance, or yes, 100 is a good value, 100, and a yellow LED will be shining.
00:05:18
and if the distance is lower is lower than 100 centimeters a red led will be shining okay
00:05:30
what do you need you need three leds connected here with their protection resistors connected
00:05:36
to for instance 12 11 and 10 and you will also need some blocks you will need a comparing blocks
00:05:43
You will need blocks like C, if, and a comparison like higher, and you will also have to check to combine different conditions.
00:05:52
For example, higher than, I mean, lower than 200 and higher than 30.
00:06:04
Remember, you already know how to combine conditions and all of them inside the block if.
00:06:13
So there will be three blocks if, each one with different conditions, for instance, higher than 200, lower than 200 and higher than 100 and lower than 100.
00:06:20
And for each condition, one of the LEDs will be shining.
00:06:35
It will shine for a short period of time.
00:06:39
We will wait for this period of time.
00:06:43
It will be shining.
00:06:45
We will wait and then it will be off again.
00:06:46
OK, so I have described the structure of the program to you.
00:06:48
If you don't understand, just watch the video again.
00:06:52
OK, remember, you have now, you know, everything you need to know
00:06:55
to do the exercise. OK.
00:06:59
And this is the exercise you have to do.
00:07:00
You will have to program something that will behave the same way
00:07:02
my real Arduino board is behaving now.
00:07:05
OK, so the exercise is easy.
00:07:09
Look and watch again the video if you have to.
00:07:12
OK, good luck.
00:07:15
- Autor/es:
- David Gonzalez Arroyo
- Subido por:
- David G.
- Licencia:
- Reconocimiento - No comercial - Compartir igual
- Visualizaciones:
- 251
- Fecha:
- 10 de enero de 2021 - 18:37
- Visibilidad:
- Público
- Centro:
- IES MARIE CURIE Loeches
- Duración:
- 07′ 17″
- Relación de aspecto:
- 1.78:1
- Resolución:
- 1920x1080 píxeles
- Tamaño:
- 26.27 MBytes