Saltar navegación

Activa JavaScript para disfrutar de los vídeos de la Mediateca.

Arduino: distance sensor (native speaker) - Contenido educativo

Ajuste de pantalla

El ajuste de pantalla se aprecia al ver el vídeo en pantalla completa. Elige la presentación que más te guste:

Subido el 27 de marzo de 2022 por David G.

113 visualizaciones

Descargar la transcripción

Hello, In this exercise we are going 00:00:01
to learn how to use a distance 00:00:04
sensor so you will be able to 00:00:06
find it in the basic library just 00:00:08
scroll down and it's right here click 00:00:12
and drag it and connect it to 00:00:15
the arduino board this way 00:00:17
I'm going to zoom in a little 00:00:20
bit 00:00:21
you can see the ground connection from 00:00:22
the sensor to the arduino board 00:00:24
and a five volts connection connected to 00:00:27
the five volts of the board 00:00:30
and there is also a control wire 00:00:33
or control connector that we are connecting 00:00:36
to number thirteen so this is how 00:00:39
we connect the sensor 00:00:41
now how do we program it so 00:00:44
if we open the code 00:00:47
I'm going to just focus first on 00:00:51
the first block that is here that 00:00:53
we see we're going to use a 00:00:55
variable that is called distance and we're 00:00:57
going to use the block to define 00:01:00
this is the way that we take 00:01:04
a value and we store it inside 00:01:05
the variable and inside is the per 00:01:07
purple block that says read the distance 00:01:10
sensor etc etc it's a very long 00:01:13
name but it basically means that the 00:01:17
sensor is going to be connected to 00:01:20
number thirteen 00:01:22
so if I scroll over 00:01:24
this section you do not need to 00:01:29
change keep it as is 00:01:30
and we are going to measure the 00:01:33
distance in centimeters 00:01:34
so centimeters is there and we use 00:01:42
this purple block to read a number 00:01:46
and store it inside this variable 00:01:49
now with this second block as you 00:01:53
already know we are going to send 00:01:55
the value to the serial monitor 00:01:57
down here okay so let's look at 00:02:01
the simulation 00:02:03
and you can see how it will 00:02:06
work 00:02:08
we will read the distance and we 00:02:09
will send it to the arduino board 00:02:11
and we'll be able to see it 00:02:12
using the serial monitor 00:02:14
so let's start 00:02:17
I'm going to just close the code 00:02:20
to make it easier to see fully 00:02:21
and then zoom out a little bit 00:02:24
and nothing happens at first but if 00:02:26
I click here on the monitor 00:02:28
this new or on the sensor sorry 00:02:31
this new part will appear so this 00:02:33
ball is simulating a kind of object 00:02:36
close to the sensor 00:02:38
and if I open the serial monitor 00:02:41
you will be able to see that 00:02:44
here the distance is three hundred and 00:02:46
three centimeters 00:02:49
and we're reading three hundred three centimeters 00:02:54
if I move the ball closer the 00:02:58
distance is one hundred and ninety two 00:02:59
centimeters one hundred and ninety two and 00:03:01
closer again sixty three and we're reading 00:03:04
sixty three centimeters okay so it means 00:03:07
that the simulation works which 00:03:10
great 00:03:12
but also I will say that it's 00:03:14
not necessarily easy to understand how this 00:03:16
works in real life so I'm going 00:03:19
to show you a real distance sensor 00:03:21
measuring in real life 00:03:23
so we can stop the stimulation 00:03:28
and here I have it set up 00:03:33
so I've created this code and uploaded 00:03:35
it to the arduino board and now 00:03:38
the board is already working 00:03:40
I'm going to use this book as 00:03:46
an object for example and the object 00:03:47
is far away 00:03:50
and there's a green light can you 00:03:53
see the green light as the object 00:03:54
moves closer we see the yellow light 00:03:57
and if the object is even closer 00:03:59
now the red light is shining 00:04:03
okay so we're measuring distances and the 00:04:05
arduino board is behaving according to the 00:04:07
distance that the the sensors reading 00:04:10
so this is the exercise that you 00:04:14
will have to program using the simulation 00:04:16
of course not the program and you 00:04:19
see that it works in real life 00:04:22
so let's go back to our simulation 00:04:25
you have everything you need here you 00:04:29
have the sensor and when you're simulating 00:04:31
you can click on it remember if 00:04:34
you are simulating you can click and 00:04:36
you'll have a virtual object to move 00:04:38
and then you have these pieces of 00:04:42
code these blocks we are reading using 00:04:43
the purple block and storing it inside 00:04:45
a variable and you will use this 00:04:48
variable to check the conditions 00:04:50
so if the distances for instance I 00:04:53
dunno let's let's look before we add 00:04:59
any code if the distance is for 00:05:01
instance higher than two hundred centimeters then 00:05:02
the green LED will be shining if 00:05:07
the distances between two hundred and one 00:05:09
hundred for instance 00:05:12
it's 00:05:13
then the yellow LED will be shining 00:05:16
and if it's lower than one hundred 00:05:18
centimeters for example then the red LED 00:05:20
will be shining 00:05:23
so what do you need well of 00:05:26
course you need three LED connected 00:05:27
here with protection resistors like always 00:05:30
connected to 00:05:35
for instance twelve eleven ten 00:05:38
connectors and you will also need some 00:05:42
comparing blocks for conditions that if then 00:05:44
blocks 00:05:48
let's find that here 00:05:52
and you will also have to combine 00:05:54
different conditions such as lower than two 00:05:56
hundred and higher than thirty just for 00:06:01
instance so remember you already know how 00:06:03
to combine conditions and all of them 00:06:06
inside the block that says if then 00:06:08
so there will be three blocks of 00:06:12
if and each one will have a 00:06:13
different condition for instance higher than two 00:06:15
hundred lower than two hundred and higher 00:06:19
than one hundred and lower than one 00:06:22
hundred centimeters and for each condition one 00:06:24
of the LED these will be shining 00:06:28
it will shine for a short period 00:06:30
of time 00:06:31
so we will wait for this period 00:06:33
of time while it's shining 00:06:34
and then it will be off again 00:06:38
okay so I have described the structure 00:06:43
of the program to you if you 00:06:46
don't understand it you can just watch 00:06:48
the video again 00:06:50
I think you now have everything you 00:06:52
need to know how to complete the 00:06:53
exercise 00:06:55
so you will have to program something 00:06:57
that will behave the same way the 00:06:59
real arduino board is behaving now with 00:07:01
the object in different conditions of how 00:07:05
far away it is to the sensor 00:07:08
in centimeters so try this and watch 00:07:10
the video again if you need to 00:07:13
good luck 00:07:16
Idioma/s:
en
Autor/es:
David Gonzalez Arroyo, Alyssa Fantel
Subido por:
David G.
Licencia:
Reconocimiento - No comercial - Compartir igual
Visualizaciones:
113
Fecha:
27 de marzo de 2022 - 22:53
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:
83.96 MBytes

Del mismo autor…

Ver más del mismo autor


EducaMadrid, Plataforma Educativa de la Comunidad de Madrid

Plataforma Educativa EducaMadrid